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')
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)
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
def empty_node(layers): return ConfigNode(layers, name='test_node')
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
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)
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)
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)