diff tests/test.py @ 130:b11af3ded7c1

Added more JSON specific unit tests
author Franz Glasner <hg@dom66.de>
date Wed, 04 Apr 2018 23:36:26 +0200
parents 5b62d2c0e5a8
children 2f2e819e8d17
line wrap: on
line diff
--- 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"),