10 from sets
import Set
as set
14 class MyConstructor(Constructor
):
19 def __init__(self
, x
, y
=0, z
=0):
24 def __eq__(self
, other
):
25 return self
.__class
__, self
.__dict
__ == other
.__class
__, other
.__dict
__
27 def construct1(constructor
, node
):
28 mapping
= constructor
.construct_mapping(node
)
29 return MyTestClass1(**mapping
)
31 MyConstructor
.add_constructor("!tag1", construct1
)
33 class MyTestClass2(MyTestClass1
, YAMLObject
):
35 yaml_constructor
= MyConstructor
38 def from_yaml(cls
, constructor
, node
):
39 x
= constructor
.construct_yaml_int(node
)
41 from_yaml
= classmethod(from_yaml
)
43 class MyTestClass3(MyTestClass2
):
47 def from_yaml(cls
, constructor
, node
):
48 mapping
= constructor
.construct_mapping(node
)
54 from_yaml
= classmethod(from_yaml
)
56 class TestTypes(test_appliance
.TestAppliance
):
58 def _testTypes(self
, test_name
, data_filename
, code_filename
):
62 constructor1
= MyConstructor(Resolver(Composer(Parser(Scanner(Reader(file(data_filename
, 'rb')))))))
63 natives1
= list(iter(constructor1
))
64 if len(natives1
) == 1:
65 natives1
= natives1
[0]
66 natives2
= eval(file(code_filename
, 'rb').read())
68 self
.failUnlessEqual(natives1
, natives2
)
69 except AssertionError:
70 if isinstance(natives1
, dict):
71 natives1
= natives1
.items()
73 natives1
= repr(natives1
)
74 natives2
= natives2
.items()
76 natives2
= repr(natives2
)
77 if natives1
!= natives2
:
82 print file(data_filename
, 'rb').read()
84 print file(code_filename
, 'rb').read()
85 print "NATIVES1:", natives1
86 print "NATIVES2:", natives2
89 TestTypes
.add_tests('testTypes', '.data', '.code')