test_multi.py (1965B)
1 # standard imports 2 import os 3 import unittest 4 import logging 5 6 from confini import Config 7 8 logging.basicConfig(level=logging.DEBUG) 9 logg = logging.getLogger() 10 11 12 class TestBasic(unittest.TestCase): 13 14 wd = os.path.dirname(__file__) 15 16 def setUp(self): 17 pass 18 19 20 def tearDown(self): 21 pass 22 23 24 def test_parse_two(self): 25 inidir_one = os.path.join(self.wd, 'files', 'multi', 'one') 26 inidir_two = os.path.join(self.wd, 'files', 'multi', 'two') 27 c = Config(inidir_one, override_dirs=[inidir_two]) 28 c.process() 29 r = c.get('FOO_BAR') 30 self.assertEqual(r, 'plugh') 31 r = c.get('FOO_BAZ') 32 self.assertEqual(r, '42') 33 r = c.get('FOO_BAH') 34 self.assertEqual(r, None) 35 r = c.get('BAR_ONE') 36 self.assertEqual(r, 'three') 37 38 39 def test_parse_two_one_undef(self): 40 inidir_one = os.path.join(self.wd, 'files', 'multi', 'one') 41 inidir_two = os.path.join(self.wd, 'files', 'multi', 'four') 42 c = Config(inidir_one, override_dirs=[inidir_two]) 43 c.process() 44 r = c.get('FOO_BAH') 45 self.assertEqual(r, '123') 46 r = c.get('FOO_BAZ') 47 self.assertEqual(r, '42') 48 49 50 def test_parse_two_schema_error(self): 51 inidir_one = os.path.join(self.wd, 'files', 'multi', 'one') 52 inidir_two = os.path.join(self.wd, 'files', 'multi', 'three') 53 c = Config(inidir_one, override_dirs=[inidir_two]) 54 with self.assertRaises(KeyError): 55 c.process() 56 57 58 def test_multi_schema(self): 59 inidir_one = os.path.join(self.wd, 'files', 'multi_schema', 'foo') 60 inidir_two = os.path.join(self.wd, 'files', 'multi_schema', 'bar') 61 c = Config(inidir_one) 62 c.add_schema_dir(inidir_two) 63 c.process() 64 r = c.get('FOO_BAZ') 65 self.assertEqual(r, '42') 66 r = c.get('XYZZY_SNUH') 67 self.assertEqual(r, '13') 68 69 70 71 if __name__ == '__main__': 72 unittest.main()