summaryrefslogtreecommitdiff
path: root/_test/test_version.py
blob: 742ec3652a1fc042f0a78c0993585bb0f17e8e22 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# coding: utf-8

import pytest  # NOQA

from roundtrip import dedent, round_trip, round_trip_load


def load(s, version=None):
    import ruamel.yaml  # NOQA

    return ruamel.yaml.round_trip_load(dedent(s), version)


class TestVersions:
    def test_explicit_1_2(self):
        r = load("""\
        %YAML 1.2
        ---
        - 12:34:56
        - 012
        - 012345678
        - 0o12
        - on
        - off
        - yes
        - no
        - true
        """)
        assert r[0] == '12:34:56'
        assert r[1] == 12
        assert r[2] == 12345678
        assert r[3] == 10
        assert r[4] == 'on'
        assert r[5] == 'off'
        assert r[6] == 'yes'
        assert r[7] == 'no'
        assert r[8] is True

    def test_explicit_1_1(self):
        r = load("""\
        %YAML 1.1
        ---
        - 12:34:56
        - 012
        - 012345678
        - 0o12
        - on
        - off
        - yes
        - no
        - true
        """)
        assert r[0] == 45296
        assert r[1] == 10
        assert r[2] == '012345678'
        assert r[3] == '0o12'
        assert r[4] is True
        assert r[5] is False
        assert r[6] is True
        assert r[7] is False
        assert r[8] is True

    def test_implicit_1_2(self):
        r = load("""\
        - 12:34:56
        - 12:34:56.78
        - 012
        - 012345678
        - 0o12
        - on
        - off
        - yes
        - no
        - true
        """)
        assert r[0] == '12:34:56'
        assert r[1] == '12:34:56.78'
        assert r[2] == 12
        assert r[3] == 12345678
        assert r[4] == 10
        assert r[5] == 'on'
        assert r[6] == 'off'
        assert r[7] == 'yes'
        assert r[8] == 'no'
        assert r[9] is True

    def test_load_version_1_1(self):
        inp = """\
        - 12:34:56
        - 12:34:56.78
        - 012
        - 012345678
        - 0o12
        - on
        - off
        - yes
        - no
        - true
        """
        r = load(inp, version='1.1')
        assert r[0] == 45296
        assert r[1] == 45296.78
        assert r[2] == 10
        assert r[3] == '012345678'
        assert r[4] == '0o12'
        assert r[5] is True
        assert r[6] is False
        assert r[7] is True
        assert r[8] is False
        assert r[9] is True


class TestIssue62:
    # bitbucket issue 62, issue_62
    def test_00(self):
        import ruamel.yaml  # NOQA

        s = dedent("""\
        {}# Outside flow collection:
        - ::vector
        - ": - ()"
        - Up, up, and away!
        - -123
        - http://example.com/foo#bar
        # Inside flow collection:
        - [::vector, ": - ()", "Down, down and away!", -456, http://example.com/foo#bar]
        """)
        with pytest.raises(ruamel.yaml.parser.ParserError):
            round_trip(s.format('%YAML 1.1\n---\n'), preserve_quotes=True)
        round_trip(s.format(""), preserve_quotes=True)

    def test_00_single_comment(self):
        import ruamel.yaml  # NOQA

        s = dedent("""\
        {}# Outside flow collection:
        - ::vector
        - ": - ()"
        - Up, up, and away!
        - -123
        - http://example.com/foo#bar
        - [::vector, ": - ()", "Down, down and away!", -456, http://example.com/foo#bar]
        """)
        with pytest.raises(ruamel.yaml.parser.ParserError):
            round_trip(s.format('%YAML 1.1\n---\n'), preserve_quotes=True)
        round_trip(s.format(""), preserve_quotes=True)
        # round_trip(s.format('%YAML 1.2\n---\n'), preserve_quotes=True, version=(1, 2))

    def test_01(self):
        import ruamel.yaml  # NOQA

        s = dedent("""\
        {}[random plain value that contains a ? character]
        """)
        with pytest.raises(ruamel.yaml.parser.ParserError):
            round_trip(s.format('%YAML 1.1\n---\n'), preserve_quotes=True)
        round_trip(s.format(""), preserve_quotes=True)
        # note the flow seq on the --- line!
        round_trip(s.format('%YAML 1.2\n--- '), preserve_quotes=True, version='1.2')

    def test_so_45681626(self):
        # was not properly parsing
        round_trip_load('{"in":{},"out":{}}')