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
|
# coding: utf-8
import pytest # NOQA
from roundtrip import round_trip, round_trip_load, YAML
def register_xxx(**kw):
from ruamel import yaml
class XXX(yaml.comments.CommentedMap):
@staticmethod
def yaml_dump(dumper, data):
return dumper.represent_mapping('!xxx', data)
@classmethod
def yaml_load(cls, constructor, node):
data = cls()
yield data
constructor.construct_mapping(node, data)
yaml.add_constructor('!xxx', XXX.yaml_load, constructor=yaml.RoundTripConstructor)
yaml.add_representer(XXX, XXX.yaml_dump, representer=yaml.RoundTripRepresenter)
class TestIndentFailures:
def test_tag(self):
round_trip("""\
!!python/object:__main__.Developer
name: Anthon
location: Germany
language: python
""")
def test_full_tag(self):
round_trip("""\
!!tag:yaml.org,2002:python/object:__main__.Developer
name: Anthon
location: Germany
language: python
""")
def test_standard_tag(self):
round_trip("""\
!!tag:yaml.org,2002:python/object:map
name: Anthon
location: Germany
language: python
""")
def test_Y1(self):
round_trip("""\
!yyy
name: Anthon
location: Germany
language: python
""")
def test_Y2(self):
round_trip("""\
!!yyy
name: Anthon
location: Germany
language: python
""")
class TestRoundTripCustom:
def test_X1(self):
register_xxx()
round_trip("""\
!xxx
name: Anthon
location: Germany
language: python
""")
@pytest.mark.xfail(strict=True)
def test_X_pre_tag_comment(self):
register_xxx()
round_trip("""\
-
# hello
!xxx
name: Anthon
location: Germany
language: python
""")
@pytest.mark.xfail(strict=True)
def test_X_post_tag_comment(self):
register_xxx()
round_trip("""\
- !xxx
# hello
name: Anthon
location: Germany
language: python
""")
def test_scalar_00(self):
# https://stackoverflow.com/a/45967047/1307905
round_trip("""\
Outputs:
Vpc:
Value: !Ref: vpc # first tag
Export:
Name: !Sub "${AWS::StackName}-Vpc" # second tag
""")
class TestIssue201:
def test_encoded_unicode_tag(self):
round_trip_load("""
s: !!python/%75nicode 'abc'
""")
class TestImplicitTaggedNodes:
def test_scalar(self):
round_trip("""\
- !Scalar abcdefg
""")
def test_mapping(self):
round_trip("""\
- !Mapping {a: 1, b: 2}
""")
def test_sequence(self):
yaml = YAML()
yaml.brace_single_entry_mapping_in_flow_sequence = True
yaml.mapping_value_align = True
yaml.round_trip("""
- !Sequence [a, {b: 1}, {c: {d: 3}}]
""")
def test_sequence2(self):
yaml = YAML()
yaml.mapping_value_align = True
yaml.round_trip("""
- !Sequence [a, b: 1, c: {d: 3}]
""")
|