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'
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')
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')
def test_multiple_layer_get():
    d = ConfigTree(layers=['first', 'second', 'third'])
    d.set_with_metadata('test_key', 'test_value', 'first')
    d.set_with_metadata('test_key', 'test_value2', 'second')
    d.set_with_metadata('test_key', 'test_value3', 'third')

    d.set_with_metadata('test_key2', 'test_value4', 'first')
    d.set_with_metadata('test_key2', 'test_value5', 'second')

    d.set_with_metadata('test_key3', 'test_value6', 'first')

    assert d.test_key == 'test_value3'
    assert d.test_key2 == 'test_value5'
    assert d.test_key3 == 'test_value6'
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'