-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestdata.py
More file actions
176 lines (154 loc) · 5.73 KB
/
testdata.py
File metadata and controls
176 lines (154 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
from xmlserializer import XMLSerializerMixin
from testpkg.subpkg.code import PackagedClass
MODULE_NAME = __name__
class Foo(XMLSerializerMixin):
x = 1
def __init__(self, y):
self.y = y
foo_xml = ('<Foo module="{0}">'
+ '<y>'
+ '<int module="__builtin__">2</int>'
+ '</y>'
+'</Foo>').format(MODULE_NAME)
class Bar(XMLSerializerMixin):
def __init__(self, myfoo, x, s):
self.myfoo = myfoo
self.x = x
self.s = s
bar_xml = ('<Bar module="{0}">'
+ '<x>'
+ '<int module="__builtin__">1</int>'
+ '</x>'
+ '<s>'
+ '<str module="__builtin__">hola</str>'
+ '</s>'
+ '<myfoo>'
+ '<Foo module="{0}">'
+ '<y>'
+ '<int module="__builtin__">2</int>'
+ '</y>'
+ '</Foo>'
+ '</myfoo>'
+'</Bar>').format(MODULE_NAME)
class Dic(XMLSerializerMixin):
def __init__(self, d):
self.mydict = d
dic_xml = ('<Dic module="{0}">'
+ '<mydict>'
+ '<dict module="__builtin__">'
+ '<entry>'
+ '<key>'
+ '<int module="__builtin__">1</int>'
+ '</key>'
+ '<value>'
+ '<str module="__builtin__">hola</str>'
+ '</value>'
+ '</entry>'
+ '<entry>'
+ '<key>'
+ '<int module="__builtin__">2</int>'
+ '</key>'
+ '<value>'
+ '<str module="__builtin__">adios</str>'
+ '</value>'
+ '</entry>'
+ '</dict>'
+ '</mydict>'
+'</Dic>').format(MODULE_NAME)
class Lst(XMLSerializerMixin):
def __init__(self, l):
self.mylist = l
lst_xml = ('<Lst module="{0}">'
+ '<mylist>'
+ '<list module="__builtin__">'
+ '<element>'
+ '<int module="__builtin__">1</int>'
+ '</element>'
+ '<element>'
+ '<str module="__builtin__">hola</str>'
+ '</element>'
+ '</list>'
+ '</mylist>'
+'</Lst>').format(MODULE_NAME)
class Tup(XMLSerializerMixin):
def __init__(self, t):
self.mytuple = t
tup_xml = ('<Tup module="{0}">'
+ '<mytuple>'
+ '<tuple module="__builtin__">'
+ '<element>'
+ '<int module="__builtin__">1</int>'
+ '</element>'
+ '<element>'
+ '<str module="__builtin__">hola</str>'
+ '</element>'
+ '</tuple>'
+ '</mytuple>'
+'</Tup>').format(MODULE_NAME)
class RandomClass(object):
def __init__(self, x):
self.x = x
class NestedWithRandomClass(XMLSerializerMixin):
def __init__(self):
self.rc = RandomClass(1)
rand_xml = ('<NestedWithRandomClass module="{0}">'
+ '<rc>'
+ '<RandomClass module="{0}">'
+ '<x>'
+ '<int module="__builtin__">1</int>'
+ '</x>'
+ '</RandomClass>'
+ '</rc>'
+'</NestedWithRandomClass>').format(MODULE_NAME)
class Packaged(XMLSerializerMixin):
def __init__(self):
self.pkgd = PackagedClass(1)
pkgd_cls_xml = ('<Packaged module="{0}">'
+ '<pkgd>'
+ '<PackagedClass module="testpkg.subpkg.code">'
+ '<x>'
+ '<int module="__builtin__">1</int>'
+ '</x>'
+ '</PackagedClass>'
+ '</pkgd>'
+'</Packaged>').format(MODULE_NAME)
class NestedDictionaryListAndTuple(XMLSerializerMixin):
def __init__(self):
self.dic = {Foo(2):RandomClass(1)}
self.lst = [Bar(Foo(2), 1, 'hola')]
self.tup = (NestedWithRandomClass(), Packaged())
nested_dic_lst_tup_xml = ('<NestedDictionaryListAndTuple module="{0}">'
+ '<tup>'
+ '<tuple module="__builtin__">'
+ '<element>'
+ rand_xml
+ '</element>'
+ '<element>'
+ pkgd_cls_xml
+ '</element>'
+ '</tuple>'
+ '</tup>'
+ '<lst>'
+ '<list module="__builtin__">'
+ '<element>'
+ bar_xml
+ '</element>'
+ '</list>'
+ '</lst>'
+ '<dic>'
+ '<dict module="__builtin__">'
+ '<entry>'
+ '<key>'
+ foo_xml
+ '</key>'
+ '<value>'
+ '<RandomClass module="{0}">'
+ '<x>'
+ '<int module="__builtin__">1</int>'
+ '</x>'
+ '</RandomClass>'
+ '</value>'
+ '</entry>'
+ '</dict>'
+ '</dic>'
+'</NestedDictionaryListAndTuple>').format(MODULE_NAME)