Exemple #1
0
    def test_load_with_configs(self):
        os.environ['key'] = 'value'

        config = ChainConfig(EnvironmentConfig())
        config.load()

        self.assertEqual('value', config['key'])
Exemple #2
0
    def test_get_value_with_overridden_key(self):
        config = ChainConfig(
            MemoryConfig(data={'key': 1}),
            MemoryConfig(data={'key': 2})
        )

        self.assertEqual(2, config.get_value('key', int))
    def test_resolve_with_variable_in_a_composite_config(self):
        config = MemoryConfig()

        root = ChainConfig(MemoryConfig(data={'key': 'value'}),
                           ChainConfig(config))

        self.assertEqual('value',
                         self._interpolator.resolve('${key}', config.lookup))
Exemple #4
0
    def test_updated_trigger(self):
        child = MemoryConfig()

        config = ChainConfig(child)

        passed = []
        config.updated.add(lambda: passed.append(True))

        child.set('key', 'value')

        self.assertEqual(1, len(passed))
Exemple #5
0
    def _create_base_config(self, load_data=False):
        if load_data:
            config = ChainConfig(
                MemoryConfig(data={
                    'key_str': 'value',
                    'key_int': 1,
                    'key_int_as_str': '1',
                    'key_dict': {'key_str': 'value'},
                    'key_dict_as_str': 'item_key=value',
                    'key_list_as_str': 'item1,item2'}),

                MemoryConfig(data={
                    'key_interpolated': '${key_str}',
                    'key_ignore_case': 'value',
                    'key_IGNORE_case': 'value1',
                    'key_delimited': {'key_str': 'value'}})
            )
            config.load()
        else:
            config = ChainConfig()

        return config
Exemple #6
0
    def test_child_lookup(self):
        child = MemoryConfig()

        config = ChainConfig(child)

        self.assertEqual(config.lookup, child.lookup)
Exemple #7
0
 def test_configs_with_list_of_str_as_value(self):
     with self.assertRaises(TypeError):
         ChainConfig(['non config'])
Exemple #8
0
    def test_configs_with_list_of_configs_as_value(self):
        child = MemoryConfig()

        config = ChainConfig(child)

        self.assertEqual(id(child), id(config.configs[0]))
Exemple #9
0
 def test_configs_with_none_as_value(self):
     with self.assertRaises(TypeError):
         ChainConfig(None)