• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2import yaml
3import test_constructor
4import pprint
5
6def test_representer_types(code_filename, verbose=False):
7    test_constructor._make_objects()
8    for allow_unicode in [False, True]:
9        for encoding in ['utf-8', 'utf-16-be', 'utf-16-le']:
10            with open(code_filename, 'rb') as file:
11                native1 = test_constructor._load_code(file.read())
12            native2 = None
13            try:
14                output = yaml.dump(native1, Dumper=test_constructor.MyDumper,
15                            allow_unicode=allow_unicode, encoding=encoding)
16                native2 = yaml.load(output, Loader=test_constructor.MyLoader)
17                try:
18                    if native1 == native2:
19                        continue
20                except TypeError:
21                    pass
22                value1 = test_constructor._serialize_value(native1)
23                value2 = test_constructor._serialize_value(native2)
24                if verbose:
25                    print("SERIALIZED NATIVE1:")
26                    print(value1)
27                    print("SERIALIZED NATIVE2:")
28                    print(value2)
29                assert value1 == value2, (native1, native2)
30            finally:
31                if verbose:
32                    print("NATIVE1:")
33                    pprint.pprint(native1)
34                    print("NATIVE2:")
35                    pprint.pprint(native2)
36                    print("OUTPUT:")
37                    print(output)
38
39test_representer_types.unittest = ['.code']
40
41if __name__ == '__main__':
42    import test_appliance
43    test_appliance.run(globals())
44
45