def test_replace_source_not_found(): source_a = DictConfigSource({}) source_b = DictConfigSource({}) config = Config() config.add_source(source_a) with pytest.raises(ValueError): config.replace_source(source_b, source_a)
def test_replace_source(): sources = [DictConfigSource({}), DictConfigSource({})] config = Config(sources=sources) assert config.config_sources == sources assert config.config_sources[0] is sources[0] assert config.config_sources[1] is sources[1] replacement_source = DictConfigSource({}) config.replace_source(sources[0], replacement_source) assert config.config_sources == [replacement_source, sources[1]] assert config.config_sources[0] is replacement_source assert config.config_sources[1] is sources[1]
def test_replace_source_bad_type(): source = DictConfigSource({}) config = Config(sources=[source]) with pytest.raises(TypeError): bad_type: ConfigSource = 3 config.replace_source(source, bad_type)