예제 #1
0
def test_node_update_no_args():
    n = ConfigNode(['base'], name='test_node')
    n.update('test_value', layer=None, source=None)
    assert n._values['base'] == (None, 'test_value')

    n = ConfigNode(['layer_1', 'layer_2'], name='test_node')
    n.update('test_value', layer=None, source=None)
    assert 'layer_1' not in n._values
    assert n._values['layer_2'] == (None, 'test_value')
예제 #2
0
def test_node_frozen_update():
    n = ConfigNode(['base'], name='test_node')
    n.freeze()
    with pytest.raises(ConfigurationError):
        n.update('test_val', layer=None, source=None)
예제 #3
0
def full_node(layers_and_values):
    n = ConfigNode(list(layers_and_values.keys()), name='test_node')
    for layer, value in layers_and_values.items():
        n.update(value, layer, source=None)
    return n
예제 #4
0
def empty_node(layers):
    return ConfigNode(layers, name='test_node')
예제 #5
0
def test_node_str():
    n = ConfigNode(['base'], name='test_node')
    n.update('test_value', layer='base', source='test')
    s = 'base: test_value'
    assert str(n) == s

    n = ConfigNode(['base', 'layer_1'], name='test_node')
    n.update('test_value', layer='base', source='test')
    s = 'base: test_value'
    assert str(n) == s

    n = ConfigNode(['base', 'layer_1'], name='test_node')
    n.update('test_value', layer=None, source='test')
    s = 'layer_1: test_value'
    assert str(n) == s

    n = ConfigNode(['base', 'layer_1'], name='test_node')
    n.update('test_value', layer='base', source='test')
    n.update('test_value', layer='layer_1', source='test')
    s = 'layer_1: test_value'
    assert str(n) == s
예제 #6
0
def test_node_repr():
    n = ConfigNode(['base'], name='test_node')
    n.update('test_value', layer='base', source='test')
    s = '''\
        base: test_value
            source: test'''
    assert repr(n) == textwrap.dedent(s)

    n = ConfigNode(['base', 'layer_1'], name='test_node')
    n.update('test_value', layer='base', source='test')
    s = '''\
        base: test_value
            source: test'''
    assert repr(n) == textwrap.dedent(s)

    n = ConfigNode(['base', 'layer_1'], name='test_node')
    n.update('test_value', layer=None, source='test')
    s = '''\
        layer_1: test_value
            source: test'''
    assert repr(n) == textwrap.dedent(s)

    n = ConfigNode(['base', 'layer_1'], name='test_node')
    n.update('test_value', layer='base', source='test')
    n.update('test_value', layer='layer_1', source='test')
    s = '''\
        layer_1: test_value
            source: test
        base: test_value
            source: test'''
    assert repr(n) == textwrap.dedent(s)
예제 #7
0
def test_node_duplicate_update():
    n = ConfigNode(['base'], name='test_node')
    n.update('test_value', layer=None, source=None)
    with pytest.raises(DuplicatedConfigurationError):
        n.update('test_value', layer=None, source=None)
예제 #8
0
def test_node_bad_layer_update():
    n = ConfigNode(['base'], name='test_node')
    with pytest.raises(ConfigurationKeyError):
        n.update('test_value', layer='layer_1', source=None)