10 from sets
import Set
as set
14 class MyLoader(Loader
):
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 MyLoader
.add_constructor("!tag1", construct1
)
33 class MyTestClass2(MyTestClass1
, YAMLObject
):
35 yaml_loader
= MyLoader
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 YAMLObject1(YAMLObject
):
57 yaml_loader
= MyLoader
60 def __init__(self
, my_parameter
=None, my_another_parameter
=None):
61 self
.my_parameter
= my_parameter
62 self
.my_another_parameter
= my_another_parameter
64 def __eq__(self
, other
):
65 if isinstance(other
, YAMLObject1
):
66 return self
.__class
__, self
.__dict
__ == other
.__class
__, other
.__dict
__
70 class TestTypes(test_appliance
.TestAppliance
):
72 def _testTypes(self
, test_name
, data_filename
, code_filename
):
76 data1
= list(load_all(file(data_filename
, 'rb'), Loader
=MyLoader
))
79 data2
= eval(file(code_filename
, 'rb').read())
81 self
.failUnlessEqual(data1
, data2
)
82 except AssertionError:
83 if isinstance(data1
, dict):
95 print file(data_filename
, 'rb').read()
97 print file(code_filename
, 'rb').read()
98 print "NATIVES1:", data1
99 print "NATIVES2:", data2
102 TestTypes
.add_tests('testTypes', '.data', '.code')