Mercurial > hgrepos > Python > libs > ConfigMix
comparison tests/test.py @ 657:213f0ec3bbbc
Test list access with negative indexes
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Mon, 30 May 2022 13:19:19 +0200 |
| parents | 2b1c7a68f913 |
| children | b97e5f3bbc8e |
comparison
equal
deleted
inserted
replaced
| 656:2b1c7a68f913 | 657:213f0ec3bbbc |
|---|---|
| 965 for idx in range(len(cfg.getvarl(u"the-list"))): | 965 for idx in range(len(cfg.getvarl(u"the-list"))): |
| 966 self.assertEqual( | 966 self.assertEqual( |
| 967 idx, | 967 idx, |
| 968 cfg.getvar_s(u"the-list.~%d~.entry" % (idx, ))) | 968 cfg.getvar_s(u"the-list.~%d~.entry" % (idx, ))) |
| 969 | 969 |
| 970 def test51_neg_index_access_to_lists_with_subdicts(self): | |
| 971 cfg = self._load(os.path.join(TESTDATADIR, | |
| 972 "index-access-for-jails.yml")) | |
| 973 self.assertEqual( | |
| 974 2, | |
| 975 cfg.getvarl_s(u"the-list", -1, u"entry")) | |
| 976 | |
| 977 def test52_neg_index_access_to_lists_with_subdicts(self): | |
| 978 cfg = self._load(os.path.join(TESTDATADIR, | |
| 979 "index-access-for-jails.yml")) | |
| 980 self.assertEqual( | |
| 981 2, | |
| 982 cfg.getvar_s(u"the-list.~%d~.entry" % (-1, ))) | |
| 983 | |
| 970 | 984 |
| 971 class T02LoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase): | 985 class T02LoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase): |
| 972 | 986 |
| 973 def setUp(self): | 987 def setUp(self): |
| 974 self._load = configmix.load | 988 self._load = configmix.load |
| 1913 self.assertEqual(1, len(jcfg)) | 1927 self.assertEqual(1, len(jcfg)) |
| 1914 self.assertEqual(idx, jcfg.getvarl_s(u"entry")) | 1928 self.assertEqual(idx, jcfg.getvarl_s(u"entry")) |
| 1915 self.assertEqual((u"the-list", idx), jcfg._path) | 1929 self.assertEqual((u"the-list", idx), jcfg._path) |
| 1916 self.assertEqual(u"the-list.~%d~." % (idx, ), jcfg._pathstr) | 1930 self.assertEqual(u"the-list.~%d~." % (idx, ), jcfg._pathstr) |
| 1917 | 1931 |
| 1932 def test_negative_index_jail_access(self): | |
| 1933 cfg = configmix.load(os.path.join( | |
| 1934 TESTDATADIR, "index-access-for-jails.yml")) | |
| 1935 jcfg = cfg.jailed(rootpath=(u"the-list", -1)) | |
| 1936 self.assertEqual(2, jcfg.getvarl_s("entry")) | |
| 1937 self.assertEqual((u"the-list", -1), jcfg._path) | |
| 1938 self.assertEqual(u"the-list.~-1~.", jcfg._pathstr) | |
| 1939 | |
| 1918 def test_index_jail_access_with_strpath(self): | 1940 def test_index_jail_access_with_strpath(self): |
| 1919 cfg = configmix.load(os.path.join( | 1941 cfg = configmix.load(os.path.join( |
| 1920 TESTDATADIR, "index-access-for-jails.yml")) | 1942 TESTDATADIR, "index-access-for-jails.yml")) |
| 1921 for idx in range(len(cfg.getvarl(u"the-list"))): | 1943 for idx in range(len(cfg.getvarl(u"the-list"))): |
| 1922 jcfg = cfg.jailed(root=u"the-list.~%d~" % (idx, )) | 1944 jcfg = cfg.jailed(root=u"the-list.~%d~" % (idx, )) |
