diff options
author | Anthon van der Neut <anthon@mnt.org> | 2018-08-05 17:05:06 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2018-08-05 17:05:06 +0200 |
commit | e58ed78b291889578477741fb5ad5f05bf914d6b (patch) | |
tree | 73fa7be33210f4e9ee033f662486643e041dfdd0 | |
parent | 992aecee297f7fe781eddc715fff6d7f5bbed875 (diff) | |
download | ruamel.yaml-e58ed78b291889578477741fb5ad5f05bf914d6b.tar.gz |
undid miswrapping of tests
-rw-r--r-- | _test/test_a_dedent.py | 43 | ||||
-rw-r--r-- | _test/test_add_xxx.py | 6 | ||||
-rw-r--r-- | _test/test_anchor.py | 66 | ||||
-rw-r--r-- | _test/test_api_change.py | 32 | ||||
-rw-r--r-- | _test/test_comment_manipulation.py | 339 | ||||
-rw-r--r-- | _test/test_comments.py | 365 | ||||
-rw-r--r-- | _test/test_copy.py | 54 | ||||
-rw-r--r-- | _test/test_datetime.py | 111 | ||||
-rw-r--r-- | _test/test_documents.py | 51 | ||||
-rw-r--r-- | _test/test_fail.py | 96 | ||||
-rw-r--r-- | _test/test_float.py | 78 | ||||
-rw-r--r-- | _test/test_flowsequencekey.py | 9 | ||||
-rw-r--r-- | _test/test_indentation.py | 215 | ||||
-rw-r--r-- | _test/test_int.py | 48 | ||||
-rw-r--r-- | _test/test_issues.py | 6 | ||||
-rw-r--r-- | _test/test_line_col.py | 42 | ||||
-rw-r--r-- | _test/test_literal.py | 167 | ||||
-rw-r--r-- | _test/test_program_config.py | 18 | ||||
-rw-r--r-- | _test/test_string.py | 97 | ||||
-rw-r--r-- | _test/test_tag.py | 60 | ||||
-rw-r--r-- | _test/test_version.py | 43 | ||||
-rw-r--r-- | _test/test_yamlfile.py | 60 | ||||
-rw-r--r-- | _test/test_z_check_debug_leftovers.py | 12 |
23 files changed, 613 insertions, 1405 deletions
diff --git a/_test/test_a_dedent.py b/_test/test_a_dedent.py index 984e1a2..fc6157a 100644 --- a/_test/test_a_dedent.py +++ b/_test/test_a_dedent.py @@ -4,54 +4,45 @@ from roundtrip import dedent class TestDedent: def test_start_newline(self): - x = dedent( - """ + # fmt: off + x = dedent(""" 123 456 - """ - ) + """) + # fmt: on assert x == '123\n 456\n' def test_start_space_newline(self): - # special construct to prevent stripping of following whitespac - x = dedent( - ' ' - """ + # special construct to prevent stripping of following whitespace + # fmt: off + x = dedent(" " """ 123 - """ - ) + """) + # fmt: on assert x == '123\n' def test_start_no_newline(self): # special construct to prevent stripping of following whitespac - x = dedent( - """\ + x = dedent("""\ 123 456 - """ - ) + """) assert x == '123\n 456\n' def test_preserve_no_newline_at_end(self): - x = dedent( - """ - 123""" - ) + x = dedent(""" + 123""") assert x == '123' def test_preserve_no_newline_at_all(self): - x = dedent( - """\ - 123""" - ) + x = dedent("""\ + 123""") assert x == '123' def test_multiple_dedent(self): x = dedent( - dedent( - """ + dedent(""" 123 - """ - ) + """) ) assert x == '123\n' diff --git a/_test/test_add_xxx.py b/_test/test_add_xxx.py index 031b89f..085e352 100644 --- a/_test/test_add_xxx.py +++ b/_test/test_add_xxx.py @@ -152,8 +152,7 @@ def test_issue_127(): style = None return dumper.represent_scalar(cls.yaml_tag, data.logical_id, style=style) - document = dedent( - """\ + document = dedent("""\ AList: - !Ref One - !Ref 'Two' @@ -163,8 +162,7 @@ def test_issue_127(): CList: - Five Six - 'Seven Eight' - """ - ) + """) data = ruamel.yaml.round_trip_load(document, preserve_quotes=True) assert ruamel.yaml.round_trip_dump(data, indent=4, block_seq_indent=2) == document.replace( '\n Two and', ' Two and' diff --git a/_test/test_anchor.py b/_test/test_anchor.py index cb632d8..3838833 100644 --- a/_test/test_anchor.py +++ b/_test/test_anchor.py @@ -24,14 +24,12 @@ class TestAnchorsAliases: from ruamel.yaml.serializer import Serializer assert Serializer.ANCHOR_TEMPLATE == 'id%03d' - data = load( - """ + data = load(""" a: &id002 b: 1 c: 2 d: *id002 - """ - ) + """) compare( data, """ @@ -64,8 +62,7 @@ class TestAnchorsAliases: def test_anchor_assigned(self): from ruamel.yaml.comments import CommentedMap - data = load( - """ + data = load(""" a: &id002 b: 1 c: 2 @@ -74,8 +71,7 @@ class TestAnchorsAliases: b: 1 c: 2 f: *etemplate - """ - ) + """) d = data['d'] assert isinstance(d, CommentedMap) assert d.yaml_anchor() is None # got dropped as it matches pattern @@ -85,8 +81,7 @@ class TestAnchorsAliases: assert e.yaml_anchor().always_dump is False def test_anchor_id_retained(self): - data = load( - """ + data = load(""" a: &id002 b: 1 c: 2 @@ -95,8 +90,7 @@ class TestAnchorsAliases: b: 1 c: 2 f: *etemplate - """ - ) + """) compare( data, """ @@ -118,14 +112,12 @@ class TestAnchorsAliases: from ruamel.yaml.composer import ComposerError with pytest.raises(ComposerError): - data = load( - """ + data = load(""" d: *id002 a: &id002 b: 1 c: 2 - """ - ) + """) data = data def test_anchor_on_sequence(self): @@ -133,8 +125,7 @@ class TestAnchorsAliases: # https://bitbucket.org/ruamel/yaml/issue/7/anchor-names-not-preserved from ruamel.yaml.comments import CommentedSeq - data = load( - """ + data = load(""" nut1: &alice - 1 - 2 @@ -144,15 +135,13 @@ class TestAnchorsAliases: nut3: - *blake - *alice - """ - ) + """) r = data['nut1'] assert isinstance(r, CommentedSeq) assert r.yaml_anchor() is not None assert r.yaml_anchor().value == 'alice' - merge_yaml = dedent( - """ + merge_yaml = dedent(""" - &CENTER {x: 1, y: 2} - &LEFT {x: 0, y: 2} - &BIG {r: 10} @@ -174,8 +163,7 @@ class TestAnchorsAliases: - <<: [*BIG, *LEFT, *SMALL] x: 1 label: center/huge - """ - ) + """) def test_merge_00(self): data = load(self.merge_yaml) @@ -196,16 +184,14 @@ class TestAnchorsAliases: def test_merge_accessible(self): from ruamel.yaml.comments import CommentedMap, merge_attrib - data = load( - """ + data = load(""" k: &level_2 { a: 1, b2 } l: &level_1 { a: 10, c: 3 } m: <<: *level_1 c: 30 d: 40 - """ - ) + """) d = data['m'] assert isinstance(d, CommentedMap) assert hasattr(d, merge_attrib) @@ -278,8 +264,7 @@ class TestAnchorsAliases: # issue 130 reported by Devid Fee import ruamel.yaml - ys = dedent( - """\ + ys = dedent("""\ components: server: &server_component type: spark.server:ServerComponent @@ -295,8 +280,7 @@ class TestAnchorsAliases: <<: *shell_component components: server: {<<: *server_service} - """ - ) + """) data = ruamel.yaml.safe_load(ys) assert data['services']['shell']['components']['server']['port'] == 8000 @@ -304,8 +288,7 @@ class TestAnchorsAliases: # issue 130 reported by Devid Fee import ruamel.yaml - ys = dedent( - """\ + ys = dedent("""\ components: server: &server_component type: spark.server:ServerComponent @@ -322,16 +305,14 @@ class TestAnchorsAliases: <<: *shell_component components: server: {<<: *server_service} - """ - ) + """) data = ruamel.yaml.safe_load(ys) assert data['services']['shell']['components']['server']['port'] == 4000 class TestMergeKeysValues: - yaml_str = dedent( - """\ + yaml_str = dedent("""\ - &mx a: x1 b: x2 @@ -345,8 +326,7 @@ class TestMergeKeysValues: <<: *mx m: 6 <<: *my - """ - ) + """) # in the following d always has "expanded" the merges @@ -423,15 +403,13 @@ class TestDuplicateKeyThroughAnchor: from ruamel.yaml import safe_load, round_trip_load from ruamel.yaml.constructor import DuplicateKeyFutureWarning, DuplicateKeyError - s = dedent( - """\ + s = dedent("""\ &anchor foo: foo: bar *anchor : duplicate key baz: bat *anchor : duplicate key - """ - ) + """) if version_info < (0, 15, 1): pass elif version_info < (0, 16, 0): diff --git a/_test/test_api_change.py b/_test/test_api_change.py index f191c56..43c8c90 100644 --- a/_test/test_api_change.py +++ b/_test/test_api_change.py @@ -144,15 +144,13 @@ class TestLoadAll: fn = Path(str(tmpdir)) / 'test.yaml' fn.write_text( - textwrap.dedent( - u"""\ - --- - - a - --- - - b - ... - """ - ) + textwrap.dedent(u"""\ + --- + - a + --- + - b + ... + """) ) yaml = YAML() assert list(yaml.load_all(fn)) == [['a'], ['b']] @@ -167,15 +165,13 @@ class TestDuplSet: yaml = YAML() with pytest.raises(DuplicateKeyError): yaml.load( - textwrap.dedent( - """\ - !!set - ? a - ? b - ? c - ? a - """ - ) + textwrap.dedent("""\ + !!set + ? a + ? b + ? c + ? a + """) ) diff --git a/_test/test_comment_manipulation.py b/_test/test_comment_manipulation.py index 92810da..8e89931 100644 --- a/_test/test_comment_manipulation.py +++ b/_test/test_comment_manipulation.py @@ -16,11 +16,8 @@ def compare(data, s, **kw): def compare_eol(data, s): - assert round_trip_dump(data).replace('\n', '|\n') == dedent(s).replace('EOL', "").replace( - '\n', '|\n' - ) - - + assert round_trip_dump(data).replace('\n', '|\n') == \ + dedent(s).replace('EOL', '').replace('\n', '|\n') # @pytest.mark.xfail @@ -28,312 +25,238 @@ class TestCommentsManipulation: # list def test_seq_set_comment_on_existing_explicit_column(self): - data = load( - """ + data = load(""" - a # comment 1 - b - c - """ - ) + """) data.yaml_add_eol_comment('comment 2', key=1, column=6) - compare( - data, - """ + compare(data, """ - a # comment 1 - b # comment 2 - c - """, - ) + """) def test_seq_overwrite_comment_on_existing_explicit_column(self): - data = load( - """ + data = load(""" - a # comment 1 - b - c - """ - ) + """) data.yaml_add_eol_comment('comment 2', key=0, column=6) - compare( - data, - """ + compare(data, """ - a # comment 2 - b - c - """, - ) + """) def test_seq_first_comment_explicit_column(self): - data = load( - """ + data = load(""" - a - b - c - """ - ) + """) data.yaml_add_eol_comment('comment 1', key=1, column=6) - compare( - data, - """ + compare(data, """ - a - b # comment 1 - c - """, - ) + """) def test_seq_set_comment_on_existing_column_prev(self): - data = load( - """ + data = load(""" - a # comment 1 - b - c - d # comment 3 - """ - ) + """) data.yaml_add_eol_comment('comment 2', key=1) - compare( - data, - """ + compare(data, """ - a # comment 1 - b # comment 2 - c - d # comment 3 - """, - ) + """) def test_seq_set_comment_on_existing_column_next(self): - data = load( - """ + data = load(""" - a # comment 1 - b - c - d # comment 3 - """ - ) + """) print(data._yaml_comment) # print(type(data._yaml_comment._items[0][0].start_mark)) # 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, - """ + compare(data, """ - a # comment 1 - b - c # comment 2 - d # comment 3 - """, - ) + """) def test_seq_set_comment_on_existing_column_further_away(self): """ no comment line before or after, take the latest before the new position """ - data = load( - """ + data = load(""" - a # comment 1 - b - c - d - e - f # comment 3 - """ - ) + """) print(data._yaml_comment) # print(type(data._yaml_comment._items[0][0].start_mark)) # 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, - """ + compare(data, """ - a # comment 1 - b - c - d # comment 2 - e - f # comment 3 - """, - ) + """) def test_seq_set_comment_on_existing_explicit_column_with_hash(self): - data = load( - """ + data = load(""" - a # comment 1 - b - c - """ - ) + """) data.yaml_add_eol_comment('# comment 2', key=1, column=6) - compare( - data, - """ + compare(data, """ - a # comment 1 - b # comment 2 - c - """, - ) + """) # dict def test_dict_set_comment_on_existing_explicit_column(self): - data = load( - """ + data = load(""" a: 1 # comment 1 b: 2 c: 3 d: 4 e: 5 - """ - ) + """) data.yaml_add_eol_comment('comment 2', key='c', column=7) - compare( - data, - """ + compare(data, """ a: 1 # comment 1 b: 2 c: 3 # comment 2 d: 4 e: 5 - """, - ) + """) def test_dict_overwrite_comment_on_existing_explicit_column(self): - data = load( - """ + data = load(""" a: 1 # comment 1 b: 2 c: 3 d: 4 e: 5 - """ - ) + """) data.yaml_add_eol_comment('comment 2', key='a', column=7) - compare( - data, - """ + compare(data, """ a: 1 # comment 2 b: 2 c: 3 d: 4 e: 5 - """, - ) + """) def test_map_set_comment_on_existing_column_prev(self): - data = load( - """ + data = load(""" a: 1 # comment 1 b: 2 c: 3 d: 4 e: 5 # comment 3 - """ - ) + """) data.yaml_add_eol_comment('comment 2', key='b') - compare( - data, - """ + compare(data, """ a: 1 # comment 1 b: 2 # comment 2 c: 3 d: 4 e: 5 # comment 3 - """, - ) + """) def test_map_set_comment_on_existing_column_next(self): - data = load( - """ + data = load(""" a: 1 # comment 1 b: 2 c: 3 d: 4 e: 5 # comment 3 - """ - ) + """) data.yaml_add_eol_comment('comment 2', key='d') - compare( - data, - """ + compare(data, """ a: 1 # comment 1 b: 2 c: 3 d: 4 # comment 2 e: 5 # comment 3 - """, - ) + """) def test_map_set_comment_on_existing_column_further_away(self): """ no comment line before or after, take the latest before the new position """ - data = load( - """ + data = load(""" a: 1 # comment 1 b: 2 c: 3 d: 4 e: 5 # comment 3 - """ - ) + """) data.yaml_add_eol_comment('comment 2', key='c') print(round_trip_dump(data)) - compare( - data, - """ + compare(data, """ a: 1 # comment 1 b: 2 c: 3 # comment 2 d: 4 e: 5 # comment 3 - """, - ) + """) # @pytest.mark.xfail def test_before_top_map_rt(self): - data = load( - """ + data = load(""" a: 1 b: 2 - """ - ) + """) data.yaml_set_start_comment('Hello\nWorld\n') - compare( - data, - """ + compare(data, """ # Hello # World a: 1 b: 2 - """.format( - comment='#' - ), - ) + """.format(comment='#')) def test_before_top_map_replace(self): - data = load( - """ + data = load(""" # abc # def a: 1 # 1 b: 2 - """ - ) + """) data.yaml_set_start_comment('Hello\nWorld\n') - compare( - data, - """ + compare(data, """ # Hello # World a: 1 # 1 b: 2 - """.format( - comment='#' - ), - ) + """.format(comment='#')) def test_before_top_map_from_scratch(self): from ruamel.yaml.comments import CommentedMap @@ -344,61 +267,42 @@ class TestCommentsManipulation: data.yaml_set_start_comment('Hello\nWorld\n') # print(data.ca) # print(data.ca._items) - compare( - data, - """ + compare(data, """ # Hello # World a: 1 b: 2 - """.format( - comment='#' - ), - ) + """.format(comment='#')) def test_before_top_seq_rt(self): - data = load( - """ + data = load(""" - a - b - """ - ) + """) data.yaml_set_start_comment('Hello\nWorld\n') print(round_trip_dump(data)) - compare( - data, - """ + compare(data, """ # Hello # World - a - b - """, - ) + """) def test_before_top_seq_rt_replace(self): - data = load( - """ + data = load(""" # this # that - a - b - """.format( - comment='#' - ) - ) + """.format(comment='#')) data.yaml_set_start_comment('Hello\nWorld\n') print(round_trip_dump(data)) - compare( - data, - """ + compare(data, """ # Hello # World - a - b - """.format( - comment='#' - ), - ) + """.format(comment='#')) def test_before_top_seq_from_scratch(self): from ruamel.yaml.comments import CommentedSeq @@ -408,66 +312,47 @@ class TestCommentsManipulation: data.append('b') data.yaml_set_start_comment('Hello\nWorld\n') print(round_trip_dump(data)) - compare( - data, - """ + compare(data, """ # Hello # World - a - b - """.format( - comment='#' - ), - ) + """.format(comment='#')) # nested variants def test_before_nested_map_rt(self): - data = load( - """ + data = load(""" a: 1 b: c: 2 d: 3 - """ - ) + """) data['b'].yaml_set_start_comment('Hello\nWorld\n') - compare( - data, - """ + compare(data, """ a: 1 b: # Hello # World c: 2 d: 3 - """.format( - comment='#' - ), - ) + """.format(comment='#')) def test_before_nested_map_rt_indent(self): - data = load( - """ + data = load(""" a: 1 b: c: 2 d: 3 - """ - ) + """) data['b'].yaml_set_start_comment('Hello\nWorld\n', indent=2) - compare( - data, - """ + compare(data, """ a: 1 b: # Hello # World c: 2 d: 3 - """.format( - comment='#' - ), - ) + """.format(comment='#')) print(data['b'].ca) def test_before_nested_map_from_scratch(self): @@ -480,19 +365,14 @@ class TestCommentsManipulation: datab['c'] = 2 datab['d'] = 3 data['b'].yaml_set_start_comment('Hello\nWorld\n') - compare( - data, - """ + compare(data, """ a: 1 b: # Hello # World c: 2 d: 3 - """.format( - comment='#' - ), - ) + """.format(comment='#')) def test_before_nested_seq_from_scratch(self): from ruamel.yaml.comments import CommentedMap, CommentedSeq @@ -504,19 +384,14 @@ class TestCommentsManipulation: datab.append('c') datab.append('d') data['b'].yaml_set_start_comment('Hello\nWorld\n', indent=2) - compare( - data, - """ + compare(data, """ a: 1 b: # Hello # World - c - d - """.format( - comment='#' - ), - ) + """.format(comment='#')) def test_before_nested_seq_from_scratch_block_seq_indent(self): from ruamel.yaml.comments import CommentedMap, CommentedSeq @@ -528,26 +403,18 @@ class TestCommentsManipulation: datab.append('c') datab.append('d') data['b'].yaml_set_start_comment('Hello\nWorld\n', indent=2) - compare( - data, - """ + compare(data, """ a: 1 b: # Hello # World - c - d - """.format( - comment='#' - ), - indent=4, - block_seq_indent=2, - ) + """.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 - data = load( - """ + data = load(""" xyz: a: 1 # comment 1 b: 2 @@ -555,15 +422,12 @@ class TestCommentsManipulation: test1: test2: test3: 3 - """ - ) + """) data.yaml_set_comment_before_after_key( 'test1', 'before test1 (top level)', after='before test2' ) data['test1']['test2'].yaml_set_start_comment('after test2', indent=4) - compare( - data, - """ + compare(data, """ xyz: a: 1 # comment 1 b: 2 @@ -574,12 +438,10 @@ class TestCommentsManipulation: test2: # after test2 test3: 3 - """, - ) + """) def test_map_set_comment_before_and_after_non_first_key_01(self): - data = load( - """ + data = load(""" xyz: a: 1 # comment 1 b: 2 @@ -587,16 +449,13 @@ class TestCommentsManipulation: test1: test2: test3: 3 - """ - ) + """) data.yaml_set_comment_before_after_key( 'test1', 'before test1 (top level)', after='before test2\n\n' ) 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, - """ + compare_eol(data, """ xyz: a: 1 # comment 1 b: 2 @@ -608,12 +467,10 @@ class TestCommentsManipulation: test2: # after test2 test3: 3 - """, - ) + """) def test_map_set_comment_before_and_after_non_first_key_02(self): - data = load( - """ + data = load(""" xyz: a: 1 # comment 1 b: 2 @@ -621,16 +478,13 @@ class TestCommentsManipulation: test1: test2: test3: 3 - """ - ) + """) data.yaml_set_comment_before_after_key( 'test1', 'xyz\n\nbefore test1 (top level)', after='\nbefore test2', after_indent=4 ) 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, - """ + compare_eol(data, """ xyz: a: 1 # comment 1 b: 2 @@ -644,5 +498,4 @@ class TestCommentsManipulation: test2: # after test2 test3: 3 - """, - ) + """) diff --git a/_test/test_comments.py b/_test/test_comments.py index 7a43a97..bb08f7e 100644 --- a/_test/test_comments.py +++ b/_test/test_comments.py @@ -27,18 +27,15 @@ class TestComments: round_trip(x, extra='a\n') def test_no_comments(self): - round_trip( - """ + round_trip(""" - europe: 10 - usa: - ohio: 2 - california: 9 - """ - ) + """) def test_round_trip_ordering(self): - round_trip( - """ + round_trip(""" a: 1 b: 2 c: 3 @@ -47,32 +44,25 @@ class TestComments: d: 4 e: 5 f: 6 - """ - ) + """) def test_complex(self): - round_trip( - """ + round_trip(""" - europe: 10 # top - usa: - ohio: 2 - california: 9 # o - """ - ) + """) def test_dropped(self): - round_trip( - """ + round_trip(""" # comment scalar ... - """, - 'scalar\n...\n', - ) + """, "scalar\n...\n") def test_main_mapping_begin_end(self): - round_trip( - """ + round_trip(""" # C start a # C start b abc: 1 @@ -80,8 +70,7 @@ class TestComments: klm: 3 # C end a # C end b - """ - ) + """) def test_reindent(self): x = """\ @@ -91,17 +80,14 @@ class TestComments: """ d = round_trip_load(x) y = round_trip_dump(d, indent=4) - assert y == dedent( - """\ + assert y == dedent("""\ a: b: # comment 1 c: 1 # comment 2 - """ - ) + """) def test_main_mapping_begin_end_items_post(self): - round_trip( - """ + round_trip(""" # C start a # C start b abc: 1 # abc comment @@ -109,12 +95,10 @@ class TestComments: klm: 3 # klm comment # C end a # C end b - """ - ) + """) def test_main_sequence_begin_end(self): - round_trip( - """ + round_trip(""" # C start a # C start b - abc @@ -122,12 +106,10 @@ class TestComments: - klm # C end a # C end b - """ - ) + """) def test_main_sequence_begin_end_items_post(self): - round_trip( - """ + round_trip(""" # C start a # C start b - abc # abc comment @@ -135,12 +117,10 @@ class TestComments: - klm # klm comment # C end a # C end b - """ - ) + """) def test_main_mapping_begin_end_complex(self): - round_trip( - """ + round_trip(""" # C start a # C start b abc: 1 @@ -150,12 +130,10 @@ class TestComments: 3b: beta # it is all greek to me # C end a # C end b - """ - ) + """) def test_09(self): # 2.9 from the examples in the spec - round_trip( - """ + round_trip(""" hr: # 1998 hr ranking - Mark McGwire - Sammy Sosa @@ -163,14 +141,10 @@ class TestComments: # 1998 rbi ranking - Sammy Sosa - Ken Griffey - """, - indent=4, - block_seq_indent=2, - ) + """, indent=4, block_seq_indent=2) def test_09a(self): - round_trip( - """ + round_trip(""" hr: # 1998 hr ranking - Mark McGwire - Sammy Sosa @@ -178,44 +152,36 @@ class TestComments: # 1998 rbi ranking - Sammy Sosa - Ken Griffey - """ - ) + """) def test_simple_map_middle_comment(self): - round_trip( - """ + round_trip(""" abc: 1 # C 3a # C 3b ghi: 2 - """ - ) + """) def test_map_in_map_0(self): - round_trip( - """ + round_trip(""" map1: # comment 1 # comment 2 map2: key1: val1 - """ - ) + """) def test_map_in_map_1(self): # comment is moved from value to key - round_trip( - """ + round_trip(""" map1: # comment 1 map2: key1: val1 - """ - ) + """) def test_application_arguments(self): # application configur - round_trip( - """ + round_trip(""" args: username: anthon passwd: secret @@ -224,8 +190,7 @@ class TestComments: session-name: test loop: wait: 10 - """ - ) + """) def test_substitute(self): x = """ @@ -245,8 +210,7 @@ class TestComments: assert round_trip_dump(data) == dedent(x) def test_set_comment(self): - round_trip( - """ + round_trip(""" !!set # the beginning ? a @@ -254,35 +218,29 @@ class TestComments: ? b # You see? Promised you. ? c # this is the end - """ - ) + """) def test_omap_comment_roundtrip(self): - round_trip( - """ + round_trip(""" !!omap - a: 1 - b: 2 # two - c: 3 # three - d: 4 - """ - ) + """) def test_omap_comment_roundtrip_pre_comment(self): - round_trip( - """ + round_trip(""" !!omap - a: 1 - b: 2 # two - c: 3 # three # last one - d: 4 - """ - ) + """) def test_non_ascii(self): - round_trip( - """ + round_trip(""" verbosity: 1 # 0 is minimal output, -1 none base_url: http://gopher.net special_indices: [1, 5, 8] @@ -301,19 +259,16 @@ class TestComments: <<: *asia_europe Spain: Madrid Italy: Rome - """ - ) + """) def test_dump_utf8(self): import ruamel.yaml # NOQA - x = dedent( - """\ + x = dedent("""\ ab: - x # comment - y # more comment - """ - ) + """) data = round_trip_load(x) dumper = ruamel.yaml.RoundTripDumper for utf in [True, False]: @@ -325,13 +280,11 @@ class TestComments: def test_dump_unicode_utf8(self): import ruamel.yaml # NOQA - x = dedent( - u"""\ + x = dedent(u"""\ ab: - x # comment - y # more comment - """ - ) + """) data = round_trip_load(x) dumper = ruamel.yaml.RoundTripDumper for utf in [True, False]: @@ -378,8 +331,7 @@ class TestInsertPopList: d = round_trip_load(self.ins) d['ab'].insert(0, 'xyz') y = round_trip_dump(d, indent=2) - assert y == dedent( - """\ + assert y == dedent("""\ ab: - xyz - a # a @@ -390,15 +342,13 @@ class TestInsertPopList: de: - 1 - 2 - """ - ) + """) def test_insert_1(self): d = round_trip_load(self.ins) d['ab'].insert(4, 'xyz') y = round_trip_dump(d, indent=2) - assert y == dedent( - """\ + assert y == dedent("""\ ab: - a # a - b # b @@ -409,15 +359,13 @@ class TestInsertPopList: de: - 1 - 2 - """ - ) + """) def test_insert_2(self): d = round_trip_load(self.ins) d['ab'].insert(1, 'xyz') y = round_trip_dump(d, indent=2) - assert y == dedent( - """\ + assert y == dedent("""\ ab: - a # a - xyz @@ -428,16 +376,14 @@ class TestInsertPopList: de: - 1 - 2 - """ - ) + """) def test_pop_0(self): d = round_trip_load(self.ins) d['ab'].pop(0) y = round_trip_dump(d, indent=2) print(y) - assert y == dedent( - """\ + assert y == dedent("""\ ab: - b # b - c @@ -446,16 +392,14 @@ class TestInsertPopList: de: - 1 - 2 - """ - ) + """) def test_pop_1(self): d = round_trip_load(self.ins) d['ab'].pop(1) y = round_trip_dump(d, indent=2) print(y) - assert y == dedent( - """\ + assert y == dedent("""\ ab: - a # a - c @@ -464,16 +408,14 @@ class TestInsertPopList: de: - 1 - 2 - """ - ) + """) def test_pop_2(self): d = round_trip_load(self.ins) d['ab'].pop(2) y = round_trip_dump(d, indent=2) print(y) - assert y == dedent( - """\ + assert y == dedent("""\ ab: - a # a - b # b @@ -482,16 +424,14 @@ class TestInsertPopList: de: - 1 - 2 - """ - ) + """) def test_pop_3(self): d = round_trip_load(self.ins) d['ab'].pop(3) y = round_trip_dump(d, indent=2) print(y) - assert y == dedent( - """\ + assert y == dedent("""\ ab: - a # a - b # b @@ -499,8 +439,7 @@ class TestInsertPopList: de: - 1 - 2 - """ - ) + """) # inspired by demux' question on stackoverflow @@ -519,28 +458,24 @@ class TestInsertInMapping: d.insert(1, 'last name', 'Vandelay', comment='new key') y = round_trip_dump(d) print(y) - assert y == dedent( - """\ + assert y == dedent("""\ first_name: Art last name: Vandelay # new key occupation: Architect # This is an occupation comment about: Art Vandelay is a fictional character that George invents... - """ - ) + """) def test_insert_at_pos_0(self): d = round_trip_load(self.ins) d.insert(0, 'last name', 'Vandelay', comment='new key') y = round_trip_dump(d) print(y) - assert y == dedent( - """\ + assert y == dedent("""\ last name: Vandelay # new key first_name: Art occupation: Architect # This is an occupation comment about: Art Vandelay is a fictional character that George invents... - """ - ) + """) def test_insert_at_pos_3(self): # much more simple if done with appending. @@ -548,20 +483,17 @@ class TestInsertInMapping: d.insert(3, 'last name', 'Vandelay', comment='new key') y = round_trip_dump(d) print(y) - assert y == dedent( - """\ + assert y == dedent("""\ first_name: Art occupation: Architect # This is an occupation comment about: Art Vandelay is a fictional character that George invents... last name: Vandelay # new key - """ - ) + """) class TestCommentedMapMerge: def test_in_operator(self): - data = round_trip_load( - """ + data = round_trip_load(""" x: &base a: 1 b: 2 @@ -570,36 +502,31 @@ class TestCommentedMapMerge: <<: *base k: 4 l: 5 - """ - ) + """) assert data['x']['a'] == 1 assert 'a' in data['x'] assert data['y']['a'] == 1 assert 'a' in data['y'] def test_issue_60(self): - data = round_trip_load( - """ + data = round_trip_load(""" x: &base a: 1 y: <<: *base - """ - ) + """) assert data['x']['a'] == 1 assert data['y']['a'] == 1 assert str(data['y']) == """ordereddict([('a', 1)])""" def test_issue_60_1(self): - data = round_trip_load( - """ + data = round_trip_load(""" x: &base a: 1 y: <<: *base b: 2 - """ - ) + """) assert data['x']['a'] == 1 assert data['y']['a'] == 1 assert str(data['y']) == """ordereddict([('b', 2), ('a', 1)])""" @@ -608,8 +535,7 @@ class TestCommentedMapMerge: class TestEmptyLines: # prompted by issue 46 from Alex Harvey def test_issue_46(self): - yaml_str = dedent( - """\ + yaml_str = dedent("""\ --- # Please add key/value pairs in alphabetical order @@ -618,15 +544,13 @@ class TestEmptyLines: jenkins_ad_credentials: bind_name: 'CN=svc-AAA-BBB-T,OU=Example,DC=COM,DC=EXAMPLE,DC=Local' bind_pass: 'xxxxyyyy{' - """ - ) + """) d = round_trip_load(yaml_str, preserve_quotes=True) y = round_trip_dump(d, explicit_start=True) assert yaml_str == y def test_multispace_map(self): - round_trip( - """ + round_trip(""" a: 1x b: 2x @@ -638,13 +562,11 @@ class TestEmptyLines: d: 4x - """ - ) + """) @pytest.mark.xfail(strict=True) def test_multispace_map_initial(self): - round_trip( - """ + round_trip(""" a: 1x @@ -657,33 +579,27 @@ class TestEmptyLines: d: 4x - """ - ) + """) def test_embedded_map(self): - round_trip( - """ + round_trip(""" - a: 1y b: 2y c: 3y - """ - ) + """) def test_toplevel_seq(self): - round_trip( - """\ + round_trip("""\ - 1 - 2 - 3 - """ - ) + """) def test_embedded_seq(self): - round_trip( - """ + round_trip(""" a: b: - 1 @@ -692,8 +608,7 @@ class TestEmptyLines: - 3 - """ - ) + """) def test_line_with_only_spaces(self): # issue 54 @@ -718,14 +633,12 @@ class TestEmptyLines: assert stripped == y def test_issue_54_not_ok(self): - yaml_str = dedent( - """\ + yaml_str = dedent("""\ toplevel: # some comment sublevel: 300 - """ - ) + """) d = round_trip_load(yaml_str) print(d.ca) y = round_trip_dump(d, indent=4) @@ -733,61 +646,50 @@ class TestEmptyLines: assert yaml_str == y def test_issue_54_ok(self): - yaml_str = dedent( - """\ + yaml_str = dedent("""\ toplevel: # some comment sublevel: 300 - """ - ) + """) d = round_trip_load(yaml_str) y = round_trip_dump(d, indent=4) assert yaml_str == y def test_issue_93(self): - round_trip( - """\ + round_trip("""\ a: b: - c1: cat # a1 # my comment on catfish - c2: catfish # a2 - """ - ) + """) def test_issue_93_00(self): - round_trip( - """\ + round_trip("""\ a: - - c1: cat # a1 # my comment on catfish - c2: catfish # a2 - """ - ) + """) def test_issue_93_01(self): - round_trip( - """\ + round_trip("""\ - - c1: cat # a1 # my comment on catfish - c2: catfish # a2 - """ - ) + """) def test_issue_93_02(self): # never failed as there is no indent - round_trip( - """\ + round_trip("""\ - c1: cat # my comment on catfish - c2: catfish - """ - ) + """) def test_issue_96(self): # inserted extra line on trailing spaces - round_trip( - """\ + round_trip("""\ a: b: c: c_val @@ -795,15 +697,13 @@ class TestEmptyLines: e: g: g_val - """ - ) + """) class TestUnicodeComments: @pytest.mark.skipif(sys.version_info < (2, 7), reason='wide unicode') def test_issue_55(self): # reported by Haraguroicha Hsu - round_trip( - """\ + round_trip("""\ name: TEST description: test using author: Harguroicha @@ -818,111 +718,87 @@ class TestUnicodeComments: - :no: 05338777 # 〇〇啓 - :no: 05273867 # 〇 - :no: 05205786 # 〇𤦌 - """ - ) + """) class TestEmptyValueBeforeComments: def test_issue_25a(self): - round_trip( - """\ + round_trip("""\ - a: b c: d d: # foo - e: f - """ - ) + """) def test_issue_25a1(self): - round_trip( - """\ + round_trip("""\ - a: b c: d d: # foo e: f - """ - ) + """) def test_issue_25b(self): - round_trip( - """\ + round_trip("""\ var1: #empty var2: something #notempty - """ - ) + """) def test_issue_25c(self): - round_trip( - """\ + round_trip("""\ params: a: 1 # comment a b: # comment b c: 3 # comment c - """ - ) + """) def test_issue_25c1(self): - round_trip( - """\ + round_trip("""\ params: a: 1 # comment a b: # comment b # extra c: 3 # comment c - """ - ) + """) def test_issue_25_00(self): - round_trip( - """\ + round_trip("""\ params: a: 1 # comment a b: # comment b - """ - ) + """) def test_issue_25_01(self): - round_trip( - """\ + round_trip("""\ a: # comment 1 # comment 2 - b: # comment 3 c: 1 # comment 4 - """ - ) + """) def test_issue_25_02(self): - round_trip( - """\ + round_trip("""\ a: # comment 1 # comment 2 - b: 2 # comment 3 - """ - ) + """) def test_issue_25_03(self): - round_trip( - """\ + round_trip("""\ a: # comment 1 # comment 2 - b: 2 # comment 3 - """, - indent=4, - block_seq_indent=2, - ) + """, indent=4, block_seq_indent=2) def test_issue_25_04(self): - round_trip( - """\ + round_trip("""\ a: # comment 1 # comment 2 b: 1 # comment 3 - """ - ) + """) def test_flow_seq_within_seq(self): - round_trip( - """\ + round_trip("""\ # comment 1 - a - b @@ -934,8 +810,7 @@ class TestEmptyValueBeforeComments: - f # comment 4 - [] - """ - ) + """) test_block_scalar_commented_line_template = """\ diff --git a/_test/test_copy.py b/_test/test_copy.py index a912259..4931d2a 100644 --- a/_test/test_copy.py +++ b/_test/test_copy.py @@ -13,11 +13,9 @@ from roundtrip import dedent, round_trip_load, round_trip_dump class TestDeepCopy: def test_preserve_flow_style_simple(self): - x = dedent( - """\ + x = dedent("""\ {foo: bar, baz: quux} - """ - ) + """) data = round_trip_load(x) data_copy = copy.deepcopy(data) y = round_trip_dump(data_copy) @@ -27,11 +25,9 @@ class TestDeepCopy: assert data.fa.flow_style() == data_copy.fa.flow_style() def test_deepcopy_flow_style_nested_dict(self): - x = dedent( - """\ + x = dedent("""\ a: {foo: bar, baz: quux} - """ - ) + """) data = round_trip_load(x) assert data['a'].fa.flow_style() is True data_copy = copy.deepcopy(data) @@ -44,20 +40,16 @@ class TestDeepCopy: print('x [{}]'.format(x)) print('y [{}]'.format(y)) - assert y == dedent( - """\ + assert y == dedent("""\ a: foo: bar baz: quux - """ - ) + """) def test_deepcopy_flow_style_nested_list(self): - x = dedent( - """\ + x = dedent("""\ a: [1, 2, 3] - """ - ) + """) data = round_trip_load(x) assert data['a'].fa.flow_style() is True data_copy = copy.deepcopy(data) @@ -70,23 +62,19 @@ class TestDeepCopy: print('x [{}]'.format(x)) print('y [{}]'.format(y)) - assert y == dedent( - """\ + assert y == dedent("""\ a: - 1 - 2 - 3 - """ - ) + """) class TestCopy: def test_copy_flow_style_nested_dict(self): - x = dedent( - """\ + x = dedent("""\ a: {foo: bar, baz: quux} - """ - ) + """) data = round_trip_load(x) assert data['a'].fa.flow_style() is True data_copy = copy.copy(data) @@ -99,20 +87,16 @@ class TestCopy: z = round_trip_dump(data) assert y == z - assert y == dedent( - """\ + assert y == dedent("""\ a: foo: bar baz: quux - """ - ) + """) def test_copy_flow_style_nested_list(self): - x = dedent( - """\ + x = dedent("""\ a: [1, 2, 3] - """ - ) + """) data = round_trip_load(x) assert data['a'].fa.flow_style() is True data_copy = copy.copy(data) @@ -125,11 +109,9 @@ class TestCopy: print('x [{}]'.format(x)) print('y [{}]'.format(y)) - assert y == dedent( - """\ + assert y == dedent("""\ a: - 1 - 2 - 3 - """ - ) + """) diff --git a/_test/test_datetime.py b/_test/test_datetime.py index fe94c02..8540863 100644 --- a/_test/test_datetime.py +++ b/_test/test_datetime.py @@ -27,140 +27,103 @@ from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NO class TestDateTime: def test_date_only(self): - round_trip( - """ + round_trip(""" - 2011-10-02 - """, - """ + """, """ - 2011-10-02 - """, - ) + """) def test_zero_fraction(self): - round_trip( - """ + round_trip(""" - 2011-10-02 16:45:00.0 - """, - """ + """, """ - 2011-10-02 16:45:00 - """, - ) + """) def test_long_fraction(self): - round_trip( - """ + round_trip(""" - 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 - """, - """ + """, """ - 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 - """, - ) + """) def test_canonical(self): - round_trip( - """ + round_trip(""" - 2011-10-02T16:45:00.1Z - """, - """ + """, """ - 2011-10-02T16:45:00.100000Z - """, - ) + """) def test_spaced_timezone(self): - round_trip( - """ + round_trip(""" - 2011-10-02T11:45:00 -5 - """, - """ + """, """ - 2011-10-02T11:45:00-5 - """, - ) + """) def test_normal_timezone(self): - round_trip( - """ + round_trip(""" - 2011-10-02T11:45:00-5 - 2011-10-02 11:45:00-5 - 2011-10-02T11:45:00-05:00 - 2011-10-02 11:45:00-05:00 - """ - ) + """) def test_no_timezone(self): - round_trip( - """ + round_trip(""" - 2011-10-02 6:45:00 - """, - """ + """, """ - 2011-10-02 06:45:00 - """, - ) + """) def test_explicit_T(self): - round_trip( - """ + round_trip(""" - 2011-10-02T16:45:00 - """, - """ + """, """ - 2011-10-02T16:45:00 - """, - ) + """) def test_explicit_t(self): # to upper - round_trip( - """ + round_trip(""" - 2011-10-02t16:45:00 - """, - """ + """, """ - 2011-10-02T16:45:00 - """, - ) + """) def test_no_T_multi_space(self): - round_trip( - """ + round_trip(""" - 2011-10-02 16:45:00 - """, - """ + """, """ - 2011-10-02 16:45:00 - """, - ) + """) def test_iso(self): - round_trip( - """ + round_trip(""" - 2011-10-02T15:45:00+01:00 - """ - ) + """) def test_zero_tz(self): - round_trip( - """ + round_trip(""" - 2011-10-02T15:45:00+0 - """ - ) + """) def test_issue_45(self): - round_trip( - """ + round_trip(""" dt: 2016-08-19T22:45:47Z - """ - ) + """) def test_deepcopy_datestring(self): # reported by Quuxplusone, http://stackoverflow.com/a/41577841/1307905 - x = dedent( - """\ + x = dedent("""\ foo: 2016-10-12T12:34:56 - """ - ) + """) data = copy.deepcopy(round_trip_load(x)) assert round_trip_dump(data) == x diff --git a/_test/test_documents.py b/_test/test_documents.py index 476f70c..6f714e9 100644 --- a/_test/test_documents.py +++ b/_test/test_documents.py @@ -7,32 +7,23 @@ from roundtrip import round_trip, round_trip_load_all class TestDocument: def test_single_doc_begin_end(self): - round_trip( - """\ + round_trip("""\ --- - a - b ... - """, - explicit_start=True, - explicit_end=True, - ) + """, explicit_start=True, explicit_end=True) def test_multi_doc_begin_end(self): from ruamel import yaml - - docs = list( - round_trip_load_all( - """\ + docs = list(round_trip_load_all("""\ --- - a ... --- - b ... - """ - ) - ) + """)) assert docs == [['a'], ['b']] out = yaml.dump_all( docs, Dumper=yaml.RoundTripDumper, explicit_start=True, explicit_end=True @@ -40,44 +31,31 @@ 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( - """\ + docs = list(round_trip_load_all("""\ - a ... --- - b ... - """ - ) - ) + """)) assert docs == [['a'], ['b']] def test_multi_doc_no_end(self): - docs = list( - round_trip_load_all( - """\ + docs = list(round_trip_load_all("""\ - a --- - b - """ - ) - ) + """)) assert docs == [['a'], ['b']] def test_multi_doc_ends_only(self): # this is ok in 1.2 - docs = list( - round_trip_load_all( - """\ + docs = list(round_trip_load_all("""\ - a ... - b ... - """, - version=(1, 2), - ) - ) + """, version=(1, 2))) assert docs == [['a'], ['b']] def test_multi_doc_ends_only_1_1(self): @@ -85,15 +63,10 @@ class TestDocument: # this is not ok in 1.1 with pytest.raises(yaml.parser.ParserError): - docs = list( - round_trip_load_all( - """\ + docs = list(round_trip_load_all("""\ - a ... - b ... - """, - version=(1, 1), - ) - ) + """, 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 9c318a0..2f0b37a 100644 --- a/_test/test_fail.py +++ b/_test/test_fail.py @@ -15,8 +15,7 @@ class TestCommentFailures: @pytest.mark.xfail(strict=True) def test_set_comment_before_tag(self): # no comments before tags - round_trip( - """ + round_trip(""" # the beginning !!set # or this one? @@ -25,15 +24,11 @@ class TestCommentFailures: ? b # You see? Promised you. ? c # this is the end - """ - ) + """) def test_set_comment_before_tag_no_fail(self): # no comments before tags - assert ( - round_trip_dump( - round_trip_load( - """ + assert round_trip_dump(round_trip_load(""" # the beginning !!set # or this one? @@ -42,11 +37,7 @@ class TestCommentFailures: ? b # You see? Promised you. ? c # this is the end - """ - ) - ) - == dedent( - """ + """)) == dedent(""" !!set # or this one? ? a @@ -54,19 +45,15 @@ class TestCommentFailures: ? b # You see? Promised you. ? c # this is the end - """ - ) - ) + """) @pytest.mark.xfail(strict=True) def test_comment_dash_line(self): - round_trip( - """ + round_trip(""" - # abc a: 1 b: 2 - """ - ) + """) def test_comment_dash_line_fail(self): x = """ @@ -76,20 +63,17 @@ class TestCommentFailures: """ data = round_trip_load(x) # this is not nice - assert round_trip_dump(data) == dedent( - """ + assert round_trip_dump(data) == dedent(""" # abc - a: 1 b: 2 - """ - ) + """) class TestIndentFailures: @pytest.mark.xfail(strict=True) def test_indent_not_retained(self): - round_trip( - """ + round_trip(""" verbosity: 1 # 0 is minimal output, -1 none base_url: http://gopher.net special_indices: [1, 5, 8] @@ -110,14 +94,10 @@ class TestIndentFailures: Italy: Rome Antarctica: - too cold - """ - ) + """) def test_indent_not_retained_no_fail(self): - assert ( - round_trip_dump( - round_trip_load( - """ + assert round_trip_dump(round_trip_load(""" verbosity: 1 # 0 is minimal output, -1 none base_url: http://gopher.net special_indices: [1, 5, 8] @@ -138,12 +118,7 @@ class TestIndentFailures: Italy: Rome Antarctica: - too cold - """ - ), - indent=4, - ) - == dedent( - """ + """), indent=4) == dedent(""" verbosity: 1 # 0 is minimal output, -1 none base_url: http://gopher.net special_indices: [1, 5, 8] @@ -164,67 +139,46 @@ class TestIndentFailures: Italy: Rome Antarctica: - too cold - """ - ) - ) + """) def Xtest_indent_top_level_no_fail(self): - round_trip( - """ + round_trip(""" - a: - b - """, - indent=4, - ) + """, indent=4) class TestTagFailures: @pytest.mark.xfail(strict=True) def test_standard_short_tag(self): - round_trip( - """\ + round_trip("""\ !!map name: Anthon location: Germany language: python - """ - ) + """) def test_standard_short_tag_no_fail(self): - assert ( - round_trip_dump( - round_trip_load( - """ + assert round_trip_dump(round_trip_load(""" !!map name: Anthon location: Germany language: python - """ - ) - ) - == dedent( - """ + """)) == dedent(""" name: Anthon location: Germany language: python - """ - ) - ) + """) class TestFlowValues: def test_flow_value_with_colon(self): - round_trip( - """\ + round_trip("""\ {a: bcd:efg} - """ - ) + """) # @pytest.mark.xfail(strict=True) def test_flow_value_with_colon_quoted(self): - round_trip( - """\ + round_trip("""\ {a: 'bcd:efg'} - """, - preserve_quotes=True, - ) + """, preserve_quotes=True) diff --git a/_test/test_float.py b/_test/test_float.py index b115eb3..146793b 100644 --- a/_test/test_float.py +++ b/_test/test_float.py @@ -11,8 +11,7 @@ from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NO class TestFloat: def test_round_trip_non_exp(self): - data = round_trip( - """\ + data = round_trip("""\ - 1.0 - 1.00 - 23.100 @@ -22,8 +21,7 @@ class TestFloat: - 42. - -42. - +42. - """ - ) + """) print(data) assert 0.999 < data[0] < 1.001 assert 0.999 < data[1] < 1.001 @@ -36,8 +34,7 @@ class TestFloat: assert 41.999 < data[8] < 42.001 def test_round_trip_zeros_0(self): - data = round_trip( - """\ + data = round_trip("""\ - 0. - +0. - -0. @@ -47,8 +44,7 @@ class TestFloat: - 0.00 - +0.00 - -0.00 - """ - ) + """) print(data) for d in data: assert -0.00001 < d < 0.00001 @@ -56,112 +52,94 @@ class TestFloat: # @pytest.mark.xfail(strict=True) def test_round_trip_zeros_1(self): # not sure if this should be supported, but it is - data = round_trip( - """\ + data = round_trip("""\ - 00.0 - +00.0 - -00.0 - """ - ) + """) print(data) for d in data: assert -0.00001 < d < 0.00001 def Xtest_round_trip_non_exp_trailing_dot(self): - data = round_trip( - """\ - """ - ) + data = round_trip("""\ + """) print(data) def test_round_trip_exp_00(self): - data = round_trip( - """\ + data = round_trip("""\ - 42e56 - 42E56 - 42.0E56 - +42.0e56 - 42.0E+056 - +42.00e+056 - """ - ) + """) print(data) for d in data: assert 41.99e56 < d < 42.01e56 # @pytest.mark.xfail(strict=True) def test_round_trip_exp_00f(self): - data = round_trip( - """\ + data = round_trip("""\ - 42.E56 - """ - ) + """) print(data) for d in data: assert 41.99e56 < d < 42.01e56 def test_round_trip_exp_01(self): - data = round_trip( - """\ + data = round_trip("""\ - -42e56 - -42E56 - -42.0e56 - -42.0E+056 - """ - ) + """) print(data) for d in data: assert -41.99e56 > d > -42.01e56 def test_round_trip_exp_02(self): - data = round_trip( - """\ + data = round_trip("""\ - 42e-56 - 42E-56 - 42.0E-56 - +42.0e-56 - 42.0E-056 - +42.0e-056 - """ - ) + """) print(data) for d in data: assert 41.99e-56 < d < 42.01e-56 def test_round_trip_exp_03(self): - data = round_trip( - """\ + data = round_trip("""\ - -42e-56 - -42E-56 - -42.0e-56 - -42.0E-056 - """ - ) + """) print(data) for d in data: assert -41.99e-56 > d > -42.01e-56 def test_round_trip_exp_04(self): - round_trip( - """\ + round_trip("""\ - 1.2e+34 - 1.23e+034 - 1.230e+34 - 1.023e+34 - -1.023e+34 - 250e6 - """ - ) + """) def test_round_trip_exp_05(self): - data = round_trip( - """\ + data = round_trip("""\ - 3.0517578123e-56 - 3.0517578123E-56 - 3.0517578123e-056 - 3.0517578123E-056 - """ - ) + """) print(data) for d in data: assert 3.0517578122e-56 < d < 3.0517578124e-56 @@ -170,23 +148,19 @@ class TestFloat: from ruamel.yaml.error import MantissaNoDotYAML1_1Warning with pytest.warns(MantissaNoDotYAML1_1Warning): - round_trip_load( - """\ + round_trip_load("""\ %YAML 1.1 --- - 1e6 - """ - ) + """) class TestCalculations(object): def test_mul_00(self): # issue 149 reported by jan.brezina@tul.cz - d = round_trip_load( - """\ + d = round_trip_load("""\ - 0.1 - """ - ) + """) d[0] *= -1 x = round_trip_dump(d) assert x == '- -0.1\n' diff --git a/_test/test_flowsequencekey.py b/_test/test_flowsequencekey.py index f8f122e..8490430 100644 --- a/_test/test_flowsequencekey.py +++ b/_test/test_flowsequencekey.py @@ -12,8 +12,7 @@ from roundtrip import round_trip # , dedent, round_trip_load, round_trip_dump class TestFlowStyleSequenceKey: def test_so_39595807(self): - round_trip( - """ + round_trip(""" %YAML 1.2 --- [2, 3, 4]: @@ -22,8 +21,4 @@ class TestFlowStyleSequenceKey: - 2 b: Hello World! c: 'Voilà !' - """, - preserve_quotes=True, - explicit_start=True, - version=(1, 2), - ) + """, preserve_quotes=True, explicit_start=True, version=(1, 2)) diff --git a/_test/test_indentation.py b/_test/test_indentation.py index dcac772..a6be430 100644 --- a/_test/test_indentation.py +++ b/_test/test_indentation.py @@ -12,14 +12,10 @@ from roundtrip import round_trip, round_trip_load, round_trip_dump, dedent, YAML def rt(s): import ruamel.yaml - - return ( - ruamel.yaml.dump( - ruamel.yaml.load(s, Loader=ruamel.yaml.RoundTripLoader), - Dumper=ruamel.yaml.RoundTripDumper, - ).strip() - + '\n' - ) + return ruamel.yaml.dump( + ruamel.yaml.load(s, Loader=ruamel.yaml.RoundTripLoader), + Dumper=ruamel.yaml.RoundTripDumper, + ).strip() + '\n' class TestIndent: @@ -29,35 +25,29 @@ class TestIndent: assert s == output def test_roundtrip_mapping_of_inline_lists(self): - s = dedent( - """\ + s = dedent("""\ a: [a, b, c] j: [k, l, m] - """ - ) + """) output = rt(s) assert s == output def test_roundtrip_mapping_of_inline_lists_comments(self): - s = dedent( - """\ + s = dedent("""\ # comment A a: [a, b, c] # comment B j: [k, l, m] - """ - ) + """) output = rt(s) assert s == output def test_roundtrip_mapping_of_inline_sequence_eol_comments(self): - s = dedent( - """\ + s = dedent("""\ # comment A a: [a, b, c] # comment B j: [k, l, m] # comment C - """ - ) + """) output = rt(s) assert s == output @@ -65,14 +55,12 @@ class TestIndent: def test_added_inline_list(self): import ruamel.yaml - s1 = dedent( - """ + s1 = dedent(""" a: - b - c - d - """ - ) + """) s = 'a: [b, c, d]\n' data = ruamel.yaml.load(s1, Loader=ruamel.yaml.RoundTripLoader) val = data['a'] @@ -86,78 +74,58 @@ class TestIndent: def test_roundtrip_flow_mapping(self): import ruamel.yaml - s = dedent( - """\ + s = dedent("""\ - {a: 1, b: hallo} - {j: fka, k: 42} - """ - ) + """) data = ruamel.yaml.load(s, Loader=ruamel.yaml.RoundTripLoader) output = ruamel.yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper) assert s == output def test_roundtrip_sequence_of_inline_mappings_eol_comments(self): - s = dedent( - """\ + s = dedent("""\ # comment A - {a: 1, b: hallo} # comment B - {j: fka, k: 42} # comment C - """ - ) + """) output = rt(s) assert s == output def test_indent_top_level(self): - round_trip( - """ + round_trip(""" - a: - b - """, - indent=4, - ) + """, indent=4) def test_set_indent_5_block_list_indent_1(self): - round_trip( - """ + round_trip(""" a: - b: c - 1 - d: - 2 - """, - indent=5, - block_seq_indent=1, - ) + """, indent=5, block_seq_indent=1) def test_set_indent_4_block_list_indent_2(self): - round_trip( - """ + round_trip(""" a: - b: c - 1 - d: - 2 - """, - indent=4, - block_seq_indent=2, - ) + """, indent=4, block_seq_indent=2) def test_set_indent_3_block_list_indent_0(self): - round_trip( - """ + round_trip(""" a: - b: c - 1 - d: - 2 - """, - indent=3, - block_seq_indent=0, - ) + """, indent=3, block_seq_indent=0) def Xtest_set_indent_3_block_list_indent_2(self): - round_trip( - """ + round_trip(""" a: - b: c @@ -167,27 +135,19 @@ class TestIndent: d: - 2 - """, - indent=3, - block_seq_indent=2, - ) + """, indent=3, block_seq_indent=2) def test_set_indent_3_block_list_indent_2(self): - round_trip( - """ + round_trip(""" a: - b: c - 1 - d: - 2 - """, - indent=3, - block_seq_indent=2, - ) + """, indent=3, block_seq_indent=2) def Xtest_set_indent_2_block_list_indent_2(self): - round_trip( - """ + round_trip(""" a: - b: c @@ -197,55 +157,42 @@ class TestIndent: d: - 2 - """, - indent=2, - block_seq_indent=2, - ) + """, 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( - """ + round_trip(""" a: - b: c - 1 - d: - 2 - """, - indent=2, - block_seq_indent=2, - ) + """, indent=2, block_seq_indent=2) # have to set indent! def test_roundtrip_four_space_indents(self): - s = 'a:\n' '- foo\n' '- bar\n' + s = ( + 'a:\n' + '- foo\n' + '- bar\n' + ) round_trip(s, indent=4) def test_roundtrip_four_space_indents_no_fail(self): - assert ( - round_trip_dump( - round_trip_load( - """ + assert round_trip_dump(round_trip_load(""" a: - foo - bar - """ - ) - ) - == dedent( - """ + """)) == dedent(""" a: - foo - bar - """ - ) - ) + """) class TestYpkgIndent: def test_00(self): - round_trip( - """ + round_trip(""" name : nano version : 2.3.2 release : 1 @@ -260,12 +207,7 @@ 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=' ', - ) + """, indent=4, block_seq_indent=2, top_level_colon_align=True, prefix_colon=' ') def guess(s): @@ -277,50 +219,30 @@ def guess(s): class TestGuessIndent: def test_guess_20(self): - assert ( - guess( - """\ + assert guess("""\ a: - 1 - """ - ) - == (2, 0) - ) + """) == (2, 0) def test_guess_42(self): - assert ( - guess( - """\ + assert guess("""\ a: - 1 - """ - ) - == (4, 2) - ) + """) == (4, 2) def test_guess_42a(self): # block seq indent prevails over nested key indent level - assert ( - guess( - """\ + assert guess("""\ b: a: - 1 - """ - ) - == (4, 2) - ) + """) == (4, 2) def test_guess_3None(self): - assert ( - guess( - """\ + assert guess("""\ b: a: 1 - """ - ) - == (3, None) - ) + """) == (3, None) class TestSeparateMapSeqIndents: @@ -331,70 +253,58 @@ class TestSeparateMapSeqIndents: yaml = YAML() yaml.indent = 6 yaml.block_seq_indent = 3 - yaml.round_trip( - """ + yaml.round_trip(""" a: - 1 - [1, 2] - """ - ) + """) def test_01(self): yaml = YAML() yaml.indent(sequence=6) yaml.indent(offset=3) - yaml.round_trip( - """ + yaml.round_trip(""" a: - 1 - {b: 3} - """ - ) + """) def test_02(self): yaml = YAML() yaml.indent(mapping=5, sequence=6, offset=3) - yaml.round_trip( - """ + yaml.round_trip(""" a: b: - 1 - [1, 2] - """ - ) + """) def test_03(self): - round_trip( - """ + round_trip(""" a: b: c: - 1 - [1, 2] - """, - indent=4, - ) + """, indent=4) def test_04(self): yaml = YAML() yaml.indent(mapping=5, sequence=6) - yaml.round_trip( - """ + yaml.round_trip(""" a: b: - 1 - [1, 2] - {d: 3.14} - """ - ) + """) def test_issue_51(self): yaml = YAML() # yaml.map_indent = 2 # the default yaml.indent(sequence=4, offset=2) yaml.preserve_quotes = True - yaml.round_trip( - """ + yaml.round_trip(""" role::startup::author::rsyslog_inputs: imfile: - ruleset: 'AEM-slinglog' @@ -405,8 +315,7 @@ class TestSeparateMapSeqIndents: File: '/opt/aem/author/crx-quickstart/logs/stdout.log' startmsg.regex: '^[-+T.:[:digit:]]*' tag: 'stdout' - """ - ) + """) # ############ indentation diff --git a/_test/test_int.py b/_test/test_int.py index daf4fda..080eb54 100644 --- a/_test/test_int.py +++ b/_test/test_int.py @@ -12,27 +12,23 @@ from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump class TestBinHexOct: # @pytest.mark.xfail(strict=True) def test_round_trip_hex_oct(self): - round_trip( - """\ + round_trip("""\ - 42 - 0b101010 - 0x2a - 0x2A - 0o52 - """ - ) + """) def test_calculate(self): # make sure type, leading zero(s) and underscore are preserved - s = dedent( - """\ + s = dedent("""\ - 42 - 0b101010 - 0x_2a - 0x2A - 0o00_52 - """ - ) + """) x = round_trip_load(s) for idx, elem in enumerate(x): # x[idx] = type(elem)(elem - 21) @@ -55,8 +51,7 @@ class TestBinHexOct: # the old octal representation. def test_leading_zero_hex_oct_bin(self): - round_trip( - """\ + round_trip("""\ - 0b0101010 - 0b00101010 - 0x02a @@ -65,32 +60,26 @@ class TestBinHexOct: - 0x002A - 0o052 - 0o0052 - """ - ) + """) def test_leading_zero_int(self): - round_trip( - """\ + round_trip("""\ - 042 - 0042 - """ - ) + """) def test_leading_zero_YAML_1_1(self): - d = round_trip_load( - """\ + d = round_trip_load("""\ %YAML 1.1 --- - 042 - 0o42 - """ - ) + """) assert d[0] == 0o42 assert d[1] == '0o42' def test_underscore(self): - round_trip( - """\ + round_trip("""\ - 0b10000_10010010 - 0b0_0000_1001_0010 - 0x2_87_57_b2_ @@ -98,28 +87,23 @@ class TestBinHexOct: - 0x_0_2_8_7_5_7_B_2 - 0o2416_53662 - 42_42_ - """ - ) + """) def test_leading_underscore(self): - d = round_trip_load( - """\ + d = round_trip_load("""\ - 0x_2_8_7_5_7_B_2 - _42_42_ - 42_42_ - """ - ) + """) assert d[0] == 42424242 assert d[1] == '_42_42_' assert d[2] == 4242 def test_big(self): # bitbucket issue 144 reported by ccatterina - d = round_trip_load( - """\ + d = round_trip_load("""\ - 2_147_483_647 - 9_223_372_036_854_775_808 - """ - ) + """) assert d[0] == 2147483647 assert d[1] == 9223372036854775808 diff --git a/_test/test_issues.py b/_test/test_issues.py index 559dcba..5de34e2 100644 --- a/_test/test_issues.py +++ b/_test/test_issues.py @@ -13,8 +13,7 @@ class TestIssue61: def test_issue_61(self): import ruamel.yaml - s = dedent( - """ + s = dedent(""" def1: &ANCHOR1 key1: value1 def: &ANCHOR @@ -22,8 +21,7 @@ class TestIssue61: key: value comb: <<: *ANCHOR - """ - ) + """) data = ruamel.yaml.round_trip_load(s) assert str(data['comb']) == str(data['def']) assert str(data['comb']) == "ordereddict([('key', 'value'), ('key1', 'value1')])" diff --git a/_test/test_line_col.py b/_test/test_line_col.py index 4f7ad5d..febe9c2 100644 --- a/_test/test_line_col.py +++ b/_test/test_line_col.py @@ -11,94 +11,80 @@ def load(s): class TestLineCol: def test_item_00(self): - data = load( - """ + data = load(""" - a - e - [b, d] - c - """ - ) + """) assert data[2].lc.line == 2 assert data[2].lc.col == 2 def test_item_01(self): - data = load( - """ + data = load(""" - a - e - {x: 3} - c - """ - ) + """) assert data[2].lc.line == 2 assert data[2].lc.col == 2 def test_item_02(self): - data = load( - """ + data = load(""" - a - e - !!set {x, y} - c - """ - ) + """) assert data[2].lc.line == 2 assert data[2].lc.col == 2 def test_item_03(self): - data = load( - """ + data = load(""" - a - e - !!omap - x: 1 - y: 3 - c - """ - ) + """) assert data[2].lc.line == 2 assert data[2].lc.col == 2 def test_item_04(self): - data = load( - """ + data = load(""" # testing line and column based on SO # http://stackoverflow.com/questions/13319067/ - key1: item 1 key2: item 2 - key3: another item 1 key4: another item 2 - """ - ) + """) assert data[0].lc.line == 2 assert data[0].lc.col == 2 assert data[1].lc.line == 4 assert data[1].lc.col == 2 def test_pos_mapping(self): - data = load( - """ + data = load(""" a: 1 b: 2 c: 3 # comment klm: 42 d: 4 - """ - ) + """) assert data.lc.key('klm') == (4, 0) assert data.lc.value('klm') == (4, 5) def test_pos_sequence(self): - data = load( - """ + data = load(""" - a - b - c # next one! - klm - d - """ - ) + """) assert data.lc.item(3) == (4, 2) diff --git a/_test/test_literal.py b/_test/test_literal.py index 5847269..86ae5f6 100644 --- a/_test/test_literal.py +++ b/_test/test_literal.py @@ -31,43 +31,31 @@ class TestNoIndent: def test_top_literal_scalar_indent_example_9_5(self): yaml = YAML() s = '%!PS-Adobe-2.0' - d = yaml.load( - """ + d = yaml.load(""" --- | {} - """.format( - s - ) - ) + """.format(s)) print(d) assert d == s + '\n' def test_top_literal_scalar_no_indent(self): yaml = YAML() s = 'testing123' - d = yaml.load( - """ + d = yaml.load(""" --- | {} - """.format( - s - ) - ) + """.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( - """ + d = yaml.load(""" %YAML 1.1 --- | {} - """.format( - s - ) - ) + """.format(s)) print(d) assert d == s + '\n' @@ -76,17 +64,11 @@ class TestNoIndent: from ruamel.yaml import safe_load s = 'testing123' - d = safe_load( - dedent( - """ + d = safe_load(dedent(""" %YAML 1.1 --- | {} - """.format( - s - ) - ) - ) + """.format(s))) print(d) assert d == s + '\n' @@ -97,112 +79,80 @@ class TestNoIndent: yaml.top_level_block_style_scalar_no_indent_error_1_1 = True s = 'testing123' with pytest.raises(ParserError): - yaml.load( - """ + yaml.load(""" %YAML 1.1 --- | {} - """.format( - s - ) - ) + """.format(s)) def test_top_literal_scalar_indent_offset_one(self): yaml = YAML() s = 'testing123' - d = yaml.load( - """ + d = yaml.load(""" --- |1 {} - """.format( - s - ) - ) + """.format(s)) print(d) assert d == s + '\n' def test_top_literal_scalar_indent_offset_four(self): yaml = YAML() s = 'testing123' - d = yaml.load( - """ + d = yaml.load(""" --- |4 {} - """.format( - s - ) - ) + """.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( - """ + d = yaml.load(""" --- |4 {s} {s} - """.format( - s=s - ) - ) + """.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( - """ + d = yaml.load(""" --- | {} - """.format( - s - ) - ) + """.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( - """ + d = yaml.load(""" --- > {} - """.format( - s - ) - ) + """.format(s)) print(d) assert d == s + '\n' def test_top_folding_scalar_no_indent(self): yaml = YAML() s = 'testing123' - d = yaml.load( - """ + d = yaml.load(""" --- > {} - """.format( - s - ) - ) + """.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( - """ + d = yaml.load(""" --- > {} - """.format( - s - ) - ) + """.format(s)) print(d) assert d == s + '\n' @@ -210,18 +160,12 @@ class TestNoIndent: yaml = YAML(typ='safe', pure=True) s1 = 'abc' s2 = 'klm' - for idx, d1 in enumerate( - yaml.load_all( - """ + for idx, d1 in enumerate(yaml.load_all(""" --- |- {} --- | {} - """.format( - s1, s2 - ) - ) - ): + """.format(s1, s2))): print('d1:', d1) assert ['abc', 'klm\n'][idx] == d1 @@ -234,36 +178,7 @@ class Test_RoundTripLiteral: ys = """ --- | {} - """.format( - s - ) - d = yaml.load(ys) - yaml.dump(d, compare=ys) - - def test_rt_top_literal_scalar_no_indent_comment(self): - yaml = YAML() - yaml.explicit_start = True - s = 'testing123' - ys = """ - --- | # a comment - {} - """.format( - s - ) - d = yaml.load(ys) - yaml.dump(d, compare=ys) - - def test_rt_top_literal_scalar_no_indent_leading_empty_line(self): - yaml = YAML() - yaml.explicit_start = True - s = 'testing123' - ys = """ - --- | - - {} - """.format( - s - ) + """.format(s) d = yaml.load(ys) yaml.dump(d, compare=ys) @@ -275,9 +190,7 @@ class Test_RoundTripLiteral: ys = """ --- | {} - """.format( - s - ) + """.format(s) d = yaml.load(ys) yaml.dump(d, compare=ys) @@ -289,9 +202,7 @@ class Test_RoundTripLiteral: ys = """ --- {} - """.format( - s - ) + """.format(s) d = yaml.load(ys) yaml.dump(d, compare=ys) @@ -303,9 +214,7 @@ class Test_RoundTripLiteral: ys = """ --- {} - """.format( - s - ) + """.format(s) d = yaml.load(ys) yaml.dump(d, compare=ys) @@ -317,9 +226,7 @@ class Test_RoundTripLiteral: ys = """ --- {} - """.format( - s - ) + """.format(s) d = yaml.load(ys) yaml.dump(d, compare=ys) @@ -333,9 +240,7 @@ class Test_RoundTripLiteral: ys = """ --- {} - """.format( - s - ) + """.format(s) d = yaml.load(ys) yaml.dump(d, compare=ys) @@ -346,9 +251,7 @@ class Test_RoundTripLiteral: ys = """ --- |- {} - """.format( - s - ) + """.format(s) d = yaml.load(ys) yaml.dump(d, compare=ys) @@ -358,8 +261,6 @@ class Test_RoundTripLiteral: ys = """ - | {} - """.format( - s - ) + """.format(s) d = yaml.load(ys) yaml.dump(d, compare=ys) diff --git a/_test/test_program_config.py b/_test/test_program_config.py index 4d7cbd5..dcd8351 100644 --- a/_test/test_program_config.py +++ b/_test/test_program_config.py @@ -8,8 +8,7 @@ from roundtrip import round_trip class TestProgramConfig: def test_application_arguments(self): # application configur - round_trip( - """ + round_trip(""" args: username: anthon passwd: secret @@ -18,13 +17,11 @@ class TestProgramConfig: session-name: test loop: wait: 10 - """ - ) + """) def test_single(self): # application configuration - round_trip( - """ + round_trip(""" # default arguments for the program args: # needed to prevent comment wrapping # this should be your username @@ -39,13 +36,11 @@ class TestProgramConfig: # experiment with the following wait: 10 # no more argument info to pass - """ - ) + """) def test_multi(self): # application configuration - round_trip( - """ + round_trip(""" # default arguments for the program args: # needed to prevent comment wrapping # this should be your username @@ -60,5 +55,4 @@ class TestProgramConfig: # experiment with the following wait: 10 # no more argument info to pass - """ - ) + """) diff --git a/_test/test_string.py b/_test/test_string.py index 351ca0e..5a466db 100644 --- a/_test/test_string.py +++ b/_test/test_string.py @@ -24,31 +24,24 @@ from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NO class TestPreservedScalarString: def test_basic_string(self): - round_trip( - """ + round_trip(""" a: abcdefg - """ - ) + """, ) def test_quoted_integer_string(self): - round_trip( - """ + round_trip(""" a: '12345' - """ - ) + """) @pytest.mark.skipif( platform.python_implementation() == 'Jython', reason='Jython throws RepresenterError' ) def test_preserve_string(self): - round_trip( - """ + round_trip(""" a: | abc def - """, - intermediate=dict(a='abc\ndef\n'), - ) + """, intermediate=dict(a='abc\ndef\n')) @pytest.mark.skipif( platform.python_implementation() == 'Jython', reason='Jython throws RepresenterError' @@ -66,18 +59,15 @@ class TestPreservedScalarString: 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: + round_trip(""" a: |+ ghi jkl b: x - """, - intermediate=dict(a='ghi\njkl\n\n\n', b='x'), - ) + """, intermediate=dict(a='ghi\njkl\n\n\n', b='x')) @pytest.mark.skipif( platform.python_implementation() == 'Jython', reason='Jython throws RepresenterError' @@ -85,80 +75,59 @@ 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( - """ + round_trip(""" a: |+ ghi jkl ... - """, - intermediate=dict(a='ghi\njkl\n\n'), - ) + """, intermediate=dict(a='ghi\njkl\n\n')) def test_fold_string(self): with pytest.raises(AssertionError) as excinfo: # NOQA - round_trip( - """ + round_trip(""" a: > abc def - """, - intermediate=dict(a='abc def\n'), - ) + """, intermediate=dict(a='abc def\n')) def test_fold_string_strip(self): with pytest.raises(AssertionError) as excinfo: # NOQA - round_trip( - """ + round_trip(""" a: >- abc def - """, - intermediate=dict(a='abc def'), - ) + """, intermediate=dict(a='abc def')) def test_fold_string_keep(self): with pytest.raises(AssertionError) as excinfo: # NOQA - round_trip( - """ + round_trip(""" a: >+ abc def - """, - intermediate=dict(a='abc def\n\n'), - ) + """, intermediate=dict(a='abc def\n\n')) class TestQuotedScalarString: def test_single_quoted_string(self): - round_trip( - """ + round_trip(""" a: 'abc' - """, - preserve_quotes=True, - ) + """, preserve_quotes=True) def test_double_quoted_string(self): - round_trip( - """ + round_trip(""" a: "abc" - """, - preserve_quotes=True, - ) + """, preserve_quotes=True) def test_non_preserved_double_quoted_string(self): - round_trip( - """ + round_trip(""" a: "abc" - """, - outp=""" + """, outp=""" a: abc - """, - ) + """) class TestReplace: @@ -167,35 +136,29 @@ class TestReplace: def test_replace_preserved_scalar_string(self): import ruamel - s = dedent( - """\ + s = dedent("""\ foo: | foo foo bar foo - """ - ) + """) data = round_trip_load(s, preserve_quotes=True) so = data['foo'].replace('foo', 'bar', 2) assert isinstance(so, ruamel.yaml.scalarstring.PreservedScalarString) - assert so == dedent( - """ + assert so == dedent(""" bar bar bar foo - """ - ) + """) def test_replace_double_quoted_scalar_string(self): import ruamel - s = dedent( - """\ + s = dedent("""\ foo: "foo foo bar foo" - """ - ) + """) data = round_trip_load(s, preserve_quotes=True) so = data['foo'].replace('foo', 'bar', 2) assert isinstance(so, ruamel.yaml.scalarstring.DoubleQuotedScalarString) diff --git a/_test/test_tag.py b/_test/test_tag.py index 824a0c3..dd2245a 100644 --- a/_test/test_tag.py +++ b/_test/test_tag.py @@ -25,112 +25,92 @@ def register_xxx(**kw): class TestIndentFailures: def test_tag(self): - round_trip( - """\ + round_trip("""\ !!python/object:__main__.Developer name: Anthon location: Germany language: python - """ - ) + """) def test_full_tag(self): - round_trip( - """\ + round_trip("""\ !!tag:yaml.org,2002:python/object:__main__.Developer name: Anthon location: Germany language: python - """ - ) + """) def test_standard_tag(self): - round_trip( - """\ + round_trip("""\ !!tag:yaml.org,2002:python/object:map name: Anthon location: Germany language: python - """ - ) + """) def test_Y1(self): - round_trip( - """\ + round_trip("""\ !yyy name: Anthon location: Germany language: python - """ - ) + """) def test_Y2(self): - round_trip( - """\ + round_trip("""\ !!yyy name: Anthon location: Germany language: python - """ - ) + """) class TestRoundTripCustom: def test_X1(self): register_xxx() - round_trip( - """\ + 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( - """\ + 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( - """\ + round_trip("""\ - !xxx # hello name: Anthon location: Germany language: python - """ - ) + """) def test_scalar_00(self): # https://stackoverflow.com/a/45967047/1307905 - round_trip( - """\ + 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( - """ + round_trip_load(""" s: !!python/%75nicode 'abc' - """ - ) + """) diff --git a/_test/test_version.py b/_test/test_version.py index 9aa4133..61e3bca 100644 --- a/_test/test_version.py +++ b/_test/test_version.py @@ -13,8 +13,7 @@ def load(s, version=None): class TestVersions: def test_explicit_1_2(self): - r = load( - """\ + r = load("""\ %YAML 1.2 --- - 12:34:56 @@ -26,8 +25,7 @@ class TestVersions: - yes - no - true - """ - ) + """) assert r[0] == '12:34:56' assert r[1] == 12 assert r[2] == 12345678 @@ -39,8 +37,7 @@ class TestVersions: assert r[8] is True def test_explicit_1_1(self): - r = load( - """\ + r = load("""\ %YAML 1.1 --- - 12:34:56 @@ -52,8 +49,7 @@ class TestVersions: - yes - no - true - """ - ) + """) assert r[0] == 45296 assert r[1] == 10 assert r[2] == '012345678' @@ -65,8 +61,7 @@ class TestVersions: assert r[8] is True def test_implicit_1_2(self): - r = load( - """\ + r = load("""\ - 12:34:56 - 12:34:56.78 - 012 @@ -77,8 +72,7 @@ class TestVersions: - yes - no - true - """ - ) + """) assert r[0] == '12:34:56' assert r[1] == '12:34:56.78' assert r[2] == 12 @@ -91,8 +85,7 @@ class TestVersions: assert r[9] is True def test_load_version_1_1(self): - r = load( - """\ + r = load("""\ - 12:34:56 - 12:34:56.78 - 012 @@ -103,9 +96,7 @@ class TestVersions: - yes - no - true - """, - version='1.1', - ) + """, version="1.1") assert r[0] == 45296 assert r[1] == 45296.78 assert r[2] == 10 @@ -123,8 +114,7 @@ class TestIssue62: def test_00(self): import ruamel.yaml # NOQA - s = dedent( - """\ + s = dedent("""\ {}# Outside flow collection: - ::vector - ": - ()" @@ -133,8 +123,7 @@ class TestIssue62: - 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) @@ -142,8 +131,7 @@ class TestIssue62: def test_00_single_comment(self): import ruamel.yaml # NOQA - s = dedent( - """\ + s = dedent("""\ {}# Outside flow collection: - ::vector - ": - ()" @@ -151,8 +139,7 @@ class TestIssue62: - -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) @@ -161,11 +148,9 @@ class TestIssue62: def test_01(self): import ruamel.yaml # NOQA - s = dedent( - """\ + 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) diff --git a/_test/test_yamlfile.py b/_test/test_yamlfile.py index b5897f0..52cdaa5 100644 --- a/_test/test_yamlfile.py +++ b/_test/test_yamlfile.py @@ -14,12 +14,10 @@ from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NO class TestYAML: def test_backslash(self): - round_trip( - """ + round_trip(""" handlers: static_files: applications/\\1/static/\\2 - """ - ) + """) def test_omap_out(self): # ordereddict mapped to !!omap @@ -28,24 +26,20 @@ class TestYAML: x = ordereddict([('a', 1), ('b', 2)]) res = ruamel.yaml.dump(x, default_flow_style=False) - assert res == dedent( - """ + assert res == dedent(""" !!omap - a: 1 - b: 2 - """ - ) + """) def test_omap_roundtrip(self): - round_trip( - """ + round_trip(""" !!omap - a: 1 - b: 2 - c: 3 - d: 4 - """ - ) + """) @pytest.mark.skipif(sys.version_info < (2, 7), reason='collections not available') def test_dump_collections_ordereddict(self): @@ -55,13 +49,11 @@ class TestYAML: # OrderedDict mapped to !!omap x = OrderedDict([('a', 1), ('b', 2)]) res = ruamel.yaml.dump(x, Dumper=ruamel.yaml.RoundTripDumper, default_flow_style=False) - assert res == dedent( - """ + assert res == dedent(""" !!omap - a: 1 - b: 2 - """ - ) + """) @pytest.mark.skipif( sys.version_info >= (3, 0) or platform.python_implementation() != 'CPython', @@ -74,13 +66,11 @@ class TestYAML: # OrderedDict mapped to !!omap x = ordereddict([('a', 1), ('b', 2)]) res = ruamel.yaml.dump(x, Dumper=ruamel.yaml.RoundTripDumper, default_flow_style=False) - assert res == dedent( - """ + assert res == dedent(""" !!omap - a: 1 - b: 2 - """ - ) + """) def test_CommentedSet(self): from ruamel.yaml.constructor import CommentedSet @@ -100,49 +90,41 @@ class TestYAML: x = set(['a', 'b', 'c']) res = ruamel.yaml.dump(x, default_flow_style=False) - assert res == dedent( - """ + assert res == dedent(""" !!set a: null b: null c: null - """ - ) + """) # @pytest.mark.xfail # ordering is not preserved in a set def test_set_compact(self): # this format is read and also should be written by default - round_trip( - """ + round_trip(""" !!set ? a ? b ? c - """ - ) + """) def test_blank_line_after_comment(self): - round_trip( - """ + round_trip(""" # Comment with spaces after it. a: 1 - """ - ) + """) def test_blank_line_between_seq_items(self): - round_trip( - """ + round_trip(""" # Seq with spaces in between items. b: - bar - baz - """ - ) + """) @pytest.mark.skipif( platform.python_implementation() == 'Jython', reason='Jython throws RepresenterError' @@ -221,13 +203,11 @@ class TestYAML: def test_load_all_perserve_quotes(self): import ruamel.yaml # NOQA - s = dedent( - """\ + s = dedent("""\ a: 'hello' --- b: "goodbye" - """ - ) + """) data = [] for x in ruamel.yaml.round_trip_load_all(s, preserve_quotes=True): data.append(x) diff --git a/_test/test_z_check_debug_leftovers.py b/_test/test_z_check_debug_leftovers.py index 37d6970..f5be5df 100644 --- a/_test/test_z_check_debug_leftovers.py +++ b/_test/test_z_check_debug_leftovers.py @@ -10,29 +10,25 @@ class TestLeftOverDebug: # idea here is to capture round_trip_output via pytest stdout capture # if there is are any leftover debug statements they should show up def test_00(self, capsys): - s = dedent( - """ + s = dedent(""" a: 1 b: [] c: [a, 1] d: {f: 3.14, g: 42} - """ - ) + """) d = round_trip_load(s) round_trip_dump(d, sys.stdout) out, err = capsys.readouterr() assert out == s def test_01(self, capsys): - s = dedent( - """ + s = dedent(""" - 1 - [] - [a, 1] - {f: 3.14, g: 42} - - 123 - """ - ) + """) d = round_trip_load(s) round_trip_dump(d, sys.stdout) out, err = capsys.readouterr() |