From 4636a977cc9e46fa941d1b32b16a7d668f5ddc35 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 2 Sep 2013 17:13:07 +0200 Subject: [PATCH] requirements: calculate all requirements for an option --- test/test_requires.py | 24 ++++++++++++++++++++++++ tiramisu/option.py | 9 ++++++--- tiramisu/setting.py | 10 +++++----- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/test/test_requires.py b/test/test_requires.py index 0f9af61..3d386d7 100644 --- a/test/test_requires.py +++ b/test/test_requires.py @@ -88,6 +88,30 @@ def test_multiple_requires(): c.ip_address_service +def test_multiple_requires_cumulative(): + a = StrOption('activate_service', '') + b = IPOption('ip_address_service', '', + requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'}, + {'option': a, 'expected': 'yes', 'action': 'hidden'}]) + od = OptionDescription('service', '', [a, b]) + c = Config(od) + c.read_write() + c.ip_address_service + c.activate_service = 'yes' + props = [] + try: + c.ip_address_service + except PropertiesOptionError as err: + props = err.proptype + assert set(props) == set(['hidden', 'disabled']) + + c.activate_service = 'ok' + c.ip_address_service + + c.activate_service = 'no' + c.ip_address_service + + def test_multiple_requires_inverse(): a = StrOption('activate_service', '') b = IPOption('ip_address_service', '', diff --git a/tiramisu/option.py b/tiramisu/option.py index c1c949f..ff50ea2 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -1045,6 +1045,8 @@ def validate_requires_arg(requires, name): ret_requires = {} config_action = {} + # start parsing all requires given by user (has dict) + # transforme it to a tuple for require in requires: if not type(require) == dict: raise ValueError(_("malformed requirements type for option:" @@ -1058,6 +1060,7 @@ def validate_requires_arg(requires, name): '{2}'.format(name, unknown_keys, valid_keys)) + # prepare all attributes try: option = require['option'] expected = require['expected'] @@ -1106,12 +1109,12 @@ def validate_requires_arg(requires, name): inverse, transitive, same_action) else: ret_requires[action][option][1].append(expected) + # transform dict to tuple ret = [] for opt_requires in ret_requires.values(): ret_action = [] for require in opt_requires.values(): - req = (require[0], tuple(require[1]), require[2], require[3], - require[4], require[5]) - ret_action.append(req) + ret_action.append((require[0], tuple(require[1]), require[2], + require[3], require[4], require[5])) ret.append(tuple(ret_action)) return frozenset(config_action.keys()), tuple(ret) diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 879656c..46741b5 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -402,11 +402,11 @@ class Settings(object): def setpermissive(self, permissive, opt=None, path=None): """ enables us to put the permissives in the storage - - :param path: the option's path + + :param path: the option's path :param type: str - :param opt: if an option object is set, the path is extracted. - it is better (faster) to set the path parameter + :param opt: if an option object is set, the path is extracted. + it is better (faster) to set the path parameter instead of passing a :class:`tiramisu.option.Option()` object. """ if opt is not None and path is None: @@ -527,7 +527,7 @@ class Settings(object): calc_properties.add(action) # the calculation cannot be carried out break - return calc_properties + return calc_properties def _get_opt_path(self, opt): return self.context().cfgimpl_get_description().impl_get_path_by_opt(opt)