File: test_documents.py

package info (click to toggle)
python-srsly 2.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,256 kB
  • sloc: python: 17,567; ansic: 1,434; sh: 12; makefile: 6
file content (79 lines) | stat: -rwxr-xr-x 1,827 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# coding: utf-8

import pytest  # NOQA

from .roundtrip import round_trip, 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):
        from srsly.ruamel_yaml import dump_all, RoundTripDumper

        inp = """\
        ---
        - a
        ...
        ---
        - b
        ...
        """
        docs = list(round_trip_load_all(inp))
        assert docs == [["a"], ["b"]]
        out = dump_all(
            docs, Dumper=RoundTripDumper, 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):
        from srsly.ruamel_yaml import parser

        # this is not ok in 1.1
        with pytest.raises(parser.ParserError):
            inp = """\
            - a
            ...
            - b
            ...
            """
            docs = list(round_trip_load_all(inp, version=(1, 1)))
            assert docs == [["a"], ["b"]]  # not True, but not reached