|
93
|
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)) |
|
95
|
39 self.assertEqual(255, cfg.get("key6")) |
|
93
|
40 |
|
|
41 def test01_ini_types(self): |
|
|
42 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini")) |
|
|
43 self.__check_types(cfg) |
|
|
44 |
|
|
45 def test02_py_types(self): |
|
|
46 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf1.py")) |
|
|
47 self.__check_types(cfg) |
|
|
48 |
|
|
49 def test03_yaml_types(self): |
|
|
50 with open(os.path.join(TESTDATADIR, "conf1.yml"), "rt") as f: |
|
|
51 cfg = configmix.yaml.safe_load(f) |
|
|
52 self.__check_types(cfg) |
|
|
53 |
|
|
54 def test04_py_export_all(self): |
|
|
55 # When __all__ is given only it's keys are exported |
|
|
56 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf2.py")) |
|
|
57 self.assertEqual(u("the next value"), cfg.get("key1")) |
|
|
58 self.assertTrue(isinstance(cfg.get("key1"), type(u('')))) |
|
|
59 self.assertTrue(cfg.get("key2") is None) |
|
|
60 |
|
|
61 def test05_py_hide_private(self): |
|
|
62 # When no __all__ is given all symbols with leading "_" are hidden |
|
|
63 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf3.py")) |
|
|
64 self.assertEqual(u("the next value "), cfg.get("key1")) |
|
|
65 self.assertTrue(isinstance(cfg.get("key1"), type(u('')))) |
|
|
66 self.assertTrue(cfg.get("_key2") is None) |
|
|
67 |
|
|
68 |
|
|
69 if __name__ == "__main__": |
|
|
70 unittest.main() |