apply_requires: add property if any property raise PropertyError if same_action is False
This commit is contained in:
parent
755b2312c2
commit
c2471320c3
|
@ -25,6 +25,37 @@ def test_requires():
|
|||
assert props == ['disabled']
|
||||
|
||||
|
||||
def test_requires_same_action():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[(a, False, 'new')])
|
||||
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[(b, False, 'disabled', False, True, False)])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.cfgimpl_get_settings().append('new')
|
||||
c.activate_service
|
||||
c.activate_service_web
|
||||
c.ip_address_service_web
|
||||
c.activate_service = False
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
c.activate_service_web
|
||||
except PropertiesOptionError, err:
|
||||
props = err.proptype
|
||||
assert props == ['new']
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
c.ip_address_service_web
|
||||
except PropertiesOptionError, err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
|
||||
def test_requires_transitive():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
|
|
|
@ -820,7 +820,7 @@ def validate_requires_arg(requires, name):
|
|||
if len(req) == 3:
|
||||
action = req[2]
|
||||
inverse = False
|
||||
elif len(req) in [4, 5]:
|
||||
elif len(req) in [4, 5, 6]:
|
||||
action = req[2]
|
||||
inverse = req[3]
|
||||
else:
|
||||
|
|
|
@ -356,11 +356,16 @@ def apply_requires(opt, config):
|
|||
option, expected, action = require
|
||||
inverse = False
|
||||
transitive = True
|
||||
same_action = True
|
||||
elif len(require) == 4:
|
||||
option, expected, action, inverse = require
|
||||
transitive = True
|
||||
same_action = True
|
||||
elif len(require) == 5:
|
||||
option, expected, action, inverse, transitive = require
|
||||
same_action = True
|
||||
elif len(require) == 6:
|
||||
option, expected, action, inverse, transitive, same_action = require
|
||||
path = descr.impl_get_path_by_opt(option)
|
||||
if path == optpath or path.startswith(optpath + '.'):
|
||||
raise RequirementError(_("malformed requirements "
|
||||
|
@ -372,9 +377,9 @@ def apply_requires(opt, config):
|
|||
if not transitive:
|
||||
continue
|
||||
properties = err.proptype
|
||||
if action not in err.proptype:
|
||||
if same_action and action not in properties:
|
||||
raise RequirementError(_("option '{0}' has requirement's property error: "
|
||||
"{1} {2}").format(opt._name, path, properties), properties)
|
||||
"{1} {2}").format(opt._name, path, properties))
|
||||
#transitive action, force expected
|
||||
value = expected
|
||||
inverse = False
|
||||
|
|
Loading…
Reference in New Issue