transitivity in the requirements

This commit is contained in:
gwen 2013-06-10 15:19:00 +02:00
parent 418de157e8
commit 1c70a07d7e
2 changed files with 38 additions and 3 deletions

View file

@ -25,10 +25,11 @@ def test_requires():
assert props == ['disabled']
def test_requires_transitif():
def test_requires_transitive():
a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'disabled')])
d = IPOption('ip_address_service_web', '',
requires=[(b, False, 'disabled')])
od = OptionDescription('service', '', [a, b, d])
@ -54,7 +55,38 @@ def test_requires_transitif():
assert props == ['disabled']
def test_requires_transitif_hidden_disabled():
def test_requires_transitive_bis():
a = BoolOption('activate_service', '', True)
abis = BoolOption('activate_service_bis', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[(a, True, 'disabled', True)])
d = IPOption('ip_address_service_web', '',
requires=[(b, True, 'disabled', True)])
od = OptionDescription('service', '', [a, abis, b, d])
c = Config(od)
c.read_write()
#
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 == ['disabled']
#
props = []
try:
c.ip_address_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
def test_requires_transitive_hidden_disabled():
a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'hidden')])
@ -77,7 +109,7 @@ def test_requires_transitif_hidden_disabled():
raises(RequirementError, 'c.ip_address_service_web')
def test_requires_not_transitif():
def test_requires_not_transitive():
a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'disabled')])

View file

@ -377,6 +377,7 @@ def apply_requires(opt, config):
"{1} {2}").format(opt._name, path, properties), properties)
#transitive action, force expected
value = expected
inverse = False
except AttributeError:
raise AttributeError(_("required option not found: "
"{0}").format(path))
@ -386,6 +387,8 @@ def apply_requires(opt, config):
else:
setting.append(action)
matches = True
# the calculation cannot be carried out
break
# no requirement has been triggered, then just reverse the action
if not matches:
if inverse: