summaryrefslogtreecommitdiffstats
path: root/_test/test_documents.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_documents.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_documents.py')
-rw-r--r--_test/test_documents.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/_test/test_documents.py b/_test/test_documents.py
new file mode 100644
index 0000000..b750d5f
--- /dev/null
+++ b/_test/test_documents.py
@@ -0,0 +1,75 @@
+# coding: utf-8
+
+import pytest # NOQA
+
+from .roundtrip import round_trip, round_trip_dump_all, round_trip_load_all
+
+
+class TestDocument:
+ def test_single_doc_begin_end(self):
+ inp = """\
+ ---
+ - a
+ - b
+ ...
+ """
+ round_trip(inp, explicit_start=True, explicit_end=True)
+
+ def test_multi_doc_begin_end(self):
+ inp = """\
+ ---
+ - a
+ ...
+ ---
+ - b
+ ...
+ """
+ docs = list(round_trip_load_all(inp))
+ assert docs == [['a'], ['b']]
+ out = round_trip_dump_all(docs, explicit_start=True, explicit_end=True)
+ assert out == '---\n- a\n...\n---\n- b\n...\n'
+
+ def test_multi_doc_no_start(self):
+ inp = """\
+ - a
+ ...
+ ---
+ - b
+ ...
+ """
+ docs = list(round_trip_load_all(inp))
+ assert docs == [['a'], ['b']]
+
+ def test_multi_doc_no_end(self):
+ inp = """\
+ - a
+ ---
+ - b
+ """
+ docs = list(round_trip_load_all(inp))
+ assert docs == [['a'], ['b']]
+
+ def test_multi_doc_ends_only(self):
+ # this is ok in 1.2
+ inp = """\
+ - a
+ ...
+ - b
+ ...
+ """
+ docs = list(round_trip_load_all(inp, version=(1, 2)))
+ assert docs == [['a'], ['b']]
+
+ def test_multi_doc_ends_only_1_1(self):
+ import ruyaml
+
+ # this is not ok in 1.1
+ with pytest.raises(ruyaml.parser.ParserError):
+ inp = """\
+ - a
+ ...
+ - b
+ ...
+ """
+ docs = list(round_trip_load_all(inp, version=(1, 1)))
+ assert docs == [['a'], ['b']] # not True, but not reached