summaryrefslogtreecommitdiffstats
path: root/_test/lib/test_representer.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 20:19:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 20:19:53 +0000
commite7ee850d46d54789979bf0c5244bae1825fb7149 (patch)
tree6e94ed55df9ec749682a3c792ce752d07892b968 /_test/lib/test_representer.py
parentInitial commit. (diff)
downloadpython-ruyaml-e7ee850d46d54789979bf0c5244bae1825fb7149.tar.xz
python-ruyaml-e7ee850d46d54789979bf0c5244bae1825fb7149.zip
Adding upstream version 0.91.0.upstream/0.91.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '_test/lib/test_representer.py')
-rw-r--r--_test/lib/test_representer.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/_test/lib/test_representer.py b/_test/lib/test_representer.py
new file mode 100644
index 0000000..9eb290c
--- /dev/null
+++ b/_test/lib/test_representer.py
@@ -0,0 +1,59 @@
+import ruyaml as yaml
+
+YAML = yaml.YAML
+
+import pprint
+
+# Skipped because we have no idea where the "code_filename"
+# fixture is supposed to come from
+import pytest
+import test_constructor
+
+pytestmark = pytest.mark.skip
+
+
+def test_representer_types(code_filename, verbose=False):
+ yaml = YAML(typ='safe', pure=True)
+ test_constructor._make_objects()
+ for allow_unicode in [False, True]:
+ for encoding in ['utf-8', 'utf-16-be', 'utf-16-le']:
+ with open(code_filename, 'rb') as fp0:
+ native1 = test_constructor._load_code(fp0.read())
+ native2 = None
+ try:
+ output = yaml.dump(
+ native1,
+ Dumper=test_constructor.MyDumper,
+ allow_unicode=allow_unicode,
+ encoding=encoding,
+ )
+ native2 = yaml.load(output, Loader=test_constructor.MyLoader)
+ try:
+ if native1 == native2:
+ continue
+ except TypeError:
+ pass
+ value1 = test_constructor._serialize_value(native1)
+ value2 = test_constructor._serialize_value(native2)
+ if verbose:
+ print('SERIALIZED NATIVE1:')
+ print(value1)
+ print('SERIALIZED NATIVE2:')
+ print(value2)
+ assert value1 == value2, (native1, native2)
+ finally:
+ if verbose:
+ print('NATIVE1:')
+ pprint.pprint(native1)
+ print('NATIVE2:')
+ pprint.pprint(native2)
+ print('OUTPUT:')
+ print(output)
+
+
+test_representer_types.unittest = ['.code']
+
+if __name__ == '__main__':
+ import test_appliance
+
+ test_appliance.run(globals())