ability to disable warnings validation
This commit is contained in:
@ -113,6 +113,38 @@ def test_validator_warning():
|
||||
assert str(w[1].message) == _("warning on the value of the option {0}: {1}").format('opt3', 'error')
|
||||
|
||||
|
||||
def test_validator_warning_disabled():
|
||||
opt1 = StrOption('opt1', '', validator=return_true, default='val', warnings_only=True)
|
||||
opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True)
|
||||
opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True)
|
||||
root = OptionDescription('root', '', [opt1, opt2, opt3])
|
||||
cfg = Config(root)
|
||||
cfg.cfgimpl_get_settings().remove('warnings')
|
||||
assert cfg.opt1 == 'val'
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt1 = 'val'
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt2 = 'val'
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt3.append('val')
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt3.append('val1')
|
||||
assert w == []
|
||||
raises(ValueError, "cfg.opt2 = 1")
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt2 = 'val'
|
||||
cfg.opt3.append('val')
|
||||
assert w == []
|
||||
|
||||
|
||||
def test_validator_warning_master_slave():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=return_false, warnings_only=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=return_if_val, warnings_only=True)
|
||||
|
Reference in New Issue
Block a user