diff options
author | Tina Müller <cpan2@tinita.de> | 2021-09-23 19:56:28 +0200 |
---|---|---|
committer | Tina Müller <cpan2@tinita.de> | 2021-09-24 22:18:36 +0200 |
commit | 737ad62df0352a62c97e9fdbd0efe7860f7f1791 (patch) | |
tree | 914a6447080038e5be2cb18559d13f46d84d9c63 /tests/lib/test_constructor.py | |
parent | bd96e4000cff5a53bee565969871fbe4c8142a1a (diff) | |
download | pyyaml-git-override-anchor.tar.gz |
Also add reuse_anchors to libyaml backendoverride-anchor
Diffstat (limited to 'tests/lib/test_constructor.py')
-rw-r--r-- | tests/lib/test_constructor.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/lib/test_constructor.py b/tests/lib/test_constructor.py index f7d1995..968db71 100644 --- a/tests/lib/test_constructor.py +++ b/tests/lib/test_constructor.py @@ -258,7 +258,7 @@ def test_constructor_types(data_filename, code_filename, verbose=False): native2 = None try: with open(data_filename, 'rb') as file: - native1 = list(yaml.load_all(file, Loader=MyLoader, reuse_anchors=True)) + native1 = list(yaml.load_all(file, Loader=MyLoader)) if len(native1) == 1: native1 = native1[0] with open(code_filename, 'rb') as file: @@ -296,6 +296,34 @@ def test_subclass_blacklist_types(data_filename, verbose=False): test_subclass_blacklist_types.unittest = ['.subclass_blacklist'] +def test_reuse_anchors(data_filename, code_filename, verbose=False): + try: + with open(data_filename, 'rb') as file: + native1 = list(yaml.load_all(file, Loader=yaml.SafeLoader, reuse_anchors=True)) + if len(native1) == 1: + native1 = native1[0] + with open(code_filename, 'rb') as file: + native2 = _load_code(file.read()) + try: + if native1 == native2: + return + except TypeError: + pass + if verbose: + print("SERIALIZED NATIVE1:") + print(_serialize_value(native1)) + print("SERIALIZED NATIVE2:") + print(_serialize_value(native2)) + assert _serialize_value(native1) == _serialize_value(native2), (native1, native2) + finally: + if verbose: + print("NATIVE1:") + pprint.pprint(native1) + print("NATIVE2:") + pprint.pprint(native2) + +test_reuse_anchors.unittest = ['.reuse-anchors-data', '.reuse-anchors-code'] + if __name__ == '__main__': import sys, test_constructor sys.modules['test_constructor'] = sys.modules['__main__'] |