Mercurial > hgrepos > Python > libs > ConfigMix
comparison tests/test.py @ 116:c37fa787c022
More unittests for fetching namespaced variables and filters
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Thu, 29 Mar 2018 08:53:35 +0200 |
| parents | 5b667c252f8c |
| children | eefde3288fb8 |
comparison
equal
deleted
inserted
replaced
| 115:a5339d39af5c | 116:c37fa787c022 |
|---|---|
| 1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
| 2 | 2 |
| 3 import sys | 3 import sys |
| 4 import os | 4 import os |
| 5 import unittest | 5 import unittest |
| 6 import platform | |
| 6 | 7 |
| 7 sys.path.insert( | 8 sys.path.insert( |
| 8 0, | 9 0, |
| 9 os.path.abspath( | 10 os.path.abspath( |
| 10 os.path.normpath(os.path.join(os.path.dirname(__file__), "..")))) | 11 os.path.normpath(os.path.join(os.path.dirname(__file__), "..")))) |
| 151 url = cfg.getvar_s("db.engines.ro.url") | 152 url = cfg.getvar_s("db.engines.ro.url") |
| 152 self.assertEqual( | 153 self.assertEqual( |
| 153 u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"), | 154 u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"), |
| 154 url) | 155 url) |
| 155 | 156 |
| 157 def test03_namespace(self): | |
| 158 cfg = self._load( | |
| 159 os.path.join(TESTDATADIR, "conf20.yml"), | |
| 160 os.path.join(TESTDATADIR, "conf21.yml"), | |
| 161 os.path.join(TESTDATADIR, "conf22.ini")) | |
| 162 self.assertEqual(u(os.getcwd()), cfg.getvar("OS:cwd")) | |
| 163 self.assertEqual(u(platform.python_version()), | |
| 164 cfg.getvar_s("PY:version")) | |
| 165 | |
| 166 def test04_no_filter(self): | |
| 167 cfg = self._load( | |
| 168 os.path.join(TESTDATADIR, "conf20.yml"), | |
| 169 os.path.join(TESTDATADIR, "conf21.yml"), | |
| 170 os.path.join(TESTDATADIR, "conf22.ini")) | |
| 171 | |
| 172 def _look(): | |
| 173 return cfg.getvar("OS:cwd|upper") | |
| 174 | |
| 175 self.assertRaises(KeyError, _look) | |
| 176 | |
| 156 | 177 |
| 157 class T02LoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase): | 178 class T02LoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase): |
| 158 | 179 |
| 159 def setUp(self): | 180 def setUp(self): |
| 160 self._load = configmix.load | 181 self._load = configmix.load |
| 161 | 182 |
| 162 def test03_identity(self): | 183 def test05_identity(self): |
| 163 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini")) | 184 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini")) |
| 164 cfg2 = configmix.merge(cfg, None) | 185 cfg2 = configmix.merge(cfg, None) |
| 165 self.assertEqual(id(cfg), id(cfg2)) | 186 self.assertEqual(id(cfg), id(cfg2)) |
| 166 | 187 |
| 167 def test04_identity(self): | 188 def test06_identity(self): |
| 168 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini")) | 189 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini")) |
| 169 cfg2 = configmix.merge(cfg, {}) | 190 cfg2 = configmix.merge(cfg, {}) |
| 170 self.assertEqual(id(cfg), id(cfg2)) | 191 self.assertEqual(id(cfg), id(cfg2)) |
| 171 | 192 |
| 172 | 193 |
| 173 class T03SafeLoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase): | 194 class T03SafeLoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase): |
| 174 | 195 |
| 175 def setUp(self): | 196 def setUp(self): |
| 176 self._load = configmix.safe_load | 197 self._load = configmix.safe_load |
| 177 | 198 |
| 178 def test03_deepcopy(self): | 199 def test05_deepcopy(self): |
| 179 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini")) | 200 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini")) |
| 180 cfg2 = configmix.safe_merge(cfg, None) | 201 cfg2 = configmix.safe_merge(cfg, None) |
| 181 self.assertNotEqual(id(cfg), id(cfg2)) | 202 self.assertNotEqual(id(cfg), id(cfg2)) |
| 182 | 203 |
| 183 def test04_deepcopy(self): | 204 def test06_deepcopy(self): |
| 184 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini")) | 205 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini")) |
| 185 cfg2 = configmix.safe_merge(cfg, {}) | 206 cfg2 = configmix.safe_merge(cfg, {}) |
| 186 self.assertNotEqual(id(cfg), id(cfg2)) | 207 self.assertNotEqual(id(cfg), id(cfg2)) |
| 187 | 208 |
| 188 | 209 |
