comparison 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
comparison
equal deleted inserted replaced
104:d9f9a06e0c49 105:1c2f8a96dec2
88 with open(os.path.join(TESTDATADIR, "conf10.yml"), "rt") as f: 88 with open(os.path.join(TESTDATADIR, "conf10.yml"), "rt") as f:
89 cfg = configmix.yaml.safe_load(f) 89 cfg = configmix.yaml.safe_load(f)
90 self.__check_tree(cfg) 90 self.__check_tree(cfg)
91 91
92 92
93 class T02LoadAndMerge(unittest.TestCase):
94
95 def test01_load(self):
96 cfg = configmix.load(
97 os.path.join(TESTDATADIR, "conf20.yml"),
98 os.path.join(TESTDATADIR, "conf21.yml"))
99
100 self.assertEqual(u("the_database_user"),
101 cfg.getvar_s("db.user.name"))
102 self.assertEqual(u("the-database-password"),
103 cfg.getvar_s("db.user.pwd"))
104
105 tmpdir = cfg.getvar_s("tmpdir")
106 if os.name == 'nt':
107 self.assertFalse(u('/') in tmpdir)
108 self.assertEqual(os.path.normpath(
109 os.path.abspath(os.path.join(os.getcwd(), "tmp"))),
110 tmpdir)
111
112 self.assertEqual(u("anotherhost"),
113 cfg.getvar_s("db.locinfo.ro.hostname"))
114 self.assertEqual(u("localhost"),
115 cfg.getvar_s("db.locinfo.rw.hostname"))
116
117 self.assertEqual(5432, cfg.getvar_s("db.locinfo.ro.port"))
118
119 url = cfg.getvar_s("db.engines.ro.url")
120 self.assertEqual(
121 u("postgresql+psycopg2://the_database_user:the-database-password@anotherhost:5432/my_database_catalog"),
122 url)
123
124 def test02_load_with_ini(self):
125 cfg = configmix.load(
126 os.path.join(TESTDATADIR, "conf20.yml"),
127 os.path.join(TESTDATADIR, "conf21.yml"),
128 os.path.join(TESTDATADIR, "conf22.ini"))
129
130 self.assertEqual(u("the_database_user_2"),
131 cfg.getvar_s("db.user.name"))
132 self.assertEqual(u("the-database-password-2"),
133 cfg.getvar_s("db.user.pwd"))
134
135 tmpdir = cfg.getvar_s("tmpdir")
136 self.assertEqual(u(os.getcwd()) + u("/tmp\\2"), tmpdir)
137
138 self.assertEqual(u("3rd-host"),
139 cfg.getvar_s("db.locinfo.ro.hostname"))
140 self.assertEqual(u("localhost"),
141 cfg.getvar_s("db.locinfo.rw.hostname"))
142
143 self.assertEqual(5432, cfg.getvar_s("db.locinfo.ro.port"))
144
145 url = cfg.getvar_s("db.engines.ro.url")
146 self.assertEqual(
147 u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"),
148 url)
149
150
93 if __name__ == "__main__": 151 if __name__ == "__main__":
94 unittest.main() 152 unittest.main()