comparison tests/test.py @ 122:21d92ff8cf31

Begin the handling of JSON-style configuration files
author Franz Glasner <hg@dom66.de>
date Wed, 04 Apr 2018 09:45:29 +0200
parents ba5970a2dcef
children 5b62d2c0e5a8
comparison
equal deleted inserted replaced
121:0d378dcc018b 122:21d92ff8cf31
12 os.path.normpath(os.path.join(os.path.dirname(__file__), "..")))) 12 os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))))
13 13
14 import configmix 14 import configmix
15 import configmix.ini 15 import configmix.ini
16 import configmix.yaml 16 import configmix.yaml
17 import configmix.json
17 import configmix.py 18 import configmix.py
18 from configmix.compat import u 19 from configmix.compat import u
19 20
20 21
21 TESTDATADIR = os.path.join( 22 TESTDATADIR = os.path.join(
65 with io.open(os.path.join(TESTDATADIR, "conf1.yml"), "rt", 66 with io.open(os.path.join(TESTDATADIR, "conf1.yml"), "rt",
66 encoding="utf-8") as f: 67 encoding="utf-8") as f:
67 cfg = configmix.yaml.safe_load(f) 68 cfg = configmix.yaml.safe_load(f)
68 self.__check_types(cfg) 69 self.__check_types(cfg)
69 70
70 def test04_py_export_all(self): 71 def test04_json_types(self):
72 cfg = configmix.json.load(os.path.join(TESTDATADIR, "conf1.json"))
73 self.__check_types(cfg)
74
75 def test05_py_export_all(self):
71 # When __all__ is given only it's keys are exported 76 # When __all__ is given only it's keys are exported
72 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf2.py")) 77 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf2.py"))
73 self.assertEqual(u("the next value"), cfg.get("key1")) 78 self.assertEqual(u("the next value"), cfg.get("key1"))
74 self.assertTrue(isinstance(cfg.get("key1"), type(u('')))) 79 self.assertTrue(isinstance(cfg.get("key1"), type(u(''))))
75 self.assertTrue(cfg.get("key2") is None) 80 self.assertTrue(cfg.get("key2") is None)
76 81
77 def test05_py_hide_private(self): 82 def test06_py_hide_private(self):
78 # When no __all__ is given all symbols with leading "_" are hidden 83 # When no __all__ is given all symbols with leading "_" are hidden
79 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf3.py")) 84 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf3.py"))
80 self.assertEqual(u("the next value "), cfg.get("key1")) 85 self.assertEqual(u("the next value "), cfg.get("key1"))
81 self.assertTrue(isinstance(cfg.get("key1"), type(u('')))) 86 self.assertTrue(isinstance(cfg.get("key1"), type(u(''))))
82 self.assertTrue(cfg.get("_key2") is None) 87 self.assertTrue(cfg.get("_key2") is None)
83 88
84 def test06_ini_tree(self): 89 def test07_ini_tree(self):
85 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf10.ini")) 90 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf10.ini"))
86 self.__check_tree(cfg) 91 self.__check_tree(cfg)
87 92
88 def test07_py_tree(self): 93 def test08_py_tree(self):
89 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf10.py")) 94 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf10.py"))
90 self.__check_tree(cfg) 95 self.__check_tree(cfg)
91 96
92 def test08_yaml_tree(self): 97 def test09_yaml_tree(self):
93 with io.open(os.path.join(TESTDATADIR, "conf10.yml"), "rt", 98 with io.open(os.path.join(TESTDATADIR, "conf10.yml"), "rt",
94 encoding="utf-8") as f: 99 encoding="utf-8") as f:
95 cfg = configmix.yaml.safe_load(f) 100 cfg = configmix.yaml.safe_load(f)
96 self.__check_tree(cfg) 101 self.__check_tree(cfg)
97 102