summaryrefslogtreecommitdiffstats
path: root/_test/test_copy.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/test_copy.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/test_copy.py')
-rw-r--r--_test/test_copy.py135
1 files changed, 135 insertions, 0 deletions
diff --git a/_test/test_copy.py b/_test/test_copy.py
new file mode 100644
index 0000000..7ebd4c1
--- /dev/null
+++ b/_test/test_copy.py
@@ -0,0 +1,135 @@
+# coding: utf-8
+
+"""
+Testing copy and deepcopy, instigated by Issue 84 (Peter Amstutz)
+"""
+
+import copy
+
+import pytest # NOQA
+
+from .roundtrip import dedent, round_trip_dump, round_trip_load
+
+
+class TestDeepCopy:
+ def test_preserve_flow_style_simple(self):
+ x = dedent(
+ """\
+ {foo: bar, baz: quux}
+ """
+ )
+ data = round_trip_load(x)
+ data_copy = copy.deepcopy(data)
+ y = round_trip_dump(data_copy)
+ print('x [{}]'.format(x))
+ print('y [{}]'.format(y))
+ assert y == x
+ assert data.fa.flow_style() == data_copy.fa.flow_style()
+
+ def test_deepcopy_flow_style_nested_dict(self):
+ x = dedent(
+ """\
+ a: {foo: bar, baz: quux}
+ """
+ )
+ data = round_trip_load(x)
+ assert data['a'].fa.flow_style() is True
+ data_copy = copy.deepcopy(data)
+ assert data_copy['a'].fa.flow_style() is True
+ data_copy['a'].fa.set_block_style()
+ assert data['a'].fa.flow_style() != data_copy['a'].fa.flow_style()
+ assert data['a'].fa._flow_style is True
+ assert data_copy['a'].fa._flow_style is False
+ y = round_trip_dump(data_copy)
+
+ print('x [{}]'.format(x))
+ print('y [{}]'.format(y))
+ assert y == dedent(
+ """\
+ a:
+ foo: bar
+ baz: quux
+ """
+ )
+
+ def test_deepcopy_flow_style_nested_list(self):
+ x = dedent(
+ """\
+ a: [1, 2, 3]
+ """
+ )
+ data = round_trip_load(x)
+ assert data['a'].fa.flow_style() is True
+ data_copy = copy.deepcopy(data)
+ assert data_copy['a'].fa.flow_style() is True
+ data_copy['a'].fa.set_block_style()
+ assert data['a'].fa.flow_style() != data_copy['a'].fa.flow_style()
+ assert data['a'].fa._flow_style is True
+ assert data_copy['a'].fa._flow_style is False
+ y = round_trip_dump(data_copy)
+
+ print('x [{}]'.format(x))
+ print('y [{}]'.format(y))
+ assert y == dedent(
+ """\
+ a:
+ - 1
+ - 2
+ - 3
+ """
+ )
+
+
+class TestCopy:
+ def test_copy_flow_style_nested_dict(self):
+ x = dedent(
+ """\
+ a: {foo: bar, baz: quux}
+ """
+ )
+ data = round_trip_load(x)
+ assert data['a'].fa.flow_style() is True
+ data_copy = copy.copy(data)
+ assert data_copy['a'].fa.flow_style() is True
+ data_copy['a'].fa.set_block_style()
+ assert data['a'].fa.flow_style() == data_copy['a'].fa.flow_style()
+ assert data['a'].fa._flow_style is False
+ assert data_copy['a'].fa._flow_style is False
+ y = round_trip_dump(data_copy)
+ z = round_trip_dump(data)
+ assert y == z
+
+ assert y == dedent(
+ """\
+ a:
+ foo: bar
+ baz: quux
+ """
+ )
+
+ def test_copy_flow_style_nested_list(self):
+ x = dedent(
+ """\
+ a: [1, 2, 3]
+ """
+ )
+ data = round_trip_load(x)
+ assert data['a'].fa.flow_style() is True
+ data_copy = copy.copy(data)
+ assert data_copy['a'].fa.flow_style() is True
+ data_copy['a'].fa.set_block_style()
+ assert data['a'].fa.flow_style() == data_copy['a'].fa.flow_style()
+ assert data['a'].fa._flow_style is False
+ assert data_copy['a'].fa._flow_style is False
+ y = round_trip_dump(data_copy)
+
+ print('x [{}]'.format(x))
+ print('y [{}]'.format(y))
+ assert y == dedent(
+ """\
+ a:
+ - 1
+ - 2
+ - 3
+ """
+ )