Beispiel #1
0
def test_outer_layer_set():
    d = ConfigTree(layers=['inner', 'outer'])
    d._set_with_metadata('test_key', 'test_value', 'inner')
    d._set_with_metadata('test_key', 'test_value2', 'outer')

    d.test_key = 'test_value3'

    assert d.test_key == 'test_value3'
Beispiel #2
0
def test_drop_layer():
    d = ConfigTree(layers=['a', 'b', 'c'])
    d._set_with_metadata('test_key', 'test_value', 'a')
    d._set_with_metadata('test_key', 'test_value2', 'b')
    d._set_with_metadata('test_key', 'test_value3', 'c')

    assert d.test_key == 'test_value3'
    d.drop_layer('c')
    assert d.test_key == 'test_value2'

    with pytest.raises(ValueError):
        d.drop_layer('c')
Beispiel #3
0
def test_reset_layer():
    d = ConfigTree(layers=['a', 'b', 'c'])
    d._set_with_metadata('test_key', 'test_value', 'a')
    d._set_with_metadata('test_key', 'test_value2', 'b')

    assert d.test_key == 'test_value2'
    d.reset_layer('b')
    assert d.test_key == 'test_value'
    d._set_with_metadata('test_key', 'test_value3', 'b')
Beispiel #4
0
def test_outer_layer_set():
    d = ConfigTree(layers=['inner', 'outer'])
    d._set_with_metadata('test_key', 'test_value', 'inner', source=None)
    d._set_with_metadata('test_key', 'test_value3', layer=None, source=None)
    assert d.test_key == 'test_value3'
    assert d['test_key'] == 'test_value3'

    d = ConfigTree(layers=['inner', 'outer'])
    d._set_with_metadata('test_key', 'test_value', 'inner', source=None)
    d.test_key = 'test_value3'
    assert d.test_key == 'test_value3'
    assert d['test_key'] == 'test_value3'

    d = ConfigTree(layers=['inner', 'outer'])
    d._set_with_metadata('test_key', 'test_value', 'inner', source=None)
    d['test_key'] = 'test_value3'
    assert d.test_key == 'test_value3'
    assert d['test_key'] == 'test_value3'
Beispiel #5
0
def test_multiple_layer_get():
    d = ConfigTree(layers=['first', 'second', 'third'])
    d._set_with_metadata('test_key',
                         'test_with_source_value',
                         'first',
                         source=None)
    d._set_with_metadata('test_key', 'test_value2', 'second', source=None)
    d._set_with_metadata('test_key', 'test_value3', 'third', source=None)

    d._set_with_metadata('test_key2', 'test_value4', 'first', source=None)
    d._set_with_metadata('test_key2', 'test_value5', 'second', source=None)

    d._set_with_metadata('test_key3', 'test_value6', 'first', source=None)

    assert d.test_key == 'test_value3'
    assert d.test_key2 == 'test_value5'
    assert d.test_key3 == 'test_value6'
Beispiel #6
0
def test_reset_layer_with_preserved_keys():
    d = ConfigTree(layers=['a', 'b', 'c'])
    d._set_with_metadata('test_key', 'test_value', 'a')
    d._set_with_metadata('test_key2', 'test_value2', 'a')
    d._set_with_metadata('test_key3', 'test_value3', 'a')
    d._set_with_metadata('test_key4', 'test_value4', 'a')
    d._set_with_metadata('test_key', 'test_value5', 'b')
    d._set_with_metadata('test_key2', 'test_value6', 'b')
    d._set_with_metadata('test_key3', 'test_value7', 'b')
    d._set_with_metadata('test_key4', 'test_value8', 'b')

    d.reset_layer('b', preserve_keys=['test_key2', 'test_key3'])
    assert d.test_key == 'test_value'
    assert d.test_key2 == 'test_value6'
    assert d.test_key3 == 'test_value7'
    assert d.test_key4 == 'test_value4'