Mercurial > hgrepos > Python > libs > ConfigMix
changeset 659:b97e5f3bbc8e
Test indexed list access in variable interpolations: ok.
Also drop an extra note into the documentation.
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Mon, 30 May 2022 14:08:40 +0200 |
| parents | 6102b767fc69 |
| children | cb950239ec94 |
| files | docs/introduction.rst tests/data/index-access-for-jails.yml tests/test.py |
| diffstat | 3 files changed, 11 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/docs/introduction.rst Mon May 30 13:23:53 2022 +0200 +++ b/docs/introduction.rst Mon May 30 14:08:40 2022 +0200 @@ -301,6 +301,8 @@ - Encode the index number to string format using the ``~INDEX~`` syntax and use :py:meth:`~.Configuration.getvar` and its friends. + This syntax is also supported for variable interpolations. + Negative indexes are supported with Python semantics. Examples:
--- a/tests/data/index-access-for-jails.yml Mon May 30 13:23:53 2022 +0200 +++ b/tests/data/index-access-for-jails.yml Mon May 30 14:08:40 2022 +0200 @@ -9,3 +9,6 @@ - entry: 0 - entry: 1 - entry: 2 + +expand-me: '{{the-list.~1~.entry}}' +expand-me-2: '{{the-list.~-1~.entry}}'
--- a/tests/test.py Mon May 30 13:23:53 2022 +0200 +++ b/tests/test.py Mon May 30 14:08:40 2022 +0200 @@ -981,6 +981,12 @@ 2, cfg.getvar_s(u"the-list.~%d~.entry" % (-1, ))) + def test53_expand_an_indexed_substitution(self): + cfg = self._load(os.path.join(TESTDATADIR, + "index-access-for-jails.yml")) + self.assertEqual(1, cfg.getvar_s(u"expand-me")) + self.assertEqual(2, cfg.getvar_s(u"expand-me-2")) + class T02LoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase):
