diff tests/test.py @ 292:6a044778371a

Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
author Franz Glasner <f.glasner@feldmann-mg.com>
date Wed, 10 Feb 2021 15:04:27 +0100
parents af371f9c016d
children a03a6797533b
line wrap: on
line diff
--- a/tests/test.py	Wed Feb 10 14:47:41 2021 +0100
+++ b/tests/test.py	Wed Feb 10 15:04:27 2021 +0100
@@ -137,6 +137,30 @@
         cfg = configmix.toml.load(os.path.join(TESTDATADIR, "conf10.toml"))
         self.__check_tree(cfg)
 
+    def test12_yaml_no_duplicate_keys(self):
+        import yaml.constructor as yc
+        with io.open(os.path.join(TESTDATADIR, "duplicate-keys.yml"), "rt",
+                     encoding="utf-8") as f:
+            cfg = configmix.yaml.safe_load(f)
+
+        with io.open(os.path.join(TESTDATADIR, "duplicate-keys.yml"), "rt",
+                     encoding="utf-8") as f:
+            self.assertRaises(yc.ConstructorError,
+                              configmix.yaml.safe_load,
+                              f, strict=True)
+
+    def test13_yaml_no_duplicate_keys_2(self):
+        import yaml.constructor as yc
+        with io.open(os.path.join(TESTDATADIR, "duplicate-keys-2.yml"), "rt",
+                     encoding="utf-8") as f:
+            cfg = configmix.yaml.safe_load(f)
+
+        with io.open(os.path.join(TESTDATADIR, "duplicate-keys-2.yml"), "rt",
+                     encoding="utf-8") as f:
+            self.assertRaises(yc.ConstructorError,
+                              configmix.yaml.safe_load,
+                              f, strict=True)
+
 
 class _T02MixinLoadAndMerge: