This commit is contained in:
2019-02-25 20:30:20 +01:00
parent a248e114de
commit da015d3af0
6 changed files with 57 additions and 13 deletions

View File

@ -264,6 +264,23 @@ def test_config_multi():
assert config.option('test3').value.get() == [2, 1]
def test_prefix_error():
i1 = IntOption('test1', '')
od = OptionDescription('test', '', [i1])
config = Config(od)
config.property.read_write()
config.option('test1').value.set(1)
try:
config.option('test1').value.set('yes')
except Exception as err:
assert str(err) == '"yes" is an invalid integer for "test1"'
try:
config.option('test1').value.set('yes')
except Exception as err:
err.prefix = ''
assert str(err) == 'invalid value'
def test_no_validation():
i1 = IntOption('test1', '')
od = OptionDescription('test', '', [i1])

View File

@ -417,6 +417,7 @@ def test_mandatory_leader():
api = Config(descr)
api.property.read_only()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.value.dict()")
def test_mandatory_warnings_leader():

View File

@ -63,6 +63,12 @@ def test_unknown_config():
raises(ConfigError, "meta.config('unknown')")
def test_error_metaconfig():
od2 = make_description()
conf1 = Config(od2, session_id='conf1')
raises(TypeError, "MetaConfig([GroupConfig([conf1])], session_id='meta')")
def test_path():
meta = make_metaconfig()
assert meta.config.path() == 'meta'

View File

@ -88,6 +88,24 @@ def test_consistency_warnings_only_more_option():
assert len(w) == 1
def test_consistency_error_prefix():
a = IntOption('a', '')
b = IntOption('b', '')
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
api = Config(od)
api.option('a').value.set(1)
try:
api.option('b').value.set(1)
except Exception as err:
assert str(err) == '"1" is an invalid integer for "b", must be different from the value of "a"'
try:
api.option('b').value.set(1)
except Exception as err:
err.prefix = ''
assert str(err) == 'must be different from the value of "a"'
def test_consistency_warnings_only_option():
a = IntOption('a', '')
b = IntOption('b', '', warnings_only=True)