From a7ff4a41b4c90441ad78ade59b7df980015a54b3 Mon Sep 17 00:00:00 2001 From: Sebastian Lobinger <sebastian.lobinger@zib.de> Date: Fri, 18 Aug 2017 09:28:39 +0200 Subject: [PATCH] enhance tests to reflect also issue #3 --- test/test_config_provider.py | 42 ++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/test/test_config_provider.py b/test/test_config_provider.py index 3664c88..e2add05 100644 --- a/test/test_config_provider.py +++ b/test/test_config_provider.py @@ -3,7 +3,45 @@ import config_provider class TestConfigProvider(unittest.TestCase): + def setUp(self): + self.dummy_config = { + 'A': 'a', + 'B': 'b'} + def read_dummy_conf(self, **kwargs): + conf_dict = dict(self.dummy_config, **kwargs) + return conf_dict + self.read_function = read_dummy_conf + self.config = config_provider.ConfigProvider( + load_function = { + 'function': self.read_function, 'args': [self], + 'kwargs': {'salt': 'pepper'}}) + def test_init(self): config = config_provider.ConfigProvider( - load_function = dict, foo = 'bar') - self.assertEqual({'foo': 'bar'}, config.dict) \ No newline at end of file + load_function = { + 'function': self.read_function, 'args': [self], + 'kwargs': {'foo': 'bar'}}) + self.assertEqual({'foo': 'bar', 'A': 'a', 'B': 'b'}, config.dict) + + def test_reload(self): + old_dict = dict(self.config.dict) + self.dummy_config = {'A': 'a1', 'B': 'b'} + expected_dict = {'A': 'a1', 'B': 'b', 'salt': 'pepper'} + with self.subTest( + 'before Reload: self.config.dict = ' + str(self.config.dict) + + ' old_dict = ' + str(old_dict) + ' self.dummy_config = ' + + str(self.dummy_config)): + self.assertEqual( + old_dict, self.config.dict, 'old_dict musst equal self.config.dict') + self.assertNotEqual( + self.dummy_config, self.config.dict, + 'self.dummy_config musst not equal self.config.dict') + self.config.reload() + with self.subTest('after Reload: self.config.dict = ' + str(self.config.dict) + + ' old_dict = ' + str(old_dict) + ' self.dummy_config = ' + + str(self.dummy_config)): + self.assertEqual( + expected_dict, self.config.dict, + 'expected_dict musst equal self.config.dict') + self.assertNotEqual( + old_dict, self.config.dict, 'old_dict musst not equal self.config.dict') \ No newline at end of file -- GitLab