コード例 #1
0
def test_write_to_empty_sources():
    source1 = DictSource(auto_subsection=True)
    source2 = DictSource()
    config = StackedConfig(source2, source1)

    config.a = 10
    config['b'].c = 20

    assert source1.a == 10
    assert source1.b.c == 20
    assert source2.dump() == {}
コード例 #2
0
def test_read_source_with_converters():
    data = {'a': 1, 'b': {'c': 2}}
    converter_list = [
        ('a', str, int),
        ('c', lambda v: 2 * v, lambda v: v / 2),
    ]
    config = DictSource(data, converters=converter_list)

    assert config.a == '1'
    assert config.b.c == 4

    assert config.dump() == {'a': '1', 'b': {'c': 4}}