From e501c6d12d1aa8be06fb7a4e4d4d8faf726cb1ce Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 28 Jun 2013 11:59:51 +0200 Subject: [PATCH] support multi requires with inverse set to True --- test/test_requires.py | 84 ++++++++++++++++++++++++++++++++++++++++++- tiramisu/setting.py | 16 +++++++-- 2 files changed, 97 insertions(+), 3 deletions(-) diff --git a/test/test_requires.py b/test/test_requires.py index cfad1c3..309a3fd 100644 --- a/test/test_requires.py +++ b/test/test_requires.py @@ -2,7 +2,7 @@ import autopath from tiramisu import setting setting.expires_time = 1 -from tiramisu.option import IPOption, OptionDescription, BoolOption +from tiramisu.option import IPOption, OptionDescription, BoolOption, IntOption from tiramisu.config import Config from tiramisu.error import PropertiesOptionError, RequirementError from py.test import raises @@ -179,3 +179,85 @@ def test_requires_None(): assert props == ['disabled'] c.activate_service = False c.ip_address_service + + +def test_requires_multi_disabled(): + a = BoolOption('activate_service', '') + b = IntOption('num_service', '') + c = IPOption('ip_address_service', '', + requires=[(a, True, 'disabled'), (b, 1, 'disabled')]) + od = OptionDescription('service', '', [a, b, c]) + c = Config(od) + c.read_write() + + c.ip_address_service + + c.activate_service = True + props = [] + try: + c.ip_address_service + except PropertiesOptionError, err: + props = err.proptype + assert props == ['disabled'] + + c.activate_service = False + c.ip_address_service + + c.num_service = 1 + props = [] + try: + c.ip_address_service + except PropertiesOptionError, err: + props = err.proptype + assert props == ['disabled'] + + c.activate_service = True + props = [] + try: + c.ip_address_service + except PropertiesOptionError, err: + props = err.proptype + assert props == ['disabled'] + +def test_requires_multi_disabled_inverse(): + a = BoolOption('activate_service', '') + b = IntOption('num_service', '') + c = IPOption('ip_address_service', '', + requires=[(a, True, 'disabled', True), (b, 1, 'disabled', True)]) + od = OptionDescription('service', '', [a, b, c]) + c = Config(od) + c.read_write() + + props = [] + try: + c.ip_address_service + except PropertiesOptionError, err: + props = err.proptype + assert props == ['disabled'] + + c.activate_service = True + props = [] + try: + c.ip_address_service + except PropertiesOptionError, err: + props = err.proptype + assert props == ['disabled'] + + c.activate_service = False + props = [] + try: + c.ip_address_service + except PropertiesOptionError, err: + props = err.proptype + assert props == ['disabled'] + + c.num_service = 1 + props = [] + try: + c.ip_address_service + except PropertiesOptionError, err: + props = err.proptype + assert props == ['disabled'] + + c.activate_service = True + c.ip_address_service diff --git a/tiramisu/setting.py b/tiramisu/setting.py index ac50e2e..4604a60 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -387,13 +387,25 @@ def apply_requires(opt, config): raise AttributeError(_("required option not found: " "{0}").format(path)) if value == expected: + matches = True if inverse: + #temporary remove, definitive if no value != expected + #matches setting.remove(action) else: setting.append(action) + ## the calculation cannot be carried out + break + if value != expected: matches = True - # the calculation cannot be carried out - break + if inverse: + setting.append(action) + # the calculation cannot be carried out + break + else: + #temporary remove, definitive if no value != expected + #matches + setting.remove(action) # no requirement has been triggered, then just reverse the action if not matches: if inverse: