# HG changeset patch # User Franz Glasner # Date 1646490381 -3600 # Node ID db3ff4fbb4ce22bc4c5a187c0239fb2f5fabf83e # Parent 226aae226b8daab3926a6aed549c013b5c8addb0 More unittests concerning merging and variable interpolation diff -r 226aae226b8d -r db3ff4fbb4ce tests/test.py --- 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):