diff tests/test.py @ 432:b96f49c9c76b

Proper "repr()" for a jailed configuration: put the root path into the output
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 09 Dec 2021 22:51:10 +0100
parents 40be1d25ff1c
children bbc5b64e137a
line wrap: on
line diff
--- a/tests/test.py	Thu Dec 09 22:50:26 2021 +0100
+++ b/tests/test.py	Thu Dec 09 22:51:10 2021 +0100
@@ -17,7 +17,7 @@
 import configmix.json
 import configmix.py
 import configmix.toml
-from configmix.compat import u
+from configmix.compat import u, PY2
 
 
 TESTDATADIR = os.path.join(
@@ -1535,6 +1535,27 @@
             set([u"key1", u"key2", u"tree1"]),
             set(jcfg.getkeys(u"")))
 
+    def test_repr_empty_rootpath(self):
+        cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
+        jcfg = cfg.jailed(rootpath=tuple())
+
+        self.assertEqual(
+            r"_JailedConfiguration(rootpath=())",
+            repr(jcfg))
+
+    def test_repr_non_empty_rootpath(self):
+        cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
+        jcfg = cfg.jailed(rootpath=(u"tree1", u"tree2"))
+
+        if PY2:
+            self.assertEqual(
+                r"_JailedConfiguration(rootpath=(u'tree1', u'tree2'))",
+                repr(jcfg))
+        else:
+            self.assertEqual(
+                r"_JailedConfiguration(rootpath=('tree1', 'tree2'))",
+                repr(jcfg))
+
 
 if __name__ == "__main__":
     unittest.main()