# HG changeset patch # User Franz Glasner # Date 1522877786 -7200 # Node ID b11af3ded7c164b62dce6797fb132c442c7f831a # Parent df60417d7665c82dc627bc709e9451791ae9a08b Added more JSON specific unit tests diff -r df60417d7665 -r b11af3ded7c1 tests/data/conf10.json --- /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 + } + } +} diff -r df60417d7665 -r b11af3ded7c1 tests/data/conf23.json --- /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" + } + } + } +} diff -r df60417d7665 -r b11af3ded7c1 tests/test.py --- 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"),