diff options
author | Anthon van der Neut <anthon@mnt.org> | 2018-08-03 22:14:57 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2018-08-03 22:14:57 +0200 |
commit | dce10fcff1de54121fb8b440b883ef5d3fe2f96a (patch) | |
tree | 072b4bd247e6f1cd95c08c7b67fea0fc96f0578e /_test/test_anchor.py | |
parent | 2966a4f215861fa05e0dc7e0cd53350766e794c6 (diff) | |
download | ruamel.yaml-dce10fcff1de54121fb8b440b883ef5d3fe2f96a.tar.gz |
Apply oitnb and mypy 0.620, then make everything work again0.15.48
Diffstat (limited to '_test/test_anchor.py')
-rw-r--r-- | _test/test_anchor.py | 132 |
1 files changed, 90 insertions, 42 deletions
diff --git a/_test/test_anchor.py b/_test/test_anchor.py index ae6469a..cb632d8 100644 --- a/_test/test_anchor.py +++ b/_test/test_anchor.py @@ -22,23 +22,30 @@ def compare(d, s): class TestAnchorsAliases: def test_anchor_id_renumber(self): 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, """ + """ + ) + compare( + data, + """ a: &id001 b: 1 c: 2 d: *id001 - """) + """, + ) def test_template_matcher(self): """test if id matches the anchor template""" from ruamel.yaml.serializer import templated_id + assert templated_id(u'id001') assert templated_id(u'id999') assert templated_id(u'id1000') @@ -56,7 +63,9 @@ class TestAnchorsAliases: def test_anchor_assigned(self): from ruamel.yaml.comments import CommentedMap - data = load(""" + + data = load( + """ a: &id002 b: 1 c: 2 @@ -65,7 +74,8 @@ 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 @@ -75,7 +85,8 @@ 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 @@ -84,8 +95,11 @@ class TestAnchorsAliases: b: 1 c: 2 f: *etemplate - """) - compare(data, """ + """ + ) + compare( + data, + """ a: &id001 b: 1 c: 2 @@ -94,26 +108,33 @@ class TestAnchorsAliases: b: 1 c: 2 f: *etemplate - """) + """, + ) - @pytest.mark.skipif(platform.python_implementation() == 'Jython', - reason="Jython throws RepresenterError") + @pytest.mark.skipif( + platform.python_implementation() == 'Jython', reason='Jython throws RepresenterError' + ) def test_alias_before_anchor(self): 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): # as reported by Bjorn Stabell # 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 @@ -123,13 +144,15 @@ 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} @@ -151,7 +174,8 @@ class TestAnchorsAliases: - <<: [*BIG, *LEFT, *SMALL] x: 1 label: center/huge - """) + """ + ) def test_merge_00(self): data = load(self.merge_yaml) @@ -171,14 +195,17 @@ 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) @@ -188,7 +215,7 @@ class TestAnchorsAliases: compare(data, self.merge_yaml) def test_merge_nested(self): - yaml = ''' + yaml = """ a: <<: &content 1: plugh @@ -196,11 +223,11 @@ class TestAnchorsAliases: 0: xyzzy b: <<: *content - ''' + """ data = round_trip(yaml) # NOQA def test_merge_nested_with_sequence(self): - yaml = ''' + yaml = """ a: <<: &content <<: &y2 @@ -209,11 +236,12 @@ class TestAnchorsAliases: 0: xyzzy b: <<: [*content, *y2] - ''' + """ data = round_trip(yaml) # NOQA def test_add_anchor(self): from ruamel.yaml.comments import CommentedMap + data = CommentedMap() data_a = CommentedMap() data['a'] = data_a @@ -221,31 +249,37 @@ class TestAnchorsAliases: data['b'] = 2 data.yaml_set_anchor('klm', always_dump=True) data['a'].yaml_set_anchor('xyz', always_dump=True) - compare(data, """ + compare( + data, + """ &klm a: &xyz c: 3 b: 2 - """) + """, + ) # this is an error in PyYAML def test_reused_anchor(self): from ruamel.yaml.error import ReusedAnchorWarning - yaml = ''' + + yaml = """ - &a x: 1 - <<: *a - &a x: 2 - <<: *a - ''' + """ with pytest.warns(ReusedAnchorWarning): data = round_trip(yaml) # NOQA def test_issue_130(self): # issue 130 reported by Devid Fee import ruamel.yaml - ys = dedent("""\ + + ys = dedent( + """\ components: server: &server_component type: spark.server:ServerComponent @@ -261,14 +295,17 @@ class TestAnchorsAliases: <<: *shell_component components: server: {<<: *server_service} - """) + """ + ) data = ruamel.yaml.safe_load(ys) assert data['services']['shell']['components']['server']['port'] == 8000 def test_issue_130a(self): # issue 130 reported by Devid Fee import ruamel.yaml - ys = dedent("""\ + + ys = dedent( + """\ components: server: &server_component type: spark.server:ServerComponent @@ -285,14 +322,16 @@ 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 @@ -306,12 +345,14 @@ class TestMergeKeysValues: <<: *mx m: 6 <<: *my - """) + """ + ) # in the following d always has "expanded" the merges def test_merge_for(self): from ruamel.yaml import safe_load + d = safe_load(self.yaml_str) data = round_trip_load(self.yaml_str) count = 0 @@ -322,6 +363,7 @@ class TestMergeKeysValues: def test_merge_keys(self): from ruamel.yaml import safe_load + d = safe_load(self.yaml_str) data = round_trip_load(self.yaml_str) count = 0 @@ -332,6 +374,7 @@ class TestMergeKeysValues: def test_merge_values(self): from ruamel.yaml import safe_load + d = safe_load(self.yaml_str) data = round_trip_load(self.yaml_str) count = 0 @@ -342,6 +385,7 @@ class TestMergeKeysValues: def test_merge_items(self): from ruamel.yaml import safe_load + d = safe_load(self.yaml_str) data = round_trip_load(self.yaml_str) count = 0 @@ -353,6 +397,7 @@ class TestMergeKeysValues: def test_len_items_delete(self): from ruamel.yaml import safe_load from ruamel.yaml.compat import PY3 + d = safe_load(self.yaml_str) data = round_trip_load(self.yaml_str) x = data[2].items() @@ -377,13 +422,16 @@ class TestDuplicateKeyThroughAnchor: from ruamel.yaml import version_info 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): @@ -402,27 +450,27 @@ class TestFullCharSetAnchors: def test_master_of_orion(self): # https://bitbucket.org/ruamel/yaml/issues/72/not-allowed-in-anchor-names # submitted by Shalon Wood - yaml_str = ''' + yaml_str = """ - collection: &Backend.Civilizations.RacialPerk items: - key: perk_population_growth_modifier - *Backend.Civilizations.RacialPerk - ''' + """ data = load(yaml_str) # NOQA def test_roundtrip_00(self): - yaml_str = ''' + yaml_str = """ - &dotted.words.here a: 1 b: 2 - *dotted.words.here - ''' + """ data = round_trip(yaml_str) # NOQA def test_roundtrip_01(self): - yaml_str = ''' + yaml_str = """ - &dotted.words.here[a, b] - *dotted.words.here - ''' + """ data = load(yaml_str) # NOQA compare(data, yaml_str.replace('[', ' [')) # an extra space is inserted |