From 560444b6855c3439812b6b482ef9956d014e74f3 Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Wed, 7 Jun 2017 10:25:29 +0200 Subject: error/warning on duplicate mapping keys --- _test/test_anchor.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to '_test/test_anchor.py') 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 -- cgit v1.2.1