Mercurial > hgrepos > Python > libs > ConfigMix
diff tests/test.py @ 105:1c2f8a96dec2
Unittests with some real-worl-examples of .yml and .ini configuration files
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Fri, 23 Mar 2018 17:43:36 +0100 |
| parents | 1b4d95f60650 |
| children | 057d87d030f1 |
line wrap: on
line diff
--- a/tests/test.py Fri Mar 23 17:25:21 2018 +0100 +++ b/tests/test.py Fri Mar 23 17:43:36 2018 +0100 @@ -90,5 +90,63 @@ self.__check_tree(cfg) +class T02LoadAndMerge(unittest.TestCase): + + def test01_load(self): + cfg = configmix.load( + os.path.join(TESTDATADIR, "conf20.yml"), + os.path.join(TESTDATADIR, "conf21.yml")) + + self.assertEqual(u("the_database_user"), + cfg.getvar_s("db.user.name")) + self.assertEqual(u("the-database-password"), + cfg.getvar_s("db.user.pwd")) + + tmpdir = cfg.getvar_s("tmpdir") + if os.name == 'nt': + self.assertFalse(u('/') in tmpdir) + self.assertEqual(os.path.normpath( + os.path.abspath(os.path.join(os.getcwd(), "tmp"))), + tmpdir) + + self.assertEqual(u("anotherhost"), + 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:the-database-password@anotherhost:5432/my_database_catalog"), + url) + + def test02_load_with_ini(self): + cfg = configmix.load( + os.path.join(TESTDATADIR, "conf20.yml"), + os.path.join(TESTDATADIR, "conf21.yml"), + os.path.join(TESTDATADIR, "conf22.ini")) + + 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\\2"), 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) + + if __name__ == "__main__": unittest.main()
