changeset 404:6a5aea02f3d0

Implement a ".is_jail" flag for configuration objects: to test/assert whether we expect a jail configuration
author Franz Glasner <f.glasner@feldmann-mg.com>
date Fri, 19 Nov 2021 12:40:23 +0100
parents 7db59202c9af
children af367e1d0950
files configmix/config.py tests/test.py
diffstat 2 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/configmix/config.py	Fri Nov 19 09:31:26 2021 +0100
+++ b/configmix/config.py	Fri Nov 19 12:40:23 2021 +0100
@@ -73,6 +73,9 @@
     _QUOTE = u(b'%')
     _COMMENT = u(b'#')
 
+    is_jail = False
+    """Flag to show that this is not a jail for another configuration"""
+
     def getvarl(self, *path, **kwds):
         """Get a variable where the hierarchy is given in `path` as sequence
         and the namespace is given in the `namespace` keyword argument.
@@ -708,6 +711,9 @@
 
     __slots__ = ("_base", "_path", "_pathstr")
 
+    is_jail = True
+    """Flag to show that this is a jail for another configuration"""
+
     def __init__(self, config, *path):
         super(_JailedConfiguration, self).__init__()
         self._base = config
--- a/tests/test.py	Fri Nov 19 09:31:26 2021 +0100
+++ b/tests/test.py	Fri Nov 19 12:40:23 2021 +0100
@@ -1172,7 +1172,10 @@
 
     def test_root(self):
         cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
+        self.assertFalse(cfg.is_jail)
+        
         jcfg = cfg.jailed(root=u"tree1")
+        self.assertTrue(jcfg.is_jail)
 
         self.assertTrue(jcfg.getvarl(u"tree2", u"key5"))
         self.assertTrue(jcfg.getvarl_s(u"tree2", u"key5"))