warnings only if needed

This commit is contained in:
2016-11-20 14:32:06 +01:00
parent 42d830687d
commit 0f4b1caca4
3 changed files with 127 additions and 77 deletions

View File

@ -703,3 +703,43 @@ def test_consistency_with_callback():
c.impl_add_consistency('in_network', a, b)
cfg = Config(od)
cfg.c
def test_consistency_double_warnings():
a = IntOption('a', '')
b = IntOption('b', '', 1)
c = IntOption('c', '', 1)
od = OptionDescription('od', '', [a, b, c])
warnings.simplefilter("always", ValueWarning)
a.impl_add_consistency('not_equal', b, warnings_only=True)
a.impl_add_consistency('not_equal', c, warnings_only=True)
cfg = Config(od)
with warnings.catch_warnings(record=True) as w:
cfg.a = 1
assert w != []
assert len(w) == 2
with warnings.catch_warnings(record=True) as w:
cfg.c = 2
assert w == []
with warnings.catch_warnings(record=True) as w:
cfg.a = 2
assert w != []
assert len(w) == 1
cfg.cfgimpl_get_settings().remove('warnings')
with warnings.catch_warnings(record=True) as w:
cfg.a = 1
assert w == []
def test_consistency_warnings_error():
a = IntOption('a', '')
b = IntOption('b', '', 1)
c = IntOption('c', '', 1)
od = OptionDescription('od', '', [a, b, c])
warnings.simplefilter("always", ValueWarning)
a.impl_add_consistency('not_equal', b, warnings_only=True)
a.impl_add_consistency('not_equal', c)
cfg = Config(od)
with warnings.catch_warnings(record=True) as w:
raises(ValueError, "cfg.a = 1")
assert w == []