コード例 #1
0
def test_set_sources():
    old_sources = [DictConfigSource({})]
    new_sources = [DictConfigSource({}), DictConfigSource({})]
    config = Config(sources=old_sources)
    config.set_sources(new_sources)
    assert len(config.config_sources) == 2
    assert config.config_sources[0] is new_sources[0]
    assert config.config_sources[1] is new_sources[1]
コード例 #2
0
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]
コード例 #3
0
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)
コード例 #4
0
def test_add_source():
    c = Config()
    with pytest.raises(TypeError):
        bad_type: ConfigSource = 3
        c.add_source(bad_type)

    assert len(c.config_sources) == 0
    new_source = DictConfigSource({})
    c.add_source(new_source)
    assert len(c.config_sources) == 1
    assert c.config_sources[-1] is new_source
コード例 #5
0
def test_init_with_sources():
    c = Config(sources=[
        DictConfigSource({}),
        DictConfigSource({})
    ])
    assert 2 == len(c.config_sources)
コード例 #6
0
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)