tests/test_configparser.py
changeset 3 cc27136cdead
child 4 fdaa7dc9035e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_configparser.py	Sat Apr 06 00:07:17 2013 +0200
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+
+from pycolib.configparser import ConfigParser, ConfigParserError
+
+import unittest
+import os.path
+
+
+class TestConfigParser(unittest.TestCase):
+
+    def setUp(self):
+        self.config = ConfigParser()
+        self.config.add_argument('arg_str')
+        self.config.add_argument('arg_int', int, 1)
+        script_path = os.path.dirname(os.path.realpath(__file__))
+        self.data_path = os.path.join(script_path, 'data')
+
+    def test_add_argument(self):
+        name = 'argname'
+        self.config.add_argument(name, int, 1)
+        self.assertEqual(self.config.registered_args[name]['type'], int)
+        self.assertEqual(self.config.registered_args[name]['default'], 1)
+        self.assertEqual(self.config.args[name], 1)
+
+    def test_load_badname(self):
+        self.assertRaises(IOError, self.config.load, 'bad/file_name')
+
+    def test_load_badargs(self):
+        fname = os.path.join(self.data_path, 'test_badargs.conf')
+        self.assertRaises(ConfigParserError, self.config.load, fname)
+
+    def test_load_ok(self):
+        fname = os.path.join(self.data_path, 'test_ok.conf')
+        self.config.load(fname)
+        self.assertEqual(self.config.arg_str, '1')
+        self.assertEqual(self.config.arg_int, 2)
+
+
+if __name__ == '__main__':
+    unittest.main()