Mercurial > hgrepos > Python > libs > ConfigMix
comparison tests/test.py @ 554:36d7aa000435
Implement a C-version of Configuration.interpolate_variables
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 03 Jan 2022 00:11:41 +0100 |
| parents | 9d2bd411f5c5 |
| children | 75ecbe07abff |
comparison
equal
deleted
inserted
replaced
| 553:9d2bd411f5c5 | 554:36d7aa000435 |
|---|---|
| 1918 self.split_filters(u"the-varname|None")) | 1918 self.split_filters(u"the-varname|None")) |
| 1919 | 1919 |
| 1920 def test_split_filters_many(self): | 1920 def test_split_filters_many(self): |
| 1921 self.assertEqual((u"the-varname", [u"Empty", u"None"]), | 1921 self.assertEqual((u"the-varname", [u"Empty", u"None"]), |
| 1922 self.split_filters(u"the-varname|Empty|None")) | 1922 self.split_filters(u"the-varname|Empty|None")) |
| 1923 | 1923 |
| 1924 def test_None_filter_single(self): | |
| 1925 cfg = configmix.load() | |
| 1926 x = getattr(cfg, self.interpolate_meth)(u"{{non-existing|None}}") | |
| 1927 self.assertIsNone(x) | |
| 1928 # caching should have no effect | |
| 1929 y = getattr(cfg, self.interpolate_meth)(u"{{non-existing|None}}") | |
| 1930 self.assertIsNone(y) | |
| 1931 | |
| 1932 def test_None_filter_embedded(self): | |
| 1933 cfg = configmix.load() | |
| 1934 x = getattr(cfg, self.interpolate_meth)(u"A{{non-existing|None}}Z") | |
| 1935 self.assertEqual(u"AZ", x) | |
| 1936 # caching should have no effect | |
| 1937 y = getattr(cfg, self.interpolate_meth)(u"A{{non-existing|None}}Z") | |
| 1938 self.assertEqual(u"AZ", y) | |
| 1939 | |
| 1940 def test_Empty_filtersingle(self): | |
| 1941 cfg = configmix.load() | |
| 1942 x = getattr(cfg, self.interpolate_meth)(u"{{non-existing|Empty}}") | |
| 1943 self.assertEqual("", x) | |
| 1944 # caching should have no effect | |
| 1945 y = getattr(cfg, self.interpolate_meth)(u"{{non-existing|Empty}}") | |
| 1946 self.assertEqual("", y) | |
| 1947 | |
| 1948 def test_None_filter_pass_through(self): | |
| 1949 cfg = configmix.load(os.path.join(TESTDATADIR, "conf20.yml"), | |
| 1950 os.path.join(TESTDATADIR, "conf21.yml"), | |
| 1951 os.path.join(TESTDATADIR, "conf22.ini"), | |
| 1952 os.path.join(TESTDATADIR, "conf23.json"), | |
| 1953 os.path.join(TESTDATADIR, "conf24.toml")) | |
| 1954 x = getattr(cfg, self.interpolate_meth)(u"{{intl.cache.items|None}}") | |
| 1955 self.assertEqual(10, x) | |
| 1956 # caching should have no effect | |
| 1957 y = getattr(cfg, self.interpolate_meth)(u"{{intl.cache.items|None}}") | |
| 1958 self.assertEqual(10, y) | |
| 1959 | |
| 1960 def test_Empty_filter_pass_through(self): | |
| 1961 cfg = configmix.load(os.path.join(TESTDATADIR, "conf20.yml"), | |
| 1962 os.path.join(TESTDATADIR, "conf21.yml"), | |
| 1963 os.path.join(TESTDATADIR, "conf22.ini"), | |
| 1964 os.path.join(TESTDATADIR, "conf23.json"), | |
| 1965 os.path.join(TESTDATADIR, "conf24.toml")) | |
| 1966 x = getattr(cfg, self.interpolate_meth)(u"{{intl.cache.items|Empty}}") | |
| 1967 self.assertEqual(10, x) | |
| 1968 # caching should have no effect | |
| 1969 y = getattr(cfg, self.interpolate_meth)(u"{{intl.cache.items|Empty}}") | |
| 1970 self.assertEqual(10, y) | |
| 1971 | |
| 1972 def test_Empty_filter_no_pass_through_2(self): | |
| 1973 cfg = configmix.load(os.path.join(TESTDATADIR, "conf20.yml"), | |
| 1974 os.path.join(TESTDATADIR, "conf21.yml"), | |
| 1975 os.path.join(TESTDATADIR, "conf22.ini"), | |
| 1976 os.path.join(TESTDATADIR, "conf23.json"), | |
| 1977 os.path.join(TESTDATADIR, "conf24.toml")) | |
| 1978 x = getattr(cfg, self.interpolate_meth)(u"{{intl.cache.items|Empty}}{{intl.cache.items}}") | |
| 1979 self.assertEqual(u"1010", x) | |
| 1980 # caching should have no effect | |
| 1981 y = getattr(cfg, self.interpolate_meth)(u"{{intl.cache.items|Empty}}{{intl.cache.items}}") | |
| 1982 self.assertEqual(u"1010", y) | |
| 1983 | |
| 1984 def test_interpolate_wrong_syntax(self): | |
| 1985 cfg = configmix.load() | |
| 1986 x1 = getattr(cfg, self.interpolate_meth)(u"{{the-variable}") | |
| 1987 self.assertEqual(u"{{the-variable}", x1) | |
| 1988 x2 = getattr(cfg, self.interpolate_meth)(u"A{{the-variable}Z") | |
| 1989 self.assertEqual(u"A{{the-variable}Z", x2) | |
| 1990 x3 = getattr(cfg, self.interpolate_meth)(u"A{{1{{2{{3}Z") | |
| 1991 self.assertEqual(u"A{{1{{2{{3}Z", x3) | |
| 1992 # caching should have no effect | |
| 1993 y1 = getattr(cfg, self.interpolate_meth)(u"{{the-variable}") | |
| 1994 self.assertEqual(u"{{the-variable}", y1) | |
| 1995 y2 = getattr(cfg, self.interpolate_meth)(u"A{{the-variable}Z") | |
| 1996 self.assertEqual(u"A{{the-variable}Z", y2) | |
| 1997 y3 = getattr(cfg, self.interpolate_meth)(u"A{{1{{2{{3}Z") | |
| 1998 self.assertEqual(u"A{{1{{2{{3}Z", y3) | |
| 1999 | |
| 2000 def test_interpolate_empty_str(self): | |
| 2001 cfg = configmix.load() | |
| 2002 x = getattr(cfg, self.interpolate_meth)(u"") | |
| 2003 self.assertEqual(u"", x) | |
| 2004 # caching should have no effect | |
| 2005 y = getattr(cfg, self.interpolate_meth)(u"") | |
| 2006 self.assertEqual(u"", y) | |
| 2007 | |
| 2008 def test_interpolate_no_interpolation(self): | |
| 2009 cfg = configmix.load() | |
| 2010 x = getattr(cfg, self.interpolate_meth)(u"no-interpolation-here") | |
| 2011 self.assertEqual(u"no-interpolation-here", x) | |
| 2012 # caching should have no effect | |
| 2013 y = getattr(cfg, self.interpolate_meth)(u"no-interpolation-here") | |
| 2014 self.assertEqual(u"no-interpolation-here", y) | |
| 2015 | |
| 1924 | 2016 |
| 1925 class T09Parser(_TParserMixin, unittest.TestCase): | 2017 class T09Parser(_TParserMixin, unittest.TestCase): |
| 1926 | 2018 |
| 1927 def setUp(self): | 2019 def setUp(self): |
| 1928 self.unquote = configmix.config.py_unquote | 2020 self.unquote = configmix.config.py_unquote |
| 1929 self.quote = configmix.config.py_quote | 2021 self.quote = configmix.config.py_quote |
| 1930 self.pathstr2path = configmix.config.py_pathstr2path | 2022 self.pathstr2path = configmix.config.py_pathstr2path |
| 1931 self.split_ns = configmix.config._py_split_ns | 2023 self.split_ns = configmix.config._py_split_ns |
| 1932 self.split_filters = configmix.config._py_split_filters | 2024 self.split_filters = configmix.config._py_split_filters |
| 2025 self.interpolate_meth = "py_interpolate_variables" | |
| 1933 | 2026 |
| 1934 def test_split_ns_wrong_type(self): | 2027 def test_split_ns_wrong_type(self): |
| 1935 self.assertRaises( | 2028 self.assertRaises( |
| 1936 AttributeError, # no .partition | 2029 AttributeError, # no .partition |
| 1937 self.split_ns, | 2030 self.split_ns, |
| 1957 self.unquote = configmix.config.fast_unquote | 2050 self.unquote = configmix.config.fast_unquote |
| 1958 self.quote = configmix.config.fast_quote | 2051 self.quote = configmix.config.fast_quote |
| 1959 self.pathstr2path = configmix.config.fast_pathstr2path | 2052 self.pathstr2path = configmix.config.fast_pathstr2path |
| 1960 self.split_ns = configmix.config._fast_split_ns | 2053 self.split_ns = configmix.config._fast_split_ns |
| 1961 self.split_filters = configmix.config._fast_split_filters | 2054 self.split_filters = configmix.config._fast_split_filters |
| 2055 self.interpolate_meth = "fast_interpolate_variables" | |
| 1962 | 2056 |
| 1963 def test_split_ns_wrong_type(self): | 2057 def test_split_ns_wrong_type(self): |
| 1964 self.assertRaises( | 2058 self.assertRaises( |
| 1965 TypeError, | 2059 TypeError, |
| 1966 self.split_ns, | 2060 self.split_ns, |
