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