Mercurial > hgrepos > Python > libs > ConfigMix
comparison tests/test.py @ 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 | 2426fa273a29 |
| children | df58983f28a2 |
comparison
equal
deleted
inserted
replaced
| 641:226aae226b8d | 642:db3ff4fbb4ce |
|---|---|
| 2012 os.path.join(TESTDATADIR, "conf24.toml")) | 2012 os.path.join(TESTDATADIR, "conf24.toml")) |
| 2013 x = getattr(cfg, self.interpolate_meth)(u"{{intl.cache.items|Empty}}{{intl.cache.items}}") | 2013 x = getattr(cfg, self.interpolate_meth)(u"{{intl.cache.items|Empty}}{{intl.cache.items}}") |
| 2014 self.assertEqual(u"1010", x) | 2014 self.assertEqual(u"1010", x) |
| 2015 # caching should have no effect | 2015 # caching should have no effect |
| 2016 y = getattr(cfg, self.interpolate_meth)(u"{{intl.cache.items|Empty}}{{intl.cache.items}}") | 2016 y = getattr(cfg, self.interpolate_meth)(u"{{intl.cache.items|Empty}}{{intl.cache.items}}") |
| 2017 self.assertEqual(u"1010", y) | 2017 self.assertEqual(u"1010", y) |
| 2018 | 2018 |
| 2019 def test_interpolate_wrong_syntax(self): | 2019 def test_interpolate_wrong_syntax(self): |
| 2020 cfg = configmix.load() | 2020 cfg = configmix.load() |
| 2021 x1 = getattr(cfg, self.interpolate_meth)(u"{{the-variable}") | 2021 x1 = getattr(cfg, self.interpolate_meth)(u"{{the-variable}") |
| 2022 self.assertEqual(u"{{the-variable}", x1) | 2022 self.assertEqual(u"{{the-variable}", x1) |
| 2046 self.assertEqual(u"no-interpolation-here", x) | 2046 self.assertEqual(u"no-interpolation-here", x) |
| 2047 # caching should have no effect | 2047 # caching should have no effect |
| 2048 y = getattr(cfg, self.interpolate_meth)(u"no-interpolation-here") | 2048 y = getattr(cfg, self.interpolate_meth)(u"no-interpolation-here") |
| 2049 self.assertEqual(u"no-interpolation-here", y) | 2049 self.assertEqual(u"no-interpolation-here", y) |
| 2050 | 2050 |
| 2051 def test_single_load_removes_DEL_VALUE(self): | |
| 2052 cfg = configmix.load(os.path.join(TESTDATADIR, "conf20.yml")) | |
| 2053 self.assertRaises( | |
| 2054 KeyError, | |
| 2055 cfg.getvar, | |
| 2056 u("not-deleted")) | |
| 2057 | |
| 2058 def test_single_safeload_removes_DEL_VALUE(self): | |
| 2059 cfg = configmix.safe_load(os.path.join(TESTDATADIR, "conf20.yml")) | |
| 2060 self.assertRaises( | |
| 2061 KeyError, | |
| 2062 cfg.getvar, | |
| 2063 u("not-deleted")) | |
| 2064 | |
| 2065 def test_never_expanding_lone_DEL_VALUE(self): | |
| 2066 cfg = { | |
| 2067 u("key1"): u("{{::DEL::}}"), | |
| 2068 u("subkey2"): { | |
| 2069 u("key3"): u("{{::DEL::}}") | |
| 2070 } | |
| 2071 } | |
| 2072 cfg = configmix.config.Configuration(cfg) | |
| 2073 print(repr(cfg)) | |
| 2074 self.assertEqual(u("{{::DEL::}}"), cfg.getvar_s(u("key1"))) | |
| 2075 self.assertEqual(u("{{::DEL::}}"), cfg.getvar_s(u("subkey2.key3"))) | |
| 2076 | |
| 2077 def test_merge_does_never_expand(self): | |
| 2078 cfg1 = configmix.load(os.path.join(TESTDATADIR, "conf20.yml")) | |
| 2079 self.assertEqual(u("{{appdir}}/locale"), cfg1.getvar(u("intl.localedir"))) | |
| 2080 self.assertRaises( | |
| 2081 KeyError, | |
| 2082 cfg1.getvar_s, | |
| 2083 u("intl.localedir")) | |
| 2084 | |
| 2085 cfg2 = { | |
| 2086 u("process"): u("{{::DEL::}}"), | |
| 2087 u("intl"): { | |
| 2088 u("localedir"): u("{{appdir}}/other-locale"), | |
| 2089 u("cache"): u("{{::DEL::}}") | |
| 2090 } | |
| 2091 } | |
| 2092 cfg = configmix.merge(configmix.config.Configuration(cfg2), cfg1) | |
| 2093 self.assertEqual( | |
| 2094 u("{{appdir}}/other-locale"), | |
| 2095 cfg.getvar(u("intl.localedir"))) | |
| 2096 self.assertRaises( | |
| 2097 KeyError, | |
| 2098 cfg.getvar, | |
| 2099 u("process")) | |
| 2100 self.assertRaises( | |
| 2101 KeyError, | |
| 2102 cfg.getvar, | |
| 2103 u("intl.cache")) | |
| 2104 | |
| 2105 def test_safemerge_does_never_expand(self): | |
| 2106 cfg1 = configmix.safe_load(os.path.join(TESTDATADIR, "conf20.yml")) | |
| 2107 self.assertEqual(u("{{appdir}}/locale"), cfg1.getvar(u("intl.localedir"))) | |
| 2108 self.assertRaises( | |
| 2109 KeyError, | |
| 2110 cfg1.getvar_s, | |
| 2111 u("intl.localedir")) | |
| 2112 | |
| 2113 cfg2 = { | |
| 2114 u("process"): u("{{::DEL::}}"), | |
| 2115 u("intl"): { | |
| 2116 u("localedir"): u("{{appdir}}/other-locale"), | |
| 2117 u("cache"): u("{{::DEL::}}") | |
| 2118 } | |
| 2119 } | |
| 2120 cfg = configmix.safe_merge(configmix.config.Configuration(cfg2), cfg1) | |
| 2121 self.assertEqual( | |
| 2122 u("{{appdir}}/other-locale"), | |
| 2123 cfg.getvar(u("intl.localedir"))) | |
| 2124 self.assertRaises( | |
| 2125 KeyError, | |
| 2126 cfg.getvar, | |
| 2127 u("process")) | |
| 2128 self.assertRaises( | |
| 2129 KeyError, | |
| 2130 cfg.getvar, | |
| 2131 u("intl.cache")) | |
| 2132 | |
| 2051 | 2133 |
| 2052 class T09Parser(_TParserMixin, unittest.TestCase): | 2134 class T09Parser(_TParserMixin, unittest.TestCase): |
| 2053 | 2135 |
| 2054 def setUp(self): | 2136 def setUp(self): |
| 2055 self.unquote = configmix.config.py_unquote | 2137 self.unquote = configmix.config.py_unquote |
