summaryrefslogtreecommitdiff
path: root/_test
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
parent7fcb11d7af77110fb5e3eea90cdebf108dcfe480 (diff)
downloadruamel.yaml-560444b6855c3439812b6b482ef9956d014e74f3.tar.gz
error/warning on duplicate mapping keys0.15.1
Diffstat (limited to '_test')
-rw-r--r--_test/data/duplicate-key.former-loader-error.code1
-rw-r--r--_test/data/duplicate-key.former-loader-error.data3
-rw-r--r--_test/data/duplicate-mapping-key.former-loader-error.code1
-rw-r--r--_test/data/duplicate-mapping-key.former-loader-error.data6
-rw-r--r--_test/data/duplicate-value-key.former-loader-error.code1
-rw-r--r--_test/data/duplicate-value-key.former-loader-error.data4
-rw-r--r--_test/test_anchor.py26
-rw-r--r--_test/test_api_change.py28
8 files changed, 54 insertions, 16 deletions
diff --git a/_test/data/duplicate-key.former-loader-error.code b/_test/data/duplicate-key.former-loader-error.code
deleted file mode 100644
index cb73906..0000000
--- a/_test/data/duplicate-key.former-loader-error.code
+++ /dev/null
@@ -1 +0,0 @@
-{ 'foo': 'baz' }
diff --git a/_test/data/duplicate-key.former-loader-error.data b/_test/data/duplicate-key.former-loader-error.data
deleted file mode 100644
index 84deb8f..0000000
--- a/_test/data/duplicate-key.former-loader-error.data
+++ /dev/null
@@ -1,3 +0,0 @@
----
-foo: bar
-foo: baz
diff --git a/_test/data/duplicate-mapping-key.former-loader-error.code b/_test/data/duplicate-mapping-key.former-loader-error.code
deleted file mode 100644
index 17a6285..0000000
--- a/_test/data/duplicate-mapping-key.former-loader-error.code
+++ /dev/null
@@ -1 +0,0 @@
-{ 'foo': { 'baz': 'bat', 'foo': 'duplicate key' } }
diff --git a/_test/data/duplicate-mapping-key.former-loader-error.data b/_test/data/duplicate-mapping-key.former-loader-error.data
deleted file mode 100644
index 7e7b4d1..0000000
--- a/_test/data/duplicate-mapping-key.former-loader-error.data
+++ /dev/null
@@ -1,6 +0,0 @@
----
-&anchor foo:
- foo: bar
- *anchor: duplicate key
- baz: bat
- *anchor: duplicate key
diff --git a/_test/data/duplicate-value-key.former-loader-error.code b/_test/data/duplicate-value-key.former-loader-error.code
deleted file mode 100644
index 12f48c1..0000000
--- a/_test/data/duplicate-value-key.former-loader-error.code
+++ /dev/null
@@ -1 +0,0 @@
-{ 'foo': 'bar', '=': 2 }
diff --git a/_test/data/duplicate-value-key.former-loader-error.data b/_test/data/duplicate-value-key.former-loader-error.data
deleted file mode 100644
index b34a1d6..0000000
--- a/_test/data/duplicate-value-key.former-loader-error.data
+++ /dev/null
@@ -1,4 +0,0 @@
----
-=: 1
-foo: bar
-=: 2
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
diff --git a/_test/test_api_change.py b/_test/test_api_change.py
new file mode 100644
index 0000000..10997f4
--- /dev/null
+++ b/_test/test_api_change.py
@@ -0,0 +1,28 @@
+# coding: utf-8
+
+"""
+testing of anchors and the aliases referring to them
+"""
+
+import pytest
+from ruamel.yaml import YAML
+from ruamel.yaml.constructor import DuplicateKeyError
+
+
+class TestNewAPI:
+ def test_duplicate_keys_00(self):
+ from ruamel.yaml.constructor import DuplicateKeyError
+ yaml = YAML()
+ with pytest.raises(DuplicateKeyError):
+ yaml.load('{a: 1, a: 2}')
+
+ def test_duplicate_keys_01(self):
+ yaml = YAML(typ='safe', pure=True)
+ with pytest.raises(DuplicateKeyError):
+ yaml.load('{a: 1, a: 2}')
+
+ # @pytest.mark.xfail(strict=True)
+ def test_duplicate_keys_02(self):
+ yaml = YAML(typ='safe')
+ with pytest.raises(DuplicateKeyError):
+ yaml.load('{a: 1, a: 2}')