apply_requires: add property if any property raise PropertyError if same_action is False

This commit is contained in:
Emmanuel Garette 2013-06-13 14:43:51 +02:00
parent 755b2312c2
commit c2471320c3
3 changed files with 39 additions and 3 deletions

View File

@ -25,6 +25,37 @@ def test_requires():
assert props == ['disabled'] 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(): def test_requires_transitive():
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,

View File

@ -820,7 +820,7 @@ def validate_requires_arg(requires, name):
if len(req) == 3: if len(req) == 3:
action = req[2] action = req[2]
inverse = False inverse = False
elif len(req) in [4, 5]: elif len(req) in [4, 5, 6]:
action = req[2] action = req[2]
inverse = req[3] inverse = req[3]
else: else:

View File

@ -356,11 +356,16 @@ def apply_requires(opt, config):
option, expected, action = require option, expected, action = require
inverse = False inverse = False
transitive = True transitive = True
same_action = True
elif len(require) == 4: elif len(require) == 4:
option, expected, action, inverse = require option, expected, action, inverse = require
transitive = True transitive = True
same_action = True
elif len(require) == 5: elif len(require) == 5:
option, expected, action, inverse, transitive = require 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) path = descr.impl_get_path_by_opt(option)
if path == optpath or path.startswith(optpath + '.'): if path == optpath or path.startswith(optpath + '.'):
raise RequirementError(_("malformed requirements " raise RequirementError(_("malformed requirements "
@ -372,9 +377,9 @@ def apply_requires(opt, config):
if not transitive: if not transitive:
continue continue
properties = err.proptype 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: " 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 #transitive action, force expected
value = expected value = expected
inverse = False inverse = False