Mercurial > hgrepos > Python > libs > ConfigMix
comparison tests/test.py @ 112:c50ad93eb5dc
Implemented a "safe_load()" to load with safe merging
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Sat, 24 Mar 2018 20:57:42 +0100 |
| parents | 057d87d030f1 |
| children | 5b667c252f8c |
comparison
equal
deleted
inserted
replaced
| 111:d51a18e5b0e3 | 112:c50ad93eb5dc |
|---|---|
| 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): | 93 class _T02MixinLoadAndMerge: |
| 94 | 94 |
| 95 def test01_load(self): | 95 def test01_load(self): |
| 96 cfg = configmix.load( | 96 cfg = self._load( |
| 97 os.path.join(TESTDATADIR, "conf20.yml"), | 97 os.path.join(TESTDATADIR, "conf20.yml"), |
| 98 os.path.join(TESTDATADIR, "conf21.yml")) | 98 os.path.join(TESTDATADIR, "conf21.yml")) |
| 99 | 99 |
| 100 self.assertEqual(u("the_database_user"), | 100 self.assertEqual(u("the_database_user"), |
| 101 cfg.getvar_s("db.user.name")) | 101 cfg.getvar_s("db.user.name")) |
| 126 | 126 |
| 127 self.assertEqual(list(range(0, 3)), | 127 self.assertEqual(list(range(0, 3)), |
| 128 cfg.getvar_s("test.Str")) | 128 cfg.getvar_s("test.Str")) |
| 129 | 129 |
| 130 def test02_load_with_ini(self): | 130 def test02_load_with_ini(self): |
| 131 cfg = configmix.load( | 131 cfg = self._load( |
| 132 os.path.join(TESTDATADIR, "conf20.yml"), | 132 os.path.join(TESTDATADIR, "conf20.yml"), |
| 133 os.path.join(TESTDATADIR, "conf21.yml"), | 133 os.path.join(TESTDATADIR, "conf21.yml"), |
| 134 os.path.join(TESTDATADIR, "conf22.ini")) | 134 os.path.join(TESTDATADIR, "conf22.ini")) |
| 135 | 135 |
| 136 self.assertEqual(u("the_database_user_2"), | 136 self.assertEqual(u("the_database_user_2"), |
| 152 self.assertEqual( | 152 self.assertEqual( |
| 153 u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"), | 153 u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"), |
| 154 url) | 154 url) |
| 155 | 155 |
| 156 | 156 |
| 157 class T02LoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase): | |
| 158 | |
| 159 def setUp(self): | |
| 160 self._load = configmix.load | |
| 161 | |
| 162 | |
| 163 class T03SafeLoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase): | |
| 164 | |
| 165 def setUp(self): | |
| 166 self._load = configmix.safe_load | |
| 167 | |
| 168 | |
| 157 if __name__ == "__main__": | 169 if __name__ == "__main__": |
| 158 unittest.main() | 170 unittest.main() |
