Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_config_dict(self):
config_dict = {
'tool': {'autohooks': {'lorem': 'ipsum'}},
'foo': {'lorem': 'ipsum'},
}
config = Config(config_dict)
self.assertFalse(config.is_empty())
foo_config = config.get('foo')
self.assertFalse(foo_config.is_empty())
self.assertEqual(foo_config.get_value('lorem'), 'ipsum')
self.assertEqual(foo_config.get_value('lorem', 'dolor'), 'ipsum')
self.assertEqual(foo_config.get_value('bar', 'dolor'), 'dolor')
def test_config_point_syntax(self):
config_dict = {
'tool': {'autohooks': {'plugins': {'bar': {'lorem': 'ipsum'}}}}
}
config = Config(config_dict)
self.assertFalse(config.is_empty())
bar_config = config.get('tool', 'autohooks', 'plugins', 'bar')
self.assertFalse(bar_config.is_empty())
self.assertEqual(bar_config.get_value('lorem'), 'ipsum')
def test_empty_config(self):
config = Config()
self.assertTrue(config.is_empty())
bar_config = config.get('foo').get('bar')
self.assertTrue(bar_config.is_empty())
self.assertTrue(config.get_value('foo', True))
self.assertListEqual(config.get_value('foo', ['a']), ['a'])
def __init__(self, config_dict: Dict = None) -> None:
self._config = Config(config_dict)
def get(self, *keys: str) -> 'Config':
config_dict = self._config_dict
for key in keys:
config_dict = config_dict.get(key, {})
return Config(config_dict)