don't display warning in mandatory_warnings

This commit is contained in:
2016-10-14 21:31:39 +02:00
parent 2e4fdbca03
commit 24ec5a9112
5 changed files with 58 additions and 45 deletions

View File

@ -400,7 +400,6 @@ def test_mandatory_warnings_ro():
config.str = 'a'
config.read_only()
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
assert list(config.cfgimpl_get_values().mandatory_warnings(force_permissive=True)) == ['str1', 'unicode2', 'str3']
try:
delete_session('config', config.impl_getsessionid())
except ValueError:
@ -417,7 +416,6 @@ def test_mandatory_warnings_rw():
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
config.str = 'a'
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
assert list(config.cfgimpl_get_values().mandatory_warnings(force_permissive=True)) == ['str1', 'unicode2', 'str3']
try:
delete_session('config', 'man100')
except ValueError:
@ -435,7 +433,6 @@ def test_mandatory_warnings_disabled():
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
setting[descr.str].append('disabled')
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
assert list(config.cfgimpl_get_values().mandatory_warnings(force_permissive=True)) == ['str1', 'unicode2', 'str3']
try:
delete_session('config', 'man101')
except ValueError:
@ -453,8 +450,7 @@ def test_mandatory_warnings_hidden():
config.str
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
setting[descr.str].append('hidden')
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
assert list(config.cfgimpl_get_values().mandatory_warnings(force_permissive=True)) == ['str', 'str1', 'unicode2', 'str3']
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
try:
delete_session('config', 'man102')
except ValueError:
@ -673,10 +669,8 @@ def test_mandatory_warnings_validate():
config = Config(descr, session_id='man111')
config.str = ''
raises(ValueError, "list(config.cfgimpl_get_values().mandatory_warnings())")
assert list(config.cfgimpl_get_values().mandatory_warnings(validate=False)) == ['str', 'str1', 'str3', 'unicode1', 'int1']
config.str = 'test'
raises(ValueError, "list(config.cfgimpl_get_values().mandatory_warnings())")
assert list(config.cfgimpl_get_values().mandatory_warnings(validate=False)) == ['str1', 'str3']
try:
delete_session('config', 'man111')
except ValueError:
@ -689,8 +683,7 @@ def test_mandatory_warnings_validate_empty():
config = Config(descr, session_id='man112')
config.str = ''
config.read_only()
raises(ConfigError, "list(config.cfgimpl_get_values().mandatory_warnings())")
assert list(config.cfgimpl_get_values().mandatory_warnings(validate=False)) == ['str', 'str1', 'str3', 'unicode1']
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'str3', 'unicode1']
try:
delete_session('config', 'man112')
except ValueError:

View File

@ -477,7 +477,7 @@ def test_callback_master_and_slaves_master4():
cfg.read_write()
cfg.cfgimpl_get_settings().append('expert')
cfg.cfgimpl_get_settings().setpermissive(('expert',))
assert list(cfg.cfgimpl_get_values().mandatory_warnings(force_permissive=True)) == []
assert list(cfg.cfgimpl_get_values().mandatory_warnings()) == []
def test_consistency_master_and_slaves_master_mandatory_transitive():
@ -498,7 +498,7 @@ def test_consistency_master_and_slaves_master_mandatory_transitive():
cfg.read_write()
raises(PropertiesOptionError, "cfg.val1.val1")
raises(PropertiesOptionError, "cfg.val3.val3")
assert list(cfg.cfgimpl_get_values().mandatory_warnings(force_permissive=True)) == []
assert list(cfg.cfgimpl_get_values().mandatory_warnings()) == []
def test_consistency_master_and_slaves_master_mandatory_non_transitive():
@ -517,7 +517,7 @@ def test_consistency_master_and_slaves_master_mandatory_non_transitive():
maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
cfg = Config(maconfig)
cfg.read_write()
assert list(cfg.cfgimpl_get_values().mandatory_warnings(force_permissive=True)) == ["val1.val1"]
assert list(cfg.cfgimpl_get_values().mandatory_warnings()) == ["val1.val1"]
def test_callback_master_and_slaves_master_list():

View File

@ -551,6 +551,24 @@ def test_consistency_broadcast_error():
raises(ConfigError, "c.a = ['192.168.1.0']")
def test_consistency_broadcast_warnings():
warnings.simplefilter("always", ValueWarning)
a = NetworkOption('a', '', properties=('mandatory', 'disabled'))
b = NetmaskOption('b', '', properties=('mandatory', 'disabled'))
c = NetmaskOption('c', '', properties=('mandatory', 'disabled'))
od = OptionDescription('a', '', [a, b, c])
b.impl_add_consistency('network_netmask', a, warnings_only=True)
c = Config(od)
with warnings.catch_warnings(record=True) as w:
c.a = '192.168.1.4'
c.b = '255.255.255.0'
assert len(w) == 1
c.read_write()
with warnings.catch_warnings(record=True) as w:
list(c.cfgimpl_get_values().mandatory_warnings())
assert len(w) == 0
def test_consistency_broadcast_default_1():
a = NetworkOption('a', '', '192.168.1.0')
b = NetmaskOption('b', '', '255.255.255.128')