summaryrefslogtreecommitdiff
path: root/_test/test_anchor.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2017-06-07 10:25:29 +0200
committerAnthon van der Neut <anthon@mnt.org>2017-06-07 10:25:29 +0200
commit560444b6855c3439812b6b482ef9956d014e74f3 (patch)
treeed2c7ed3287a79c1d662b274340632a107a399b9 /_test/test_anchor.py
parent7fcb11d7af77110fb5e3eea90cdebf108dcfe480 (diff)
downloadruamel.yaml-560444b6855c3439812b6b482ef9956d014e74f3.tar.gz
error/warning on duplicate mapping keys0.15.1
Diffstat (limited to '_test/test_anchor.py')
-rw-r--r--_test/test_anchor.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/_test/test_anchor.py b/_test/test_anchor.py
index 05c8693..fc4a881 100644
--- a/_test/test_anchor.py
+++ b/_test/test_anchor.py
@@ -11,6 +11,7 @@ import platform
from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NOQA
from ruamel.yaml.compat import PY3
from ruamel.yaml.error import ReusedAnchorWarning
+from ruamel.yaml import version_info
def load(s):
@@ -325,6 +326,31 @@ class TestMergeKeysValues:
assert len(x) == ref
+class TestDuplicateKeyThroughAnchor:
+ def test_duplicate_key_00(self):
+ from ruamel.yaml import safe_load, round_trip_load
+ from ruamel.yaml.constructor import DuplicateKeyFutureWarning, DuplicateKeyError
+ 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):
+ with pytest.warns(DuplicateKeyFutureWarning):
+ safe_load(s)
+ with pytest.warns(DuplicateKeyFutureWarning):
+ round_trip_load(s)
+ else:
+ with pytest.raises(DuplicateKeyError):
+ safe_load(s)
+ with pytest.raises(DuplicateKeyError):
+ round_trip_load(s)
+
+
class TestFullCharSetAnchors:
def test_master_of_orion(self):
# https://bitbucket.org/ruamel/yaml/issues/72/not-allowed-in-anchor-names