changeset 130:b11af3ded7c1

Added more JSON specific unit tests
author Franz Glasner <hg@dom66.de>
date Wed, 04 Apr 2018 23:36:26 +0200
parents df60417d7665
children b34ad08e7198
files tests/data/conf10.json tests/data/conf23.json tests/test.py
diffstat 3 files changed, 54 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/data/conf10.json	Wed Apr 04 23:36:26 2018 +0200
@@ -0,0 +1,10 @@
+{"key1": "in the root namespace",
+ "key2": "in the root namespace -- too",
+ "tree1": {
+     "key3": 32,
+     "tree2": {
+	 "key4": "get this as `tree1.tree2.key4'",
+	 "key5": true
+     }
+ }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/data/conf23.json	Wed Apr 04 23:36:26 2018 +0200
@@ -0,0 +1,13 @@
+{"tmpdir": "{{_tmpdir}}\\3",
+ "db": {
+     "user": {
+	 "name": "the_database_user_2",
+	 "pwd": "the-database-password-2"
+     },
+     "locinfo": {
+	 "ro": {
+	     "hostname": "3rd-host"
+	 }
+     }
+ }
+}
--- a/tests/test.py	Wed Apr 04 23:17:37 2018 +0200
+++ b/tests/test.py	Wed Apr 04 23:36:26 2018 +0200
@@ -101,6 +101,10 @@
             cfg = configmix.yaml.safe_load(f)
             self.__check_tree(cfg)
 
+    def test10_json_tree(self):
+        cfg = configmix.json.load(os.path.join(TESTDATADIR, "conf10.json"))
+        self.__check_tree(cfg)
+
 
 class _T02MixinLoadAndMerge:
 
@@ -165,6 +169,33 @@
             u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"),
             url)
 
+    def test02_load_with_json(self):
+        cfg = self._load(
+            os.path.join(TESTDATADIR, "conf20.yml"),
+            os.path.join(TESTDATADIR, "conf21.yml"),
+            # .ini replaced with an equivalent .json
+            os.path.join(TESTDATADIR, "conf23.json"))
+
+        self.assertEqual(u("the_database_user_2"),
+                         cfg.getvar_s("db.user.name"))
+        self.assertEqual(u("the-database-password-2"),
+                         cfg.getvar_s("db.user.pwd"))
+
+        tmpdir = cfg.getvar_s("tmpdir")
+        self.assertEqual(u(os.getcwd()) + u("/tmp\\3"), tmpdir)
+
+        self.assertEqual(u("3rd-host"),
+                         cfg.getvar_s("db.locinfo.ro.hostname"))
+        self.assertEqual(u("localhost"),
+                         cfg.getvar_s("db.locinfo.rw.hostname"))
+
+        self.assertEqual(5432, cfg.getvar_s("db.locinfo.ro.port"))
+
+        url = cfg.getvar_s("db.engines.ro.url")
+        self.assertEqual(
+            u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"),
+            url)
+
     def test03_namespace(self):
         cfg = self._load(
             os.path.join(TESTDATADIR, "conf20.yml"),