summaryrefslogtreecommitdiff
path: root/_test/test_tag.py
diff options
context:
space:
mode:
Diffstat (limited to '_test/test_tag.py')
-rw-r--r--_test/test_tag.py58
1 files changed, 35 insertions, 23 deletions
diff --git a/_test/test_tag.py b/_test/test_tag.py
index 3fd1e05..bb20621 100644
--- a/_test/test_tag.py
+++ b/_test/test_tag.py
@@ -1,20 +1,21 @@
# coding: utf-8
-import pytest # NOQA
+import pytest # type: ignore # NOQA
+from typing import Any
from roundtrip import round_trip, round_trip_load, YAML
-def register_xxx(**kw):
+def register_xxx(**kw: Any) -> None:
from ruamel import yaml
class XXX(yaml.comments.CommentedMap):
@staticmethod
- def yaml_dump(dumper, data):
+ def yaml_dump(dumper: Any, data: Any) -> Any:
return dumper.represent_mapping('!xxx', data)
@classmethod
- def yaml_load(cls, constructor, node):
+ def yaml_load(cls, constructor: Any, node: Any) -> Any:
data = cls()
yield data
constructor.construct_mapping(node, data)
@@ -24,7 +25,7 @@ def register_xxx(**kw):
class TestIndentFailures:
- def test_tag(self):
+ def test_tag(self) -> None:
round_trip("""\
!!python/object:__main__.Developer
name: Anthon
@@ -32,7 +33,7 @@ class TestIndentFailures:
language: python
""")
- def test_full_tag(self):
+ def test_full_tag(self) -> None:
round_trip("""\
!!tag:yaml.org,2002:python/object:__main__.Developer
name: Anthon
@@ -40,7 +41,7 @@ class TestIndentFailures:
language: python
""")
- def test_standard_tag(self):
+ def test_standard_tag(self) -> None:
round_trip("""\
!!tag:yaml.org,2002:python/object:map
name: Anthon
@@ -48,7 +49,7 @@ class TestIndentFailures:
language: python
""")
- def test_Y1(self):
+ def test_Y1(self) -> None:
round_trip("""\
!yyy
name: Anthon
@@ -56,7 +57,7 @@ class TestIndentFailures:
language: python
""")
- def test_Y2(self):
+ def test_Y2(self) -> None:
round_trip("""\
!!yyy
name: Anthon
@@ -66,7 +67,7 @@ class TestIndentFailures:
class TestRoundTripCustom:
- def test_X1(self):
+ def test_X1(self) -> None:
register_xxx()
round_trip("""\
!xxx
@@ -75,8 +76,8 @@ class TestRoundTripCustom:
language: python
""")
- @pytest.mark.xfail(strict=True)
- def test_X_pre_tag_comment(self):
+ @pytest.mark.xfail(strict=True) # type: ignore
+ def test_X_pre_tag_comment(self) -> None:
register_xxx()
round_trip("""\
-
@@ -87,8 +88,8 @@ class TestRoundTripCustom:
language: python
""")
- @pytest.mark.xfail(strict=True)
- def test_X_post_tag_comment(self):
+ @pytest.mark.xfail(strict=True) # type: ignore
+ def test_X_post_tag_comment(self) -> None:
register_xxx()
round_trip("""\
- !xxx
@@ -98,7 +99,7 @@ class TestRoundTripCustom:
language: python
""")
- def test_scalar_00(self):
+ def test_scalar_00(self) -> None:
# https://stackoverflow.com/a/45967047/1307905
round_trip("""\
Outputs:
@@ -110,24 +111,35 @@ class TestRoundTripCustom:
class TestIssue201:
- def test_encoded_unicode_tag(self):
+ def test_encoded_unicode_tag(self) -> None:
round_trip_load("""
s: !!python/%75nicode 'abc'
""")
class TestImplicitTaggedNodes:
- def test_scalar(self):
- round_trip("""\
- - !Scalar abcdefg
+ def test_scalar(self) -> None:
+ data = round_trip("""\
+ - !SString abcdefg
+ - !SFloat 1.0
+ - !SInt 1961
+ - !SBool true
+ - !SLit |
+ glitter in the dark near the Tanhäuser gate
""")
-
- def test_mapping(self):
+ # tagged scalers have string or string types as value
+ assert data[0].count('d') == 1
+ assert data[1].count('1') == 1
+ assert data[2].count('1') == 2
+ assert data[3].count('u') == 1
+ assert data[4].count('a') == 4
+
+ def test_mapping(self) -> None:
round_trip("""\
- !Mapping {a: 1, b: 2}
""")
- def test_sequence(self):
+ def test_sequence(self) -> None:
yaml = YAML()
yaml.brace_single_entry_mapping_in_flow_sequence = True
yaml.mapping_value_align = True
@@ -135,7 +147,7 @@ class TestImplicitTaggedNodes:
- !Sequence [a, {b: 1}, {c: {d: 3}}]
""")
- def test_sequence2(self):
+ def test_sequence2(self) -> None:
yaml = YAML()
yaml.mapping_value_align = True
yaml.round_trip("""