summaryrefslogtreecommitdiff
path: root/_test/test_comment_manipulation.py
diff options
context:
space:
mode:
Diffstat (limited to '_test/test_comment_manipulation.py')
-rw-r--r--_test/test_comment_manipulation.py71
1 files changed, 36 insertions, 35 deletions
diff --git a/_test/test_comment_manipulation.py b/_test/test_comment_manipulation.py
index 6d706f2..979b386 100644
--- a/_test/test_comment_manipulation.py
+++ b/_test/test_comment_manipulation.py
@@ -1,28 +1,29 @@
# coding: utf-8
-import pytest # NOQA
+import pytest # type: ignore # NOQA
from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NOQA
+from typing import Any
-def load(s):
+def load(s: str) -> Any:
return round_trip_load(dedent(s))
-def compare(data, s, **kw):
+def compare(data: Any, s: str, **kw: Any) -> None:
assert round_trip_dump(data, **kw) == dedent(s)
-def compare_eol(data, s):
+def compare_eol(data: Any, s: str) -> None:
assert 'EOL' in s
ds = dedent(s).replace('EOL', '').replace('\n', '|\n')
- assert round_trip_dump(data).replace('\n', '|\n') == ds
+ assert round_trip_dump(data).replace('\n', '|\n') == ds # type: ignore
class TestCommentsManipulation:
# list
- def test_seq_set_comment_on_existing_explicit_column(self):
+ def test_seq_set_comment_on_existing_explicit_column(self) -> None:
data = load("""
- a # comment 1
- b
@@ -36,7 +37,7 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def test_seq_overwrite_comment_on_existing_explicit_column(self):
+ def test_seq_overwrite_comment_on_existing_explicit_column(self) -> None:
data = load("""
- a # comment 1
- b
@@ -50,7 +51,7 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def test_seq_first_comment_explicit_column(self):
+ def test_seq_first_comment_explicit_column(self) -> None:
data = load("""
- a
- b
@@ -64,7 +65,7 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def test_seq_set_comment_on_existing_column_prev(self):
+ def test_seq_set_comment_on_existing_column_prev(self) -> None:
data = load("""
- a # comment 1
- b
@@ -80,14 +81,14 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def test_seq_set_comment_on_existing_column_next(self):
+ def test_seq_set_comment_on_existing_column_next(self) -> None:
data = load("""
- a # comment 1
- b
- c
- d # comment 3
""")
- print(data._yaml_comment)
+ print(data.ca)
# print(type(data._yaml_comment._items[0][0].start_mark))
# ruamel.yaml.error.Mark
# print(type(data._yaml_comment._items[0][0].start_mark))
@@ -100,7 +101,7 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def test_seq_set_comment_on_existing_column_further_away(self):
+ def test_seq_set_comment_on_existing_column_further_away(self) -> None:
"""
no comment line before or after, take the latest before
the new position
@@ -113,7 +114,7 @@ class TestCommentsManipulation:
- e
- f # comment 3
""")
- print(data._yaml_comment)
+ print(data.ca)
# print(type(data._yaml_comment._items[0][0].start_mark))
# ruamel.yaml.error.Mark
# print(type(data._yaml_comment._items[0][0].start_mark))
@@ -128,7 +129,7 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def test_seq_set_comment_on_existing_explicit_column_with_hash(self):
+ def test_seq_set_comment_on_existing_explicit_column_with_hash(self) -> None:
data = load("""
- a # comment 1
- b
@@ -144,7 +145,7 @@ class TestCommentsManipulation:
# dict
- def test_dict_set_comment_on_existing_explicit_column(self):
+ def test_dict_set_comment_on_existing_explicit_column(self) -> None:
data = load("""
a: 1 # comment 1
b: 2
@@ -162,7 +163,7 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def test_dict_overwrite_comment_on_existing_explicit_column(self):
+ def test_dict_overwrite_comment_on_existing_explicit_column(self) -> None:
data = load("""
a: 1 # comment 1
b: 2
@@ -180,7 +181,7 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def test_map_set_comment_on_existing_column_prev(self):
+ def test_map_set_comment_on_existing_column_prev(self) -> None:
data = load("""
a: 1 # comment 1
b: 2
@@ -198,7 +199,7 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def test_map_set_comment_on_existing_column_next(self):
+ def test_map_set_comment_on_existing_column_next(self) -> None:
data = load("""
a: 1 # comment 1
b: 2
@@ -216,7 +217,7 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def test_map_set_comment_on_existing_column_further_away(self):
+ def test_map_set_comment_on_existing_column_further_away(self) -> None:
"""
no comment line before or after, take the latest before
the new position
@@ -239,7 +240,7 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def test_before_top_map_rt(self):
+ def test_before_top_map_rt(self) -> None:
data = load("""
a: 1
b: 2
@@ -253,7 +254,7 @@ class TestCommentsManipulation:
"""
compare(data, exp.format(comment='#'))
- def test_before_top_map_replace(self):
+ def test_before_top_map_replace(self) -> None:
data = load("""
# abc
# def
@@ -269,7 +270,7 @@ class TestCommentsManipulation:
"""
compare(data, exp.format(comment='#'))
- def test_before_top_map_from_scratch(self):
+ def test_before_top_map_from_scratch(self) -> None:
from ruamel.yaml.comments import CommentedMap
data = CommentedMap()
@@ -286,7 +287,7 @@ class TestCommentsManipulation:
"""
compare(data, exp.format(comment='#'))
- def test_before_top_seq_rt(self):
+ def test_before_top_seq_rt(self) -> None:
data = load("""
- a
- b
@@ -301,7 +302,7 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def test_before_top_seq_rt_replace(self):
+ def test_before_top_seq_rt_replace(self) -> None:
s = """
# this
# that
@@ -319,7 +320,7 @@ class TestCommentsManipulation:
"""
compare(data, exp.format(comment='#'))
- def test_before_top_seq_from_scratch(self):
+ def test_before_top_seq_from_scratch(self) -> None:
from ruamel.yaml.comments import CommentedSeq
data = CommentedSeq()
@@ -336,7 +337,7 @@ class TestCommentsManipulation:
compare(data, exp.format(comment='#'))
# nested variants
- def test_before_nested_map_rt(self):
+ def test_before_nested_map_rt(self) -> None:
data = load("""
a: 1
b:
@@ -354,7 +355,7 @@ class TestCommentsManipulation:
"""
compare(data, exp.format(comment='#'))
- def test_before_nested_map_rt_indent(self):
+ def test_before_nested_map_rt_indent(self) -> None:
data = load("""
a: 1
b:
@@ -373,7 +374,7 @@ class TestCommentsManipulation:
compare(data, exp.format(comment='#'))
print(data['b'].ca)
- def test_before_nested_map_from_scratch(self):
+ def test_before_nested_map_from_scratch(self) -> None:
from ruamel.yaml.comments import CommentedMap
data = CommentedMap()
@@ -393,7 +394,7 @@ class TestCommentsManipulation:
"""
compare(data, exp.format(comment='#'))
- def test_before_nested_seq_from_scratch(self):
+ def test_before_nested_seq_from_scratch(self) -> None:
from ruamel.yaml.comments import CommentedMap, CommentedSeq
data = CommentedMap()
@@ -413,7 +414,7 @@ class TestCommentsManipulation:
"""
compare(data, exp.format(comment='#'))
- def test_before_nested_seq_from_scratch_block_seq_indent(self):
+ def test_before_nested_seq_from_scratch_block_seq_indent(self) -> None:
from ruamel.yaml.comments import CommentedMap, CommentedSeq
data = CommentedMap()
@@ -433,7 +434,7 @@ class TestCommentsManipulation:
"""
compare(data, exp.format(comment='#'), indent=4, block_seq_indent=2)
- def test_map_set_comment_before_and_after_non_first_key_00(self):
+ def test_map_set_comment_before_and_after_non_first_key_00(self) -> None:
# http://stackoverflow.com/a/40705671/1307905
data = load("""
xyz:
@@ -462,7 +463,7 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def Xtest_map_set_comment_before_and_after_non_first_key_01(self):
+ def Xtest_map_set_comment_before_and_after_non_first_key_01(self) -> None:
data = load("""
xyz:
a: 1 # comment 1
@@ -494,7 +495,7 @@ class TestCommentsManipulation:
# EOL is no longer necessary
# fixed together with issue # 216
- def test_map_set_comment_before_and_after_non_first_key_01(self):
+ def test_map_set_comment_before_and_after_non_first_key_01(self) -> None:
data = load("""
xyz:
a: 1 # comment 1
@@ -523,7 +524,7 @@ class TestCommentsManipulation:
"""
compare(data, exp)
- def Xtest_map_set_comment_before_and_after_non_first_key_02(self):
+ def Xtest_map_set_comment_before_and_after_non_first_key_02(self) -> None:
data = load("""
xyz:
a: 1 # comment 1
@@ -555,7 +556,7 @@ class TestCommentsManipulation:
"""
compare_eol(data, exp)
- def test_map_set_comment_before_and_after_non_first_key_02(self):
+ def test_map_set_comment_before_and_after_non_first_key_02(self) -> None:
data = load("""
xyz:
a: 1 # comment 1