From 1c70a07d7e3fd43cb0dcbf2f5cc89dad93da0b7b Mon Sep 17 00:00:00 2001 From: gwen Date: Mon, 10 Jun 2013 15:19:00 +0200 Subject: [PATCH] transitivity in the requirements --- test/test_requires.py | 38 +++++++++++++++++++++++++++++++++++--- tiramisu/setting.py | 3 +++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/test/test_requires.py b/test/test_requires.py index bcbb01d..3cb9c67 100644 --- a/test/test_requires.py +++ b/test/test_requires.py @@ -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')]) diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 9a9c63a..52c82bf 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -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: