|
1 #!/usr/bin/env python3 |
|
2 |
|
3 from pycolib.configparser import ConfigParser, ConfigParserError |
|
4 |
|
5 import unittest |
|
6 import os.path |
|
7 |
|
8 |
|
9 class TestConfigParser(unittest.TestCase): |
|
10 |
|
11 def setUp(self): |
|
12 self.config = ConfigParser() |
|
13 self.config.add_argument('arg_str') |
|
14 self.config.add_argument('arg_int', int, 1) |
|
15 script_path = os.path.dirname(os.path.realpath(__file__)) |
|
16 self.data_path = os.path.join(script_path, 'data') |
|
17 |
|
18 def test_add_argument(self): |
|
19 name = 'argname' |
|
20 self.config.add_argument(name, int, 1) |
|
21 self.assertEqual(self.config.registered_args[name]['type'], int) |
|
22 self.assertEqual(self.config.registered_args[name]['default'], 1) |
|
23 self.assertEqual(self.config.args[name], 1) |
|
24 |
|
25 def test_load_badname(self): |
|
26 self.assertRaises(IOError, self.config.load, 'bad/file_name') |
|
27 |
|
28 def test_load_badargs(self): |
|
29 fname = os.path.join(self.data_path, 'test_badargs.conf') |
|
30 self.assertRaises(ConfigParserError, self.config.load, fname) |
|
31 |
|
32 def test_load_ok(self): |
|
33 fname = os.path.join(self.data_path, 'test_ok.conf') |
|
34 self.config.load(fname) |
|
35 self.assertEqual(self.config.arg_str, '1') |
|
36 self.assertEqual(self.config.arg_int, 2) |
|
37 |
|
38 |
|
39 if __name__ == '__main__': |
|
40 unittest.main() |