comparison 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
comparison
equal deleted inserted replaced
129:df60417d7665 130:b11af3ded7c1
99 with io.open(os.path.join(TESTDATADIR, "conf10.yml"), "rt", 99 with io.open(os.path.join(TESTDATADIR, "conf10.yml"), "rt",
100 encoding="utf-8") as f: 100 encoding="utf-8") as f:
101 cfg = configmix.yaml.safe_load(f) 101 cfg = configmix.yaml.safe_load(f)
102 self.__check_tree(cfg) 102 self.__check_tree(cfg)
103 103
104 def test10_json_tree(self):
105 cfg = configmix.json.load(os.path.join(TESTDATADIR, "conf10.json"))
106 self.__check_tree(cfg)
107
104 108
105 class _T02MixinLoadAndMerge: 109 class _T02MixinLoadAndMerge:
106 110
107 def test01_load(self): 111 def test01_load(self):
108 cfg = self._load( 112 cfg = self._load(
163 url = cfg.getvar_s("db.engines.ro.url") 167 url = cfg.getvar_s("db.engines.ro.url")
164 self.assertEqual( 168 self.assertEqual(
165 u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"), 169 u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"),
166 url) 170 url)
167 171
172 def test02_load_with_json(self):
173 cfg = self._load(
174 os.path.join(TESTDATADIR, "conf20.yml"),
175 os.path.join(TESTDATADIR, "conf21.yml"),
176 # .ini replaced with an equivalent .json
177 os.path.join(TESTDATADIR, "conf23.json"))
178
179 self.assertEqual(u("the_database_user_2"),
180 cfg.getvar_s("db.user.name"))
181 self.assertEqual(u("the-database-password-2"),
182 cfg.getvar_s("db.user.pwd"))
183
184 tmpdir = cfg.getvar_s("tmpdir")
185 self.assertEqual(u(os.getcwd()) + u("/tmp\\3"), tmpdir)
186
187 self.assertEqual(u("3rd-host"),
188 cfg.getvar_s("db.locinfo.ro.hostname"))
189 self.assertEqual(u("localhost"),
190 cfg.getvar_s("db.locinfo.rw.hostname"))
191
192 self.assertEqual(5432, cfg.getvar_s("db.locinfo.ro.port"))
193
194 url = cfg.getvar_s("db.engines.ro.url")
195 self.assertEqual(
196 u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"),
197 url)
198
168 def test03_namespace(self): 199 def test03_namespace(self):
169 cfg = self._load( 200 cfg = self._load(
170 os.path.join(TESTDATADIR, "conf20.yml"), 201 os.path.join(TESTDATADIR, "conf20.yml"),
171 os.path.join(TESTDATADIR, "conf21.yml"), 202 os.path.join(TESTDATADIR, "conf21.yml"),
172 os.path.join(TESTDATADIR, "conf22.ini")) 203 os.path.join(TESTDATADIR, "conf22.ini"))