Skip to content
Snippets Groups Projects
Commit 71fa8aca authored by slobinger's avatar slobinger
Browse files

Merge branch '8-muliple-named-configs' into 'master'

Resolve "verschiedene Konfigurationen innerhalb einer Anwednung ermöglichen"

Closes #8

See merge request !4
parents ef3b0fd6 873bc591
No related branches found
No related tags found
1 merge request!4Resolve "verschiedene Konfigurationen innerhalb einer Anwednung ermöglichen"
class ConfigProvider:
_instance = None
_configs = {}
@classmethod
def getInstance(cls):
return ConfigProvider._instance
def getInstance(cls, name = None):
if name is None:
return ConfigProvider._instance
else:
return ConfigProvider._configs.get(name)
def __init__(self, load_function):
def __init__(self, load_function, name = None):
self._conf_dict = load_function['function'](
*load_function.get('args'), **load_function.get('kwargs'))
*load_function.get('args', []), **load_function.get('kwargs',{}))
self._load_function = load_function
ConfigProvider._instance = self
if name is None:
ConfigProvider._instance = self
else:
ConfigProvider._configs[name] = self
@property
def dict(self):
......
......@@ -47,4 +47,14 @@ class TestConfigProvider(unittest.TestCase):
old_dict, self.config.dict, 'old_dict musst not equal self.config.dict')
def test_get_instance(self):
self.assertEqual(config_provider.ConfigProvider.getInstance(), self.config)
def test_multiple_instances(self):
def get_constant_dict():
return {'foo': 'bar'}
config_provider.ConfigProvider(
load_function = {'function': get_constant_dict}, name = 'constant')
self.assertNotEqual(
config_provider.ConfigProvider.getInstance(),
config_provider.ConfigProvider.getInstance(name = 'constant'))
self.assertEqual(config_provider.ConfigProvider.getInstance(), self.config)
\ No newline at end of file
__version__ = '1.0.0'
\ No newline at end of file
__version__ = '1.1.0'
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment