diff options
Diffstat (limited to '_test/test_anchor.py')
-rw-r--r-- | _test/test_anchor.py | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/_test/test_anchor.py b/_test/test_anchor.py index 3c83886..da0f1ef 100644 --- a/_test/test_anchor.py +++ b/_test/test_anchor.py @@ -4,26 +4,26 @@ testing of anchors and the aliases referring to them """ -import pytest -from textwrap import dedent +import pytest # type: ignore # NOQA import platform from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump, YAML # NOQA +from typing import Any -def load(s): +def load(s: str) -> Any: return round_trip_load(dedent(s)) -def compare(d, s): +def compare(d: Any, s: str) -> None: assert round_trip_dump(d) == dedent(s) class TestAnchorsAliases: - def test_anchor_id_renumber(self): + def test_anchor_id_renumber(self) -> None: from ruamel.yaml.serializer import Serializer - assert Serializer.ANCHOR_TEMPLATE == 'id%03d' + assert Serializer.ANCHOR_TEMPLATE == 'id{:03d}' data = load(""" a: &id002 b: 1 @@ -40,7 +40,7 @@ class TestAnchorsAliases: """, ) - def test_template_matcher(self): + def test_template_matcher(self) -> None: """test if id matches the anchor template""" from ruamel.yaml.serializer import templated_id @@ -53,13 +53,13 @@ class TestAnchorsAliases: assert not templated_id('id000') assert not templated_id('x000') - # def test_re_matcher(self): + # def test_re_matcher(self) -> None: # import re # assert re.compile('id(?!000)\\d{3,}').match('id001') # assert not re.compile('id(?!000\\d*)\\d{3,}').match('id000') # assert re.compile('id(?!000$)\\d{3,}').match('id0001') - def test_anchor_assigned(self): + def test_anchor_assigned(self) -> None: from ruamel.yaml.comments import CommentedMap data = load(""" @@ -80,7 +80,7 @@ class TestAnchorsAliases: assert e.yaml_anchor().value == 'etemplate' assert e.yaml_anchor().always_dump is False - def test_anchor_id_retained(self): + def test_anchor_id_retained(self) -> None: data = load(""" a: &id002 b: 1 @@ -105,10 +105,10 @@ class TestAnchorsAliases: """, ) - @pytest.mark.skipif( + @pytest.mark.skipif( # type: ignore platform.python_implementation() == 'Jython', reason='Jython throws RepresenterError' ) - def test_alias_before_anchor(self): + def test_alias_before_anchor(self) -> None: from ruamel.yaml.composer import ComposerError with pytest.raises(ComposerError): @@ -120,7 +120,7 @@ class TestAnchorsAliases: """) data = data - def test_anchor_on_sequence(self): + def test_anchor_on_sequence(self) -> None: # as reported by Bjorn Stabell # https://bitbucket.org/ruamel/yaml/issue/7/anchor-names-not-preserved from ruamel.yaml.comments import CommentedSeq @@ -165,7 +165,7 @@ class TestAnchorsAliases: label: center/huge """) - def test_merge_00(self): + def test_merge_00(self) -> None: data = load(self.merge_yaml) d = data[4] ok = True @@ -181,7 +181,7 @@ class TestAnchorsAliases: print('key', k, d.get(k), data[o].get(k)) assert ok - def test_merge_accessible(self): + def test_merge_accessible(self) -> None: from ruamel.yaml.comments import CommentedMap, merge_attrib data = load(""" @@ -196,11 +196,11 @@ class TestAnchorsAliases: assert isinstance(d, CommentedMap) assert hasattr(d, merge_attrib) - def test_merge_01(self): + def test_merge_01(self) -> None: data = load(self.merge_yaml) compare(data, self.merge_yaml) - def test_merge_nested(self): + def test_merge_nested(self) -> None: yaml = """ a: <<: &content @@ -212,7 +212,7 @@ class TestAnchorsAliases: """ data = round_trip(yaml) # NOQA - def test_merge_nested_with_sequence(self): + def test_merge_nested_with_sequence(self) -> None: yaml = """ a: <<: &content @@ -225,7 +225,7 @@ class TestAnchorsAliases: """ data = round_trip(yaml) # NOQA - def test_add_anchor(self): + def test_add_anchor(self) -> None: from ruamel.yaml.comments import CommentedMap data = CommentedMap() @@ -246,7 +246,7 @@ class TestAnchorsAliases: ) # this is an error in PyYAML - def test_reused_anchor(self): + def test_reused_anchor(self) -> None: from ruamel.yaml.error import ReusedAnchorWarning yaml = """ @@ -260,7 +260,7 @@ class TestAnchorsAliases: with pytest.warns(ReusedAnchorWarning): data = round_trip(yaml) # NOQA - def test_issue_130(self): + def test_issue_130(self) -> None: # issue 130 reported by Devid Fee import ruamel.yaml @@ -285,7 +285,7 @@ class TestAnchorsAliases: data = yaml.load(ys) assert data['services']['shell']['components']['server']['port'] == 8000 - def test_issue_130a(self): + def test_issue_130a(self) -> None: # issue 130 reported by Devid Fee import ruamel.yaml @@ -331,8 +331,8 @@ class TestMergeKeysValues: # in the following d always has "expanded" the merges - def test_merge_for(self): - from ruamel.yaml import YAML + def test_merge_for(self) -> None: + from ruamel.yaml import YAML # type: ignore d = YAML(typ='safe', pure=True).load(self.yaml_str) data = round_trip_load(self.yaml_str) @@ -342,8 +342,8 @@ class TestMergeKeysValues: print(count, x) assert count == len(d[2]) - def test_merge_keys(self): - from ruamel.yaml import YAML + def test_merge_keys(self) -> None: + from ruamel.yaml import YAML # type: ignore d = YAML(typ='safe', pure=True).load(self.yaml_str) data = round_trip_load(self.yaml_str) @@ -353,8 +353,8 @@ class TestMergeKeysValues: print(count, x) assert count == len(d[2]) - def test_merge_values(self): - from ruamel.yaml import YAML + def test_merge_values(self) -> None: + from ruamel.yaml import YAML # type: ignore d = YAML(typ='safe', pure=True).load(self.yaml_str) data = round_trip_load(self.yaml_str) @@ -364,8 +364,8 @@ class TestMergeKeysValues: print(count, x) assert count == len(d[2]) - def test_merge_items(self): - from ruamel.yaml import YAML + def test_merge_items(self) -> None: + from ruamel.yaml import YAML # type: ignore d = YAML(typ='safe', pure=True).load(self.yaml_str) data = round_trip_load(self.yaml_str) @@ -375,8 +375,8 @@ class TestMergeKeysValues: print(count, x) assert count == len(d[2]) - def test_len_items_delete(self): - from ruamel.yaml import YAML + def test_len_items_delete(self) -> None: + from ruamel.yaml import YAML # type: ignore d = YAML(typ='safe', pure=True).load(self.yaml_str) data = round_trip_load(self.yaml_str) @@ -395,8 +395,8 @@ class TestMergeKeysValues: ref -= 1 assert len(x) == ref - def test_issue_196_cast_of_dict(self, capsys): - from ruamel.yaml import YAML + def test_issue_196_cast_of_dict(self, capsys: Any) -> None: + from ruamel.yaml import YAML # type: ignore yaml = YAML() mapping = yaml.load("""\ @@ -433,15 +433,15 @@ class TestMergeKeysValues: assert 'a' in dict(mapping) assert 'a' in dict(mapping.items()) - def test_values_of_merged(self): - from ruamel.yaml import YAML + def test_values_of_merged(self) -> None: + from ruamel.yaml import YAML # type: ignore yaml = YAML() data = yaml.load(dedent(self.yaml_str)) assert list(data[2].values()) == [1, 6, 'x2', 'x3', 'y4'] - def test_issue_213_copy_of_merge(self): - from ruamel.yaml import YAML + def test_issue_213_copy_of_merge(self) -> None: + from ruamel.yaml import YAML # type: ignore yaml = YAML() d = yaml.load("""\ @@ -461,9 +461,9 @@ class TestMergeKeysValues: class TestDuplicateKeyThroughAnchor: - def test_duplicate_key_00(self): + def test_duplicate_key_00(self) -> None: from ruamel.yaml import version_info - from ruamel.yaml import YAML + from ruamel.yaml import YAML # type: ignore from ruamel.yaml.constructor import DuplicateKeyFutureWarning, DuplicateKeyError s = dedent("""\ @@ -486,7 +486,7 @@ class TestDuplicateKeyThroughAnchor: with pytest.raises(DuplicateKeyError): YAML(typ='rt').load(s) - def test_duplicate_key_01(self): + def test_duplicate_key_01(self) -> None: # so issue https://stackoverflow.com/a/52852106/1307905 from ruamel.yaml import version_info from ruamel.yaml.constructor import DuplicateKeyError @@ -511,7 +511,7 @@ class TestDuplicateKeyThroughAnchor: class TestFullCharSetAnchors: - def test_master_of_orion(self): + def test_master_of_orion(self) -> None: # https://bitbucket.org/ruamel/yaml/issues/72/not-allowed-in-anchor-names # submitted by Shalon Wood yaml_str = """ @@ -522,7 +522,7 @@ class TestFullCharSetAnchors: """ data = load(yaml_str) # NOQA - def test_roundtrip_00(self): + def test_roundtrip_00(self) -> None: yaml_str = """ - &dotted.words.here a: 1 @@ -531,7 +531,7 @@ class TestFullCharSetAnchors: """ data = round_trip(yaml_str) # NOQA - def test_roundtrip_01(self): + def test_roundtrip_01(self) -> None: yaml_str = """ - &dotted.words.here[a, b] - *dotted.words.here |