summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2018-08-15 16:15:16 +0200
committerAnthon van der Neut <anthon@mnt.org>2018-08-15 16:15:16 +0200
commit21e5474048c6a5b9a267c3717078cd207ee0bdb1 (patch)
tree99c224edb71ba91941e19e3b13411989b37a5b3a
parentd89af927856c1f7f24cbc71045ae04e1cd375071 (diff)
downloadruamel.yaml-21e5474048c6a5b9a267c3717078cd207ee0bdb1.tar.gz
oitnb formats all tests
-rw-r--r--_test/test_comment_manipulation.py151
-rw-r--r--_test/test_comments.py15
-rw-r--r--_test/test_datetime.py72
-rw-r--r--_test/test_documents.py31
-rw-r--r--_test/test_fail.py33
-rw-r--r--_test/test_flowsequencekey.py5
-rw-r--r--_test/test_indentation.py108
-rw-r--r--_test/test_literal.py91
-rw-r--r--_test/test_string.py66
-rw-r--r--_test/test_version.py5
10 files changed, 351 insertions, 226 deletions
diff --git a/_test/test_comment_manipulation.py b/_test/test_comment_manipulation.py
index bdddb5b..ad0a768 100644
--- a/_test/test_comment_manipulation.py
+++ b/_test/test_comment_manipulation.py
@@ -17,8 +17,10 @@ def compare(data, s, **kw):
def compare_eol(data, s):
assert 'EOL' in s
- assert round_trip_dump(data).replace('\n', '|\n') == \
- dedent(s).replace('EOL', '').replace('\n', '|\n')
+ ds = dedent(s).replace('EOL', '').replace('\n', '|\n')
+ assert round_trip_dump(data).replace('\n', '|\n') == ds
+
+
# @pytest.mark.xfail
@@ -32,11 +34,12 @@ class TestCommentsManipulation:
- c
""")
data.yaml_add_eol_comment('comment 2', key=1, column=6)
- compare(data, """
+ exp = """
- a # comment 1
- b # comment 2
- c
- """)
+ """
+ compare(data, exp)
def test_seq_overwrite_comment_on_existing_explicit_column(self):
data = load("""
@@ -45,11 +48,12 @@ class TestCommentsManipulation:
- c
""")
data.yaml_add_eol_comment('comment 2', key=0, column=6)
- compare(data, """
+ exp = """
- a # comment 2
- b
- c
- """)
+ """
+ compare(data, exp)
def test_seq_first_comment_explicit_column(self):
data = load("""
@@ -58,11 +62,12 @@ class TestCommentsManipulation:
- c
""")
data.yaml_add_eol_comment('comment 1', key=1, column=6)
- compare(data, """
+ exp = """
- a
- b # comment 1
- c
- """)
+ """
+ compare(data, exp)
def test_seq_set_comment_on_existing_column_prev(self):
data = load("""
@@ -72,12 +77,13 @@ class TestCommentsManipulation:
- d # comment 3
""")
data.yaml_add_eol_comment('comment 2', key=1)
- compare(data, """
+ exp = """
- a # comment 1
- b # comment 2
- c
- d # comment 3
- """)
+ """
+ compare(data, exp)
def test_seq_set_comment_on_existing_column_next(self):
data = load("""
@@ -91,12 +97,13 @@ class TestCommentsManipulation:
# ruamel.yaml.error.Mark
# print(type(data._yaml_comment._items[0][0].start_mark))
data.yaml_add_eol_comment('comment 2', key=2)
- compare(data, """
+ exp = """
- a # comment 1
- b
- c # comment 2
- d # comment 3
- """)
+ """
+ compare(data, exp)
def test_seq_set_comment_on_existing_column_further_away(self):
"""
@@ -116,14 +123,15 @@ class TestCommentsManipulation:
# ruamel.yaml.error.Mark
# print(type(data._yaml_comment._items[0][0].start_mark))
data.yaml_add_eol_comment('comment 2', key=3)
- compare(data, """
+ exp = """
- a # comment 1
- b
- c
- d # comment 2
- e
- f # comment 3
- """)
+ """
+ compare(data, exp)
def test_seq_set_comment_on_existing_explicit_column_with_hash(self):
data = load("""
@@ -132,11 +140,12 @@ class TestCommentsManipulation:
- c
""")
data.yaml_add_eol_comment('# comment 2', key=1, column=6)
- compare(data, """
+ exp = """
- a # comment 1
- b # comment 2
- c
- """)
+ """
+ compare(data, exp)
# dict
@@ -149,13 +158,14 @@ class TestCommentsManipulation:
e: 5
""")
data.yaml_add_eol_comment('comment 2', key='c', column=7)
- compare(data, """
+ exp = """
a: 1 # comment 1
b: 2
c: 3 # comment 2
d: 4
e: 5
- """)
+ """
+ compare(data, exp)
def test_dict_overwrite_comment_on_existing_explicit_column(self):
data = load("""
@@ -166,13 +176,14 @@ class TestCommentsManipulation:
e: 5
""")
data.yaml_add_eol_comment('comment 2', key='a', column=7)
- compare(data, """
+ exp = """
a: 1 # comment 2
b: 2
c: 3
d: 4
e: 5
- """)
+ """
+ compare(data, exp)
def test_map_set_comment_on_existing_column_prev(self):
data = load("""
@@ -183,13 +194,14 @@ class TestCommentsManipulation:
e: 5 # comment 3
""")
data.yaml_add_eol_comment('comment 2', key='b')
- compare(data, """
+ exp = """
a: 1 # comment 1
b: 2 # comment 2
c: 3
d: 4
e: 5 # comment 3
- """)
+ """
+ compare(data, exp)
def test_map_set_comment_on_existing_column_next(self):
data = load("""
@@ -200,13 +212,14 @@ class TestCommentsManipulation:
e: 5 # comment 3
""")
data.yaml_add_eol_comment('comment 2', key='d')
- compare(data, """
+ exp = """
a: 1 # comment 1
b: 2
c: 3
d: 4 # comment 2
e: 5 # comment 3
- """)
+ """
+ compare(data, exp)
def test_map_set_comment_on_existing_column_further_away(self):
"""
@@ -222,13 +235,14 @@ class TestCommentsManipulation:
""")
data.yaml_add_eol_comment('comment 2', key='c')
print(round_trip_dump(data))
- compare(data, """
+ exp = """
a: 1 # comment 1
b: 2
c: 3 # comment 2
d: 4
e: 5 # comment 3
- """)
+ """
+ compare(data, exp)
# @pytest.mark.xfail
def test_before_top_map_rt(self):
@@ -237,12 +251,13 @@ class TestCommentsManipulation:
b: 2
""")
data.yaml_set_start_comment('Hello\nWorld\n')
- compare(data, """
+ exp = """
# Hello
# World
a: 1
b: 2
- """.format(comment='#'))
+ """
+ compare(data, exp.format(comment='#'))
def test_before_top_map_replace(self):
data = load("""
@@ -252,12 +267,13 @@ class TestCommentsManipulation:
b: 2
""")
data.yaml_set_start_comment('Hello\nWorld\n')
- compare(data, """
+ exp = """
# Hello
# World
a: 1 # 1
b: 2
- """.format(comment='#'))
+ """
+ compare(data, exp.format(comment='#'))
def test_before_top_map_from_scratch(self):
from ruamel.yaml.comments import CommentedMap
@@ -268,12 +284,13 @@ class TestCommentsManipulation:
data.yaml_set_start_comment('Hello\nWorld\n')
# print(data.ca)
# print(data.ca._items)
- compare(data, """
+ exp = """
# Hello
# World
a: 1
b: 2
- """.format(comment='#'))
+ """
+ compare(data, exp.format(comment='#'))
def test_before_top_seq_rt(self):
data = load("""
@@ -282,28 +299,31 @@ class TestCommentsManipulation:
""")
data.yaml_set_start_comment('Hello\nWorld\n')
print(round_trip_dump(data))
- compare(data, """
+ exp = """
# Hello
# World
- a
- b
- """)
+ """
+ compare(data, exp)
def test_before_top_seq_rt_replace(self):
- data = load("""
+ s = """
# this
# that
- a
- b
- """.format(comment='#'))
+ """
+ data = load(s.format(comment='#'))
data.yaml_set_start_comment('Hello\nWorld\n')
print(round_trip_dump(data))
- compare(data, """
+ exp = """
# Hello
# World
- a
- b
- """.format(comment='#'))
+ """
+ compare(data, exp.format(comment='#'))
def test_before_top_seq_from_scratch(self):
from ruamel.yaml.comments import CommentedSeq
@@ -313,12 +333,13 @@ class TestCommentsManipulation:
data.append('b')
data.yaml_set_start_comment('Hello\nWorld\n')
print(round_trip_dump(data))
- compare(data, """
+ exp = """
# Hello
# World
- a
- b
- """.format(comment='#'))
+ """
+ compare(data, exp.format(comment='#'))
# nested variants
def test_before_nested_map_rt(self):
@@ -329,14 +350,15 @@ class TestCommentsManipulation:
d: 3
""")
data['b'].yaml_set_start_comment('Hello\nWorld\n')
- compare(data, """
+ exp = """
a: 1
b:
# Hello
# World
c: 2
d: 3
- """.format(comment='#'))
+ """
+ compare(data, exp.format(comment='#'))
def test_before_nested_map_rt_indent(self):
data = load("""
@@ -346,14 +368,15 @@ class TestCommentsManipulation:
d: 3
""")
data['b'].yaml_set_start_comment('Hello\nWorld\n', indent=2)
- compare(data, """
+ exp = """
a: 1
b:
# Hello
# World
c: 2
d: 3
- """.format(comment='#'))
+ """
+ compare(data, exp.format(comment='#'))
print(data['b'].ca)
def test_before_nested_map_from_scratch(self):
@@ -366,14 +389,15 @@ class TestCommentsManipulation:
datab['c'] = 2
datab['d'] = 3
data['b'].yaml_set_start_comment('Hello\nWorld\n')
- compare(data, """
+ exp = """
a: 1
b:
# Hello
# World
c: 2
d: 3
- """.format(comment='#'))
+ """
+ compare(data, exp.format(comment='#'))
def test_before_nested_seq_from_scratch(self):
from ruamel.yaml.comments import CommentedMap, CommentedSeq
@@ -385,14 +409,15 @@ class TestCommentsManipulation:
datab.append('c')
datab.append('d')
data['b'].yaml_set_start_comment('Hello\nWorld\n', indent=2)
- compare(data, """
+ exp = """
a: 1
b:
# Hello
# World
- c
- d
- """.format(comment='#'))
+ """
+ compare(data, exp.format(comment='#'))
def test_before_nested_seq_from_scratch_block_seq_indent(self):
from ruamel.yaml.comments import CommentedMap, CommentedSeq
@@ -404,14 +429,15 @@ class TestCommentsManipulation:
datab.append('c')
datab.append('d')
data['b'].yaml_set_start_comment('Hello\nWorld\n', indent=2)
- compare(data, """
+ exp = """
a: 1
b:
# Hello
# World
- c
- d
- """.format(comment='#'), indent=4, block_seq_indent=2)
+ """
+ compare(data, exp.format(comment='#'), indent=4, block_seq_indent=2)
def test_map_set_comment_before_and_after_non_first_key_00(self):
# http://stackoverflow.com/a/40705671/1307905
@@ -428,7 +454,7 @@ class TestCommentsManipulation:
'test1', 'before test1 (top level)', after='before test2'
)
data['test1']['test2'].yaml_set_start_comment('after test2', indent=4)
- compare(data, """
+ exp = """
xyz:
a: 1 # comment 1
b: 2
@@ -439,7 +465,8 @@ class TestCommentsManipulation:
test2:
# after test2
test3: 3
- """)
+ """
+ compare(data, exp)
def Xtest_map_set_comment_before_and_after_non_first_key_01(self):
data = load("""
@@ -456,7 +483,7 @@ class TestCommentsManipulation:
)
data['test1']['test2'].yaml_set_start_comment('after test2', indent=4)
# EOL is needed here as dedenting gets rid of spaces (as well as does Emacs
- compare_eol(data, """
+ exp = """
xyz:
a: 1 # comment 1
b: 2
@@ -468,7 +495,8 @@ class TestCommentsManipulation:
test2:
# after test2
test3: 3
- """)
+ """
+ compare_eol(data, exp)
# EOL is no longer necessary
# fixed together with issue # 216
@@ -486,7 +514,7 @@ class TestCommentsManipulation:
'test1', 'before test1 (top level)', after='before test2\n\n'
)
data['test1']['test2'].yaml_set_start_comment('after test2', indent=4)
- compare(data, """
+ exp = """
xyz:
a: 1 # comment 1
b: 2
@@ -498,7 +526,8 @@ class TestCommentsManipulation:
test2:
# after test2
test3: 3
- """)
+ """
+ compare(data, exp)
def Xtest_map_set_comment_before_and_after_non_first_key_02(self):
data = load("""
@@ -515,7 +544,7 @@ class TestCommentsManipulation:
)
data['test1']['test2'].yaml_set_start_comment('after test2', indent=4)
# EOL is needed here as dedenting gets rid of spaces (as well as does Emacs
- compare_eol(data, """
+ exp = """
xyz:
a: 1 # comment 1
b: 2
@@ -529,7 +558,8 @@ class TestCommentsManipulation:
test2:
# after test2
test3: 3
- """)
+ """
+ compare_eol(data, exp)
def test_map_set_comment_before_and_after_non_first_key_02(self):
data = load("""
@@ -545,7 +575,7 @@ class TestCommentsManipulation:
'test1', 'xyz\n\nbefore test1 (top level)', after='\nbefore test2', after_indent=4
)
data['test1']['test2'].yaml_set_start_comment('after test2', indent=4)
- compare(data, """
+ exp = """
xyz:
a: 1 # comment 1
b: 2
@@ -559,4 +589,5 @@ class TestCommentsManipulation:
test2:
# after test2
test3: 3
- """)
+ """
+ compare(data, exp)
diff --git a/_test/test_comments.py b/_test/test_comments.py
index a5e4ee0..31ab2a6 100644
--- a/_test/test_comments.py
+++ b/_test/test_comments.py
@@ -55,11 +55,12 @@ class TestComments:
""")
def test_dropped(self):
- round_trip("""
+ s = """\
# comment
scalar
...
- """, 'scalar\n...\n')
+ """
+ round_trip(s, 'scalar\n...\n')
def test_main_mapping_begin_end(self):
round_trip("""
@@ -133,7 +134,7 @@ class TestComments:
""")
def test_09(self): # 2.9 from the examples in the spec
- round_trip("""
+ s = """\
hr: # 1998 hr ranking
- Mark McGwire
- Sammy Sosa
@@ -141,7 +142,8 @@ class TestComments:
# 1998 rbi ranking
- Sammy Sosa
- Ken Griffey
- """, indent=4, block_seq_indent=2)
+ """
+ round_trip(s, indent=4, block_seq_indent=2)
def test_09a(self):
round_trip("""
@@ -784,11 +786,12 @@ class TestEmptyValueBeforeComments:
""")
def test_issue_25_03(self):
- round_trip("""\
+ s = """\
a: # comment 1
# comment 2
- b: 2 # comment 3
- """, indent=4, block_seq_indent=2)
+ """
+ round_trip(s, indent=4, block_seq_indent=2)
def test_issue_25_04(self):
round_trip("""\
diff --git a/_test/test_datetime.py b/_test/test_datetime.py
index 8540863..5874c0d 100644
--- a/_test/test_datetime.py
+++ b/_test/test_datetime.py
@@ -27,47 +27,57 @@ from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NO
class TestDateTime:
def test_date_only(self):
- round_trip("""
+ inp = """
- 2011-10-02
- """, """
+ """
+ exp = """
- 2011-10-02
- """)
+ """
+ round_trip(inp, exp)
def test_zero_fraction(self):
- round_trip("""
+ inp = """
- 2011-10-02 16:45:00.0
- """, """
+ """
+ exp = """
- 2011-10-02 16:45:00
- """)
+ """
+ round_trip(inp, exp)
def test_long_fraction(self):
- round_trip("""
+ inp = """
- 2011-10-02 16:45:00.1234 # expand with zeros
- 2011-10-02 16:45:00.123456
- 2011-10-02 16:45:00.12345612 # round to microseconds
- 2011-10-02 16:45:00.1234565 # round up
- 2011-10-02 16:45:00.12345678 # round up
- """, """
+ """
+ exp = """
- 2011-10-02 16:45:00.123400 # expand with zeros
- 2011-10-02 16:45:00.123456
- 2011-10-02 16:45:00.123456 # round to microseconds
- 2011-10-02 16:45:00.123457 # round up
- 2011-10-02 16:45:00.123457 # round up
- """)
+ """
+ round_trip(inp, exp)
def test_canonical(self):
- round_trip("""
+ inp = """
- 2011-10-02T16:45:00.1Z
- """, """
+ """
+ exp = """
- 2011-10-02T16:45:00.100000Z
- """)
+ """
+ round_trip(inp, exp)
def test_spaced_timezone(self):
- round_trip("""
+ inp = """
- 2011-10-02T11:45:00 -5
- """, """
+ """
+ exp = """
- 2011-10-02T11:45:00-5
- """)
+ """
+ round_trip(inp, exp)
def test_normal_timezone(self):
round_trip("""
@@ -78,32 +88,40 @@ class TestDateTime:
""")
def test_no_timezone(self):
- round_trip("""
+ inp = """
- 2011-10-02 6:45:00
- """, """
+ """
+ exp = """
- 2011-10-02 06:45:00
- """)
+ """
+ round_trip(inp, exp)
def test_explicit_T(self):
- round_trip("""
+ inp = """
- 2011-10-02T16:45:00
- """, """
+ """
+ exp = """
- 2011-10-02T16:45:00
- """)
+ """
+ round_trip(inp, exp)
def test_explicit_t(self): # to upper
- round_trip("""
+ inp = """
- 2011-10-02t16:45:00
- """, """
+ """
+ exp = """
- 2011-10-02T16:45:00
- """)
+ """
+ round_trip(inp, exp)
def test_no_T_multi_space(self):
- round_trip("""
+ inp = """
- 2011-10-02 16:45:00
- """, """
+ """
+ exp = """
- 2011-10-02 16:45:00
- """)
+ """
+ round_trip(inp, exp)
def test_iso(self):
round_trip("""
diff --git a/_test/test_documents.py b/_test/test_documents.py
index 6f714e9..05ba7dd 100644
--- a/_test/test_documents.py
+++ b/_test/test_documents.py
@@ -7,23 +7,26 @@ from roundtrip import round_trip, round_trip_load_all
class TestDocument:
def test_single_doc_begin_end(self):
- round_trip("""\
+ inp = """\
---
- a
- b
...
- """, explicit_start=True, explicit_end=True)
+ """
+ round_trip(inp, explicit_start=True, explicit_end=True)
def test_multi_doc_begin_end(self):
from ruamel import yaml
- docs = list(round_trip_load_all("""\
+
+ inp = """\
---
- a
...
---
- b
...
- """))
+ """
+ docs = list(round_trip_load_all(inp))
assert docs == [['a'], ['b']]
out = yaml.dump_all(
docs, Dumper=yaml.RoundTripDumper, explicit_start=True, explicit_end=True
@@ -31,31 +34,34 @@ class TestDocument:
assert out == '---\n- a\n...\n---\n- b\n...\n'
def test_multi_doc_no_start(self):
- docs = list(round_trip_load_all("""\
+ inp = """\
- a
...
---
- b
...
- """))
+ """
+ docs = list(round_trip_load_all(inp))
assert docs == [['a'], ['b']]
def test_multi_doc_no_end(self):
- docs = list(round_trip_load_all("""\
+ 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
- docs = list(round_trip_load_all("""\
+ inp = """\
- a
...
- b
...
- """, version=(1, 2)))
+ """
+ docs = list(round_trip_load_all(inp, version=(1, 2)))
assert docs == [['a'], ['b']]
def test_multi_doc_ends_only_1_1(self):
@@ -63,10 +69,11 @@ class TestDocument:
# this is not ok in 1.1
with pytest.raises(yaml.parser.ParserError):
- docs = list(round_trip_load_all("""\
+ inp = """\
- a
...
- b
...
- """, version=(1, 1)))
+ """
+ docs = list(round_trip_load_all(inp, version=(1, 1)))
assert docs == [['a'], ['b']] # not True, but not reached
diff --git a/_test/test_fail.py b/_test/test_fail.py
index 2f0b37a..2bb4230 100644
--- a/_test/test_fail.py
+++ b/_test/test_fail.py
@@ -28,7 +28,7 @@ class TestCommentFailures:
def test_set_comment_before_tag_no_fail(self):
# no comments before tags
- assert round_trip_dump(round_trip_load("""
+ inp = """
# the beginning
!!set
# or this one?
@@ -37,7 +37,8 @@ class TestCommentFailures:
? b # You see? Promised you.
? c
# this is the end
- """)) == dedent("""
+ """
+ assert round_trip_dump(round_trip_load(inp)) == dedent("""
!!set
# or this one?
? a
@@ -97,7 +98,7 @@ class TestIndentFailures:
""")
def test_indent_not_retained_no_fail(self):
- assert round_trip_dump(round_trip_load("""
+ inp = """
verbosity: 1 # 0 is minimal output, -1 none
base_url: http://gopher.net
special_indices: [1, 5, 8]
@@ -118,7 +119,8 @@ class TestIndentFailures:
Italy: Rome
Antarctica:
- too cold
- """), indent=4) == dedent("""
+ """
+ assert round_trip_dump(round_trip_load(inp), indent=4) == dedent("""
verbosity: 1 # 0 is minimal output, -1 none
base_url: http://gopher.net
special_indices: [1, 5, 8]
@@ -142,10 +144,11 @@ class TestIndentFailures:
""")
def Xtest_indent_top_level_no_fail(self):
- round_trip("""
+ inp = """
- a:
- b
- """, indent=4)
+ """
+ round_trip(inp, indent=4)
class TestTagFailures:
@@ -159,26 +162,30 @@ class TestTagFailures:
""")
def test_standard_short_tag_no_fail(self):
- assert round_trip_dump(round_trip_load("""
+ inp = """
!!map
name: Anthon
location: Germany
language: python
- """)) == dedent("""
+ """
+ exp = """
name: Anthon
location: Germany
language: python
- """)
+ """
+ assert round_trip_dump(round_trip_load(inp)) == dedent(exp)
class TestFlowValues:
def test_flow_value_with_colon(self):
- round_trip("""\
+ inp = """\
{a: bcd:efg}
- """)
+ """
+ round_trip(inp)
# @pytest.mark.xfail(strict=True)
def test_flow_value_with_colon_quoted(self):
- round_trip("""\
+ inp = """\
{a: 'bcd:efg'}
- """, preserve_quotes=True)
+ """
+ round_trip(inp, preserve_quotes=True)
diff --git a/_test/test_flowsequencekey.py b/_test/test_flowsequencekey.py
index 8490430..96bee67 100644
--- a/_test/test_flowsequencekey.py
+++ b/_test/test_flowsequencekey.py
@@ -12,7 +12,7 @@ from roundtrip import round_trip # , dedent, round_trip_load, round_trip_dump
class TestFlowStyleSequenceKey:
def test_so_39595807(self):
- round_trip("""
+ inp = """\
%YAML 1.2
---
[2, 3, 4]:
@@ -21,4 +21,5 @@ class TestFlowStyleSequenceKey:
- 2
b: Hello World!
c: 'VoilĂ !'
- """, preserve_quotes=True, explicit_start=True, version=(1, 2))
+ """
+ round_trip(inp, preserve_quotes=True, explicit_start=True, version=(1, 2))
diff --git a/_test/test_indentation.py b/_test/test_indentation.py
index a6be430..6321409 100644
--- a/_test/test_indentation.py
+++ b/_test/test_indentation.py
@@ -12,10 +12,12 @@ from roundtrip import round_trip, round_trip_load, round_trip_dump, dedent, YAML
def rt(s):
import ruamel.yaml
- return ruamel.yaml.dump(
+
+ res = ruamel.yaml.dump(
ruamel.yaml.load(s, Loader=ruamel.yaml.RoundTripLoader),
Dumper=ruamel.yaml.RoundTripDumper,
- ).strip() + '\n'
+ )
+ return res.strip() + '\n'
class TestIndent:
@@ -92,40 +94,44 @@ class TestIndent:
assert s == output
def test_indent_top_level(self):
- round_trip("""
+ inp = """
- a:
- b
- """, indent=4)
+ """
+ round_trip(inp, indent=4)
def test_set_indent_5_block_list_indent_1(self):
- round_trip("""
+ inp = """
a:
- b: c
- 1
- d:
- 2
- """, indent=5, block_seq_indent=1)
+ """
+ round_trip(inp, indent=5, block_seq_indent=1)
def test_set_indent_4_block_list_indent_2(self):
- round_trip("""
+ inp = """
a:
- b: c
- 1
- d:
- 2
- """, indent=4, block_seq_indent=2)
+ """
+ round_trip(inp, indent=4, block_seq_indent=2)
def test_set_indent_3_block_list_indent_0(self):
- round_trip("""
+ inp = """
a:
- b: c
- 1
- d:
- 2
- """, indent=3, block_seq_indent=0)
+ """
+ round_trip(inp, indent=3, block_seq_indent=0)
def Xtest_set_indent_3_block_list_indent_2(self):
- round_trip("""
+ inp = """
a:
-
b: c
@@ -135,19 +141,21 @@ class TestIndent:
d:
-
2
- """, indent=3, block_seq_indent=2)
+ """
+ round_trip(inp, indent=3, block_seq_indent=2)
def test_set_indent_3_block_list_indent_2(self):
- round_trip("""
+ inp = """
a:
- b: c
- 1
- d:
- 2
- """, indent=3, block_seq_indent=2)
+ """
+ round_trip(inp, indent=3, block_seq_indent=2)
def Xtest_set_indent_2_block_list_indent_2(self):
- round_trip("""
+ inp = """
a:
-
b: c
@@ -157,42 +165,48 @@ class TestIndent:
d:
-
2
- """, indent=2, block_seq_indent=2)
+ """
+ round_trip(inp, indent=2, block_seq_indent=2)
# this is how it should be: block_seq_indent stretches the indent
def test_set_indent_2_block_list_indent_2(self):
- round_trip("""
+ inp = """
a:
- b: c
- 1
- d:
- 2
- """, indent=2, block_seq_indent=2)
+ """
+ round_trip(inp, indent=2, block_seq_indent=2)
# have to set indent!
def test_roundtrip_four_space_indents(self):
+ # fmt: off
s = (
'a:\n'
'- foo\n'
'- bar\n'
)
+ # fmt: on
round_trip(s, indent=4)
def test_roundtrip_four_space_indents_no_fail(self):
- assert round_trip_dump(round_trip_load("""
+ inp = """
a:
- foo
- bar
- """)) == dedent("""
+ """
+ exp = """
a:
- foo
- bar
- """)
+ """
+ assert round_trip_dump(round_trip_load(inp)) == dedent(exp)
class TestYpkgIndent:
def test_00(self):
- round_trip("""
+ inp = """
name : nano
version : 2.3.2
release : 1
@@ -207,7 +221,10 @@ class TestYpkgIndent:
GNU nano is an easy-to-use text editor originally designed
as a replacement for Pico, the ncurses-based editor from the non-free mailer
package Pine (itself now available under the Apache License as Alpine).
- """, indent=4, block_seq_indent=2, top_level_colon_align=True, prefix_colon=' ')
+ """
+ round_trip(
+ inp, indent=4, block_seq_indent=2, top_level_colon_align=True, prefix_colon=' '
+ )
def guess(s):
@@ -219,30 +236,34 @@ def guess(s):
class TestGuessIndent:
def test_guess_20(self):
- assert guess("""\
+ inp = """\
a:
- 1
- """) == (2, 0)
+ """
+ assert guess(inp) == (2, 0)
def test_guess_42(self):
- assert guess("""\
+ inp = """\
a:
- 1
- """) == (4, 2)
+ """
+ assert guess(inp) == (4, 2)
def test_guess_42a(self):
# block seq indent prevails over nested key indent level
- assert guess("""\
+ inp = """\
b:
a:
- 1
- """) == (4, 2)
+ """
+ assert guess(inp) == (4, 2)
def test_guess_3None(self):
- assert guess("""\
+ inp = """\
b:
a: 1
- """) == (3, None)
+ """
+ assert guess(inp) == (3, None)
class TestSeparateMapSeqIndents:
@@ -253,51 +274,56 @@ class TestSeparateMapSeqIndents:
yaml = YAML()
yaml.indent = 6
yaml.block_seq_indent = 3
- yaml.round_trip("""
+ inp = """
a:
- 1
- [1, 2]
- """)
+ """
+ yaml.round_trip(inp)
def test_01(self):
yaml = YAML()
yaml.indent(sequence=6)
yaml.indent(offset=3)
- yaml.round_trip("""
+ inp = """
a:
- 1
- {b: 3}
- """)
+ """
+ yaml.round_trip(inp)
def test_02(self):
yaml = YAML()
yaml.indent(mapping=5, sequence=6, offset=3)
- yaml.round_trip("""
+ inp = """
a:
b:
- 1
- [1, 2]
- """)
+ """
+ yaml.round_trip(inp)
def test_03(self):
- round_trip("""
+ inp = """
a:
b:
c:
- 1
- [1, 2]
- """, indent=4)
+ """
+ round_trip(inp, indent=4)
def test_04(self):
yaml = YAML()
yaml.indent(mapping=5, sequence=6)
- yaml.round_trip("""
+ inp = """
a:
b:
- 1
- [1, 2]
- {d: 3.14}
- """)
+ """
+ yaml.round_trip(inp)
def test_issue_51(self):
yaml = YAML()
diff --git a/_test/test_literal.py b/_test/test_literal.py
index 86ae5f6..edb86ce 100644
--- a/_test/test_literal.py
+++ b/_test/test_literal.py
@@ -3,7 +3,7 @@ from __future__ import print_function
import pytest # NOQA
-from roundtrip import YAML
+from roundtrip import YAML # does an automatic dedent on load
"""
@@ -31,31 +31,34 @@ class TestNoIndent:
def test_top_literal_scalar_indent_example_9_5(self):
yaml = YAML()
s = '%!PS-Adobe-2.0'
- d = yaml.load("""
+ inp = """
--- |
{}
- """.format(s))
+ """
+ d = yaml.load(inp.format(s))
print(d)
assert d == s + '\n'
def test_top_literal_scalar_no_indent(self):
yaml = YAML()
s = 'testing123'
- d = yaml.load("""
+ inp = """
--- |
{}
- """.format(s))
+ """
+ d = yaml.load(inp.format(s))
print(d)
assert d == s + '\n'
def test_top_literal_scalar_no_indent_1_1(self):
yaml = YAML()
s = 'testing123'
- d = yaml.load("""
+ inp = """
%YAML 1.1
--- |
{}
- """.format(s))
+ """
+ d = yaml.load(inp.format(s))
print(d)
assert d == s + '\n'
@@ -64,11 +67,12 @@ class TestNoIndent:
from ruamel.yaml import safe_load
s = 'testing123'
- d = safe_load(dedent("""
+ inp = """
%YAML 1.1
--- |
{}
- """.format(s)))
+ """
+ d = safe_load(dedent(inp.format(s)))
print(d)
assert d == s + '\n'
@@ -79,80 +83,88 @@ class TestNoIndent:
yaml.top_level_block_style_scalar_no_indent_error_1_1 = True
s = 'testing123'
with pytest.raises(ParserError):
- yaml.load("""
+ inp = """
%YAML 1.1
--- |
{}
- """.format(s))
+ """
+ yaml.load(inp.format(s))
def test_top_literal_scalar_indent_offset_one(self):
yaml = YAML()
s = 'testing123'
- d = yaml.load("""
+ inp = """
--- |1
{}
- """.format(s))
+ """
+ d = yaml.load(inp.format(s))
print(d)
assert d == s + '\n'
def test_top_literal_scalar_indent_offset_four(self):
yaml = YAML()
s = 'testing123'
- d = yaml.load("""
+ inp = """
--- |4
{}
- """.format(s))
+ """
+ d = yaml.load(inp.format(s))
print(d)
assert d == s + '\n'
def test_top_literal_scalar_indent_offset_two_leading_space(self):
yaml = YAML()
s = ' testing123'
- d = yaml.load("""
+ inp = """
--- |4
{s}
{s}
- """.format(s=s))
+ """
+ d = yaml.load(inp.format(s=s))
print(d)
assert d == (s + '\n') * 2
def test_top_literal_scalar_no_indent_special(self):
yaml = YAML()
s = '%!PS-Adobe-2.0'
- d = yaml.load("""
+ inp = """
--- |
{}
- """.format(s))
+ """
+ d = yaml.load(inp.format(s))
print(d)
assert d == s + '\n'
def test_top_folding_scalar_indent(self):
yaml = YAML()
s = '%!PS-Adobe-2.0'
- d = yaml.load("""
+ inp = """
--- >
{}
- """.format(s))
+ """
+ d = yaml.load(inp.format(s))
print(d)
assert d == s + '\n'
def test_top_folding_scalar_no_indent(self):
yaml = YAML()
s = 'testing123'
- d = yaml.load("""
+ inp = """
--- >
{}
- """.format(s))
+ """
+ d = yaml.load(inp.format(s))
print(d)
assert d == s + '\n'
def test_top_folding_scalar_no_indent_special(self):
yaml = YAML()
s = '%!PS-Adobe-2.0'
- d = yaml.load("""
+ inp = """
--- >
{}
- """.format(s))
+ """
+ d = yaml.load(inp.format(s))
print(d)
assert d == s + '\n'
@@ -160,12 +172,13 @@ class TestNoIndent:
yaml = YAML(typ='safe', pure=True)
s1 = 'abc'
s2 = 'klm'
- for idx, d1 in enumerate(yaml.load_all("""
+ inp = """
--- |-
{}
--- |
{}
- """.format(s1, s2))):
+ """
+ for idx, d1 in enumerate(yaml.load_all(inp.format(s1, s2))):
print('d1:', d1)
assert ['abc', 'klm\n'][idx] == d1
@@ -178,7 +191,8 @@ class Test_RoundTripLiteral:
ys = """
--- |
{}
- """.format(s)
+ """
+ ys = ys.format(s)
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -190,7 +204,8 @@ class Test_RoundTripLiteral:
ys = """
--- |
{}
- """.format(s)
+ """
+ ys = ys.format(s)
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -202,7 +217,8 @@ class Test_RoundTripLiteral:
ys = """
---
{}
- """.format(s)
+ """
+ ys = ys.format(s)
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -214,7 +230,8 @@ class Test_RoundTripLiteral:
ys = """
---
{}
- """.format(s)
+ """
+ ys = ys.format(s)
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -226,7 +243,8 @@ class Test_RoundTripLiteral:
ys = """
---
{}
- """.format(s)
+ """
+ ys = ys.format(s)
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -240,7 +258,8 @@ class Test_RoundTripLiteral:
ys = """
---
{}
- """.format(s)
+ """
+ ys = ys.format(s)
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -251,7 +270,8 @@ class Test_RoundTripLiteral:
ys = """
--- |-
{}
- """.format(s)
+ """
+ ys = ys.format(s)
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -261,6 +281,7 @@ class Test_RoundTripLiteral:
ys = """
- |
{}
- """.format(s)
+ """
+ ys = ys.format(s)
d = yaml.load(ys)
yaml.dump(d, compare=ys)
diff --git a/_test/test_string.py b/_test/test_string.py
index 5a466db..e6449ac 100644
--- a/_test/test_string.py
+++ b/_test/test_string.py
@@ -26,7 +26,7 @@ class TestPreservedScalarString:
def test_basic_string(self):
round_trip("""
a: abcdefg
- """, )
+ """)
def test_quoted_integer_string(self):
round_trip("""
@@ -37,37 +37,39 @@ class TestPreservedScalarString:
platform.python_implementation() == 'Jython', reason='Jython throws RepresenterError'
)
def test_preserve_string(self):
- round_trip("""
- a: |
- abc
- def
- """, intermediate=dict(a='abc\ndef\n'))
+ inp = """
+ a: |
+ abc
+ def
+ """
+ round_trip(inp, intermediate=dict(a='abc\ndef\n'))
@pytest.mark.skipif(
platform.python_implementation() == 'Jython', reason='Jython throws RepresenterError'
)
def test_preserve_string_strip(self):
s = """
- a: |-
- abc
- def
+ a: |-
+ abc
+ def
- """
+ """
round_trip(s, intermediate=dict(a='abc\ndef'))
@pytest.mark.skipif(
platform.python_implementation() == 'Jython', reason='Jython throws RepresenterError'
)
def test_preserve_string_keep(self):
- # with pytest.raises(AssertionError) as excinfo:
- round_trip("""
+ # with pytest.raises(AssertionError) as excinfo:
+ inp = """
a: |+
ghi
jkl
b: x
- """, intermediate=dict(a='ghi\njkl\n\n\n', b='x'))
+ """
+ round_trip(inp, intermediate=dict(a='ghi\njkl\n\n\n', b='x'))
@pytest.mark.skipif(
platform.python_implementation() == 'Jython', reason='Jython throws RepresenterError'
@@ -75,59 +77,67 @@ class TestPreservedScalarString:
def test_preserve_string_keep_at_end(self):
# at EOF you have to specify the ... to get proper "closure"
# of the multiline scalar
- round_trip("""
+ inp = """
a: |+
ghi
jkl
...
- """, intermediate=dict(a='ghi\njkl\n\n'))
+ """
+ round_trip(inp, intermediate=dict(a='ghi\njkl\n\n'))
def test_fold_string(self):
with pytest.raises(AssertionError) as excinfo: # NOQA
- round_trip("""
+ inp = """
a: >
abc
def
- """, intermediate=dict(a='abc def\n'))
+ """
+ round_trip(inp, intermediate=dict(a='abc def\n'))
def test_fold_string_strip(self):
with pytest.raises(AssertionError) as excinfo: # NOQA
- round_trip("""
+ inp = """
a: >-
abc
def
- """, intermediate=dict(a='abc def'))
+ """
+ round_trip(inp, intermediate=dict(a='abc def'))
def test_fold_string_keep(self):
with pytest.raises(AssertionError) as excinfo: # NOQA
- round_trip("""
+ inp = """
a: >+
abc
def
- """, intermediate=dict(a='abc def\n\n'))
+ """
+ round_trip(inp, intermediate=dict(a='abc def\n\n'))
class TestQuotedScalarString:
def test_single_quoted_string(self):
- round_trip("""
+ inp = """
a: 'abc'
- """, preserve_quotes=True)
+ """
+ round_trip(inp, preserve_quotes=True)
def test_double_quoted_string(self):
- round_trip("""
+ inp = """
a: "abc"
- """, preserve_quotes=True)
+ """
+ round_trip(inp, preserve_quotes=True)
def test_non_preserved_double_quoted_string(self):
- round_trip("""
+ inp = """
a: "abc"
- """, outp="""
+ """
+ exp = """
a: abc
- """)
+ """
+ round_trip(inp, outp=exp)
class TestReplace:
diff --git a/_test/test_version.py b/_test/test_version.py
index 61e3bca..742ec36 100644
--- a/_test/test_version.py
+++ b/_test/test_version.py
@@ -85,7 +85,7 @@ class TestVersions:
assert r[9] is True
def test_load_version_1_1(self):
- r = load("""\
+ inp = """\
- 12:34:56
- 12:34:56.78
- 012
@@ -96,7 +96,8 @@ class TestVersions:
- yes
- no
- true
- """, version="1.1")
+ """
+ r = load(inp, version='1.1')
assert r[0] == 45296
assert r[1] == 45296.78
assert r[2] == 10