Fix timestamp constructing and representing (close #25).
[pyyaml/python3.git] / tests / test_recursive.py
blob3c092642d3d93b4016988eb769a92a00355d00e4
2 import test_appliance
4 from yaml import *
6 class AnInstance:
8 def __init__(self, foo, bar):
9 self.foo = foo
10 self.bar = bar
12 def __repr__(self):
13 try:
14 return "%s(foo=%r, bar=%r)" % (self.__class__.__name__,
15 self.foo, self.bar)
16 except RuntimeError:
17 return "%s(foo=..., bar=...)" % self.__class__.__name__
19 class AnInstanceWithState(AnInstance):
21 def __getstate__(self):
22 return {'attributes': [self.foo, self.bar]}
24 def __setstate__(self, state):
25 self.foo, self.bar = state['attributes']
27 class TestRecursive(test_appliance.TestAppliance):
29 def _testRecursive(self, test_name, recursive_filename):
30 exec file(recursive_filename, 'r').read()
31 value1 = value
32 output1 = None
33 value2 = None
34 output2 = None
35 try:
36 output1 = dump(value1)
37 #print "OUTPUT %s:" % test_name
38 #print output1
39 value2 = load(output1)
40 output2 = dump(value2)
41 self.failUnlessEqual(output1, output2)
42 except:
43 print "VALUE1:", value1
44 print "VALUE2:", value2
45 print "OUTPUT1:"
46 print output1
47 print "OUTPUT2:"
48 print output2
49 raise
51 TestRecursive.add_tests('testRecursive', '.recursive')