changeset 416:2abde0d3c735

FIX: Handle .jailed() with an empty "root" properly
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 01 Dec 2021 23:09:00 +0100
parents 606feee43e71
children 83d537f1dfbb
files configmix/config.py tests/test.py
diffstat 2 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/configmix/config.py	Mon Nov 22 09:34:16 2021 +0100
+++ b/configmix/config.py	Wed Dec 01 23:09:00 2021 +0100
@@ -689,16 +689,21 @@
             raise ValueError("only one of `rootpath' or `root' can be given")
         if rootpath is None and root is None:
             raise ValueError("one of `rootpath' or `root' must be given")
+        if rootpath is not None and not isinstance(rootpath, (list, tuple)):
+            raise TypeError("`rootpath' must be a list or a tuple")
         if root is not None:
             # convert to path
             varns, varname = self._split_ns(root)
             if varns:
                 raise ValueError(
                     "jailed configurations do not support namespaces")
-            rootpath = [
-                self.unquote(p) for p in root.split(
-                    self._HIER_SEPARATOR)
-            ]
+            if varname:
+                rootpath = [
+                    self.unquote(p) for p in root.split(
+                        self._HIER_SEPARATOR)
+                ]
+            else:
+                rootpath = tuple()
         jc = _JailedConfiguration(*rootpath)
         if bind_root:
             jc.rebind(self)
--- a/tests/test.py	Mon Nov 22 09:34:16 2021 +0100
+++ b/tests/test.py	Wed Dec 01 23:09:00 2021 +0100
@@ -1241,7 +1241,7 @@
 
     def test_root_empty(self):
         cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
-        jcfg = cfg.jailed(rootpath=u"")
+        jcfg = cfg.jailed(root=u"")
 
         self.assertTrue(jcfg.getvarl(u"tree1", u"tree2", u"key5"))
         self.assertTrue(jcfg.getvarl_s(u"tree1", u"tree2", u"key5"))