Mercurial > hgrepos > Python > libs > ConfigMix
comparison tests/test.py @ 93:84b9578cacce
Start with unit tests
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Sun, 18 Mar 2018 14:44:41 +0100 |
| parents | |
| children | a0ed95975980 |
comparison
equal
deleted
inserted
replaced
| 92:75738d488e9d | 93:84b9578cacce |
|---|---|
| 1 # -*- coding: utf-8 -*- | |
| 2 | |
| 3 import sys | |
| 4 import os | |
| 5 import unittest | |
| 6 | |
| 7 sys.path.insert( | |
| 8 0, | |
| 9 os.path.abspath( | |
| 10 os.path.normpath(os.path.join(os.path.dirname(__file__), "..")))) | |
| 11 | |
| 12 import configmix | |
| 13 import configmix.ini | |
| 14 import configmix.yaml | |
| 15 import configmix.py | |
| 16 from configmix.compat import u | |
| 17 | |
| 18 | |
| 19 TESTDATADIR = os.path.join( | |
| 20 os.path.abspath(os.path.dirname(__file__)), | |
| 21 "data") | |
| 22 | |
| 23 | |
| 24 class T01Basic(unittest.TestCase): | |
| 25 | |
| 26 """Check with low-level internal interfaces""" | |
| 27 | |
| 28 def __check_types(self, cfg): | |
| 29 self.assertEqual(u("the value"), | |
| 30 cfg.get("key1")) | |
| 31 self.assertTrue(isinstance(cfg.get("key1"), type(u('')))) | |
| 32 self.assertEqual(2, cfg.get("key2")) | |
| 33 self.assertEqual(5.7, cfg.get("key3")) | |
| 34 self.assertTrue(isinstance(cfg.get("key1"), type(u('')))) | |
| 35 self.assertTrue(cfg.get("key4")) | |
| 36 self.assertTrue(isinstance(cfg.get("key4"), bool)) | |
| 37 self.assertFalse(cfg.get("key5")) | |
| 38 self.assertTrue(isinstance(cfg.get("key5"), bool)) | |
| 39 | |
| 40 def test01_ini_types(self): | |
| 41 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini")) | |
| 42 self.__check_types(cfg) | |
| 43 | |
| 44 def test02_py_types(self): | |
| 45 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf1.py")) | |
| 46 self.__check_types(cfg) | |
| 47 | |
| 48 def test03_yaml_types(self): | |
| 49 with open(os.path.join(TESTDATADIR, "conf1.yml"), "rt") as f: | |
| 50 cfg = configmix.yaml.safe_load(f) | |
| 51 self.__check_types(cfg) | |
| 52 | |
| 53 def test04_py_export_all(self): | |
| 54 # When __all__ is given only it's keys are exported | |
| 55 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf2.py")) | |
| 56 self.assertEqual(u("the next value"), cfg.get("key1")) | |
| 57 self.assertTrue(isinstance(cfg.get("key1"), type(u('')))) | |
| 58 self.assertTrue(cfg.get("key2") is None) | |
| 59 | |
| 60 def test05_py_hide_private(self): | |
| 61 # When no __all__ is given all symbols with leading "_" are hidden | |
| 62 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf3.py")) | |
| 63 self.assertEqual(u("the next value "), cfg.get("key1")) | |
| 64 self.assertTrue(isinstance(cfg.get("key1"), type(u('')))) | |
| 65 self.assertTrue(cfg.get("_key2") is None) | |
| 66 | |
| 67 | |
| 68 if __name__ == "__main__": | |
| 69 unittest.main() |
