summaryrefslogtreecommitdiff
path: root/_test/test_add_xxx.py
diff options
context:
space:
mode:
Diffstat (limited to '_test/test_add_xxx.py')
-rw-r--r--_test/test_add_xxx.py55
1 files changed, 28 insertions, 27 deletions
diff --git a/_test/test_add_xxx.py b/_test/test_add_xxx.py
index 8beac65..5f12ece 100644
--- a/_test/test_add_xxx.py
+++ b/_test/test_add_xxx.py
@@ -1,31 +1,32 @@
# coding: utf-8
import re
-import pytest # NOQA
+import pytest # type: ignore # NOQA
from roundtrip import dedent, round_trip_dump # NOQA
+from typing import Any
# from PyYAML docs
-class Dice(tuple):
- def __new__(cls, a, b):
+class Dice(tuple): # type: ignore
+ def __new__(cls, a: int, b: int) -> "Dice":
return tuple.__new__(cls, [a, b])
- def __repr__(self):
+ def __repr__(self) -> str:
return 'Dice(%s,%s)' % self
-def dice_constructor(loader, node):
+def dice_constructor(loader: Any, node: Any) -> Dice:
value = loader.construct_scalar(node)
a, b = map(int, value.split('d'))
return Dice(a, b)
-def dice_representer(dumper, data):
+def dice_representer(dumper: Any, data: Any) -> Any:
return dumper.represent_scalar('!dice', '{}d{}'.format(*data))
-def test_dice_constructor():
+def test_dice_constructor() -> None:
import ruamel.yaml # NOQA
yaml = ruamel.yaml.YAML(typ='unsafe', pure=True)
@@ -34,7 +35,7 @@ def test_dice_constructor():
assert str(data) == "{'initial hit points': Dice(8,4)}"
-def test_dice_constructor_with_loader():
+def test_dice_constructor_with_loader() -> None:
import ruamel.yaml # NOQA
yaml = ruamel.yaml.YAML(typ='unsafe', pure=True)
@@ -43,7 +44,7 @@ def test_dice_constructor_with_loader():
assert str(data) == "{'initial hit points': Dice(8,4)}"
-def test_dice_representer():
+def test_dice_representer() -> None:
import ruamel.yaml # NOQA
yaml = ruamel.yaml.YAML(typ='unsafe', pure=True)
@@ -55,7 +56,7 @@ def test_dice_representer():
assert buf.getvalue() == 'gold: !dice 10d6\n'
-def test_dice_implicit_resolver():
+def test_dice_implicit_resolver() -> None:
import ruamel.yaml # NOQA
yaml = ruamel.yaml.YAML(typ='unsafe', pure=True)
@@ -68,26 +69,26 @@ def test_dice_implicit_resolver():
assert yaml.load('damage: 5d10') == dict(damage=Dice(5, 10))
-class Obj1(dict):
- def __init__(self, suffix):
+class Obj1(dict): # type: ignore
+ def __init__(self, suffix: Any) -> None:
self._suffix = suffix
self._node = None
- def add_node(self, n):
+ def add_node(self, n: Any) -> None:
self._node = n
- def __repr__(self):
+ def __repr__(self) -> str:
return 'Obj1(%s->%s)' % (self._suffix, self.items())
- def dump(self):
+ def dump(self) -> str:
return repr(self._node)
-class YAMLObj1(object):
+class YAMLObj1:
yaml_tag = '!obj:'
@classmethod
- def from_yaml(cls, loader, suffix, node):
+ def from_yaml(cls, loader: Any, suffix: Any, node: Any) -> Any:
import ruamel.yaml # NOQA
obj1 = Obj1(suffix)
@@ -98,11 +99,11 @@ class YAMLObj1(object):
return obj1
@classmethod
- def to_yaml(cls, dumper, data):
+ def to_yaml(cls, dumper: Any, data: Any) -> Any:
return dumper.represent_scalar(cls.yaml_tag + data._suffix, data.dump())
-def test_yaml_obj():
+def test_yaml_obj() -> None:
import ruamel.yaml # NOQA
yaml = ruamel.yaml.YAML(typ='unsafe', pure=True)
@@ -115,7 +116,7 @@ def test_yaml_obj():
assert buf.getvalue() == """!obj:x.2 "{'a': 1}"\n"""
-def test_yaml_obj_with_loader_and_dumper():
+def test_yaml_obj_with_loader_and_dumper() -> None:
import ruamel.yaml # NOQA
yaml = ruamel.yaml.YAML(typ='unsafe', pure=True)
@@ -137,25 +138,25 @@ def test_yaml_obj_with_loader_and_dumper():
# Issue 127 reported by Tommy Wang
-def test_issue_127():
+def test_issue_127() -> None:
import ruamel.yaml # NOQA
class Ref(ruamel.yaml.YAMLObject):
- yaml_constructor = ruamel.yaml.RoundTripConstructor
- yaml_representer = ruamel.yaml.RoundTripRepresenter
+ yaml_constructor = ruamel.yaml.RoundTripConstructor # type: ignore
+ yaml_representer = ruamel.yaml.RoundTripRepresenter # type: ignore
yaml_tag = '!Ref'
- def __init__(self, logical_id):
+ def __init__(self, logical_id: Any) -> None:
self.logical_id = logical_id
@classmethod
- def from_yaml(cls, loader, node):
+ def from_yaml(cls, loader: Any, node: Any) -> Any:
return cls(loader.construct_scalar(node))
@classmethod
- def to_yaml(cls, dumper, data):
+ def to_yaml(cls, dumper: Any, data: Any) -> Any:
if isinstance(data.logical_id, ruamel.yaml.scalarstring.ScalarString):
- style = data.logical_id.style # ruamel.yaml>0.15.8
+ style = data.logical_id.style # type: ignore # ruamel.yaml>0.15.8
else:
style = None
return dumper.represent_scalar(cls.yaml_tag, data.logical_id, style=style)