Mercurial > hgrepos > Python > libs > ConfigMix
changeset 642:db3ff4fbb4ce
More unittests concerning merging and variable interpolation
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 05 Mar 2022 15:26:21 +0100 |
| parents | 226aae226b8d |
| children | 078ffa821af4 |
| files | tests/test.py |
| diffstat | 1 files changed, 83 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test.py Sat Mar 05 14:31:30 2022 +0100 +++ b/tests/test.py Sat Mar 05 15:26:21 2022 +0100 @@ -2014,7 +2014,7 @@ self.assertEqual(u"1010", x) # caching should have no effect y = getattr(cfg, self.interpolate_meth)(u"{{intl.cache.items|Empty}}{{intl.cache.items}}") - self.assertEqual(u"1010", y) + self.assertEqual(u"1010", y) def test_interpolate_wrong_syntax(self): cfg = configmix.load() @@ -2048,6 +2048,88 @@ y = getattr(cfg, self.interpolate_meth)(u"no-interpolation-here") self.assertEqual(u"no-interpolation-here", y) + def test_single_load_removes_DEL_VALUE(self): + cfg = configmix.load(os.path.join(TESTDATADIR, "conf20.yml")) + self.assertRaises( + KeyError, + cfg.getvar, + u("not-deleted")) + + def test_single_safeload_removes_DEL_VALUE(self): + cfg = configmix.safe_load(os.path.join(TESTDATADIR, "conf20.yml")) + self.assertRaises( + KeyError, + cfg.getvar, + u("not-deleted")) + + def test_never_expanding_lone_DEL_VALUE(self): + cfg = { + u("key1"): u("{{::DEL::}}"), + u("subkey2"): { + u("key3"): u("{{::DEL::}}") + } + } + cfg = configmix.config.Configuration(cfg) + print(repr(cfg)) + self.assertEqual(u("{{::DEL::}}"), cfg.getvar_s(u("key1"))) + self.assertEqual(u("{{::DEL::}}"), cfg.getvar_s(u("subkey2.key3"))) + + def test_merge_does_never_expand(self): + cfg1 = configmix.load(os.path.join(TESTDATADIR, "conf20.yml")) + self.assertEqual(u("{{appdir}}/locale"), cfg1.getvar(u("intl.localedir"))) + self.assertRaises( + KeyError, + cfg1.getvar_s, + u("intl.localedir")) + + cfg2 = { + u("process"): u("{{::DEL::}}"), + u("intl"): { + u("localedir"): u("{{appdir}}/other-locale"), + u("cache"): u("{{::DEL::}}") + } + } + cfg = configmix.merge(configmix.config.Configuration(cfg2), cfg1) + self.assertEqual( + u("{{appdir}}/other-locale"), + cfg.getvar(u("intl.localedir"))) + self.assertRaises( + KeyError, + cfg.getvar, + u("process")) + self.assertRaises( + KeyError, + cfg.getvar, + u("intl.cache")) + + def test_safemerge_does_never_expand(self): + cfg1 = configmix.safe_load(os.path.join(TESTDATADIR, "conf20.yml")) + self.assertEqual(u("{{appdir}}/locale"), cfg1.getvar(u("intl.localedir"))) + self.assertRaises( + KeyError, + cfg1.getvar_s, + u("intl.localedir")) + + cfg2 = { + u("process"): u("{{::DEL::}}"), + u("intl"): { + u("localedir"): u("{{appdir}}/other-locale"), + u("cache"): u("{{::DEL::}}") + } + } + cfg = configmix.safe_merge(configmix.config.Configuration(cfg2), cfg1) + self.assertEqual( + u("{{appdir}}/other-locale"), + cfg.getvar(u("intl.localedir"))) + self.assertRaises( + KeyError, + cfg.getvar, + u("process")) + self.assertRaises( + KeyError, + cfg.getvar, + u("intl.cache")) + class T09Parser(_TParserMixin, unittest.TestCase):
