MCPcopy Create free account
hub / github.com/ActiveState/code / test

Function test

recipes/Python/576943_Serialize_Deserialize/recipe-576943.py:95–121  ·  view source on GitHub ↗
(supressoutput = False)

Source from the content-addressed store, hash-verified

93 return nodaldict[0].pop()
94
95def test(supressoutput = False):
96 testvectors = [
97 list(((None, True, False), (1, 12341234123412341234123412341234L,0.5),
98 0.12341234123412341234,
99 u'This is\nan\tUnicode string\u0A0D\N{HANGUL SYLLABLE BYENH}',
100 set(('A','B','D')),
101 frozenset(tuple((1, '9', -0.12341234123412341234+1j, 'Y'))))),
102 tuple(),
103 list(),
104 set(),
105 frozenset(),
106 'Element that is not nested.',
107 {'a': (1, "Waka"), ('X', 'K'): u'CD', u'y':{ 1:'O', 2:('T','wo')}}]
108
109 # Recursion not yet properly supported.
110 #x = {'a': None, 'z': None}
111 #y = {'x': x}
112 #x['y'] = y
113 #testvectors.extend([x,y])
114 for root in testvectors:
115 serialized = serialize(root)
116 inverse = deserialize(serialized)
117 if not supressoutput:
118 print "Expected: ", repr(root)
119 print "Returned: ", repr(inverse)
120 if (inverse != root):
121 raise ValueError, "The test failed."
122
123if __name__ == '__main__':
124 print "Running test..."

Callers 1

recipe-576943.pyFile · 0.70

Calls 4

listClass · 0.85
serializeFunction · 0.70
deserializeFunction · 0.70
setFunction · 0.50

Tested by

no test coverage detected