Mercurial > hgrepos > Python > libs > ConfigMix
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 291:edf5cc1ffd26 | 292:6a044778371a |
|---|---|
| 134 self.__check_tree(cfg) | 134 self.__check_tree(cfg) |
| 135 | 135 |
| 136 def test11_toml_tree(self): | 136 def test11_toml_tree(self): |
| 137 cfg = configmix.toml.load(os.path.join(TESTDATADIR, "conf10.toml")) | 137 cfg = configmix.toml.load(os.path.join(TESTDATADIR, "conf10.toml")) |
| 138 self.__check_tree(cfg) | 138 self.__check_tree(cfg) |
| 139 | |
| 140 def test12_yaml_no_duplicate_keys(self): | |
| 141 import yaml.constructor as yc | |
| 142 with io.open(os.path.join(TESTDATADIR, "duplicate-keys.yml"), "rt", | |
| 143 encoding="utf-8") as f: | |
| 144 cfg = configmix.yaml.safe_load(f) | |
| 145 | |
| 146 with io.open(os.path.join(TESTDATADIR, "duplicate-keys.yml"), "rt", | |
| 147 encoding="utf-8") as f: | |
| 148 self.assertRaises(yc.ConstructorError, | |
| 149 configmix.yaml.safe_load, | |
| 150 f, strict=True) | |
| 151 | |
| 152 def test13_yaml_no_duplicate_keys_2(self): | |
| 153 import yaml.constructor as yc | |
| 154 with io.open(os.path.join(TESTDATADIR, "duplicate-keys-2.yml"), "rt", | |
| 155 encoding="utf-8") as f: | |
| 156 cfg = configmix.yaml.safe_load(f) | |
| 157 | |
| 158 with io.open(os.path.join(TESTDATADIR, "duplicate-keys-2.yml"), "rt", | |
| 159 encoding="utf-8") as f: | |
| 160 self.assertRaises(yc.ConstructorError, | |
| 161 configmix.yaml.safe_load, | |
| 162 f, strict=True) | |
| 139 | 163 |
| 140 | 164 |
| 141 class _T02MixinLoadAndMerge: | 165 class _T02MixinLoadAndMerge: |
| 142 | 166 |
| 143 def test01_load(self): | 167 def test01_load(self): |
