From 0f966f6d2602cf888519de691a78352da8d400a0 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 9 Dec 2013 15:29:37 +0100 Subject: [PATCH] check if permissive is in global properties before allow permissive for an option --- test/test_option_owner.py | 13 ++++- test/test_permissive.py | 116 +++++++++++++++++++++++++++++++++++++- tiramisu/autolib.py | 1 - tiramisu/setting.py | 7 ++- 4 files changed, 131 insertions(+), 6 deletions(-) diff --git a/test/test_option_owner.py b/test/test_option_owner.py index bc96285..b758e91 100644 --- a/test/test_option_owner.py +++ b/test/test_option_owner.py @@ -5,7 +5,7 @@ from tiramisu.setting import owners from tiramisu.config import Config from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \ StrOption, OptionDescription -from tiramisu.error import ConfigError +from tiramisu.error import ConfigError, ConstError def make_description(): @@ -52,6 +52,17 @@ def test_addowner(): assert cfg.getowner(gcdummy) == owners.gen_config +def test_addowner_multiple_time(): + owners.addowner("testowner") + raises(ConstError, 'owners.addowner("testowner")') + + +def test_delete_owner(): + owners.addowner('deleted') + raises(ConstError, 'del(owners.deleted)') + raises(ValueError, 'del(owners.deleted2)') + + def test_owner_is_not_a_string(): gcdummy = BoolOption('dummy', 'dummy', default=False) descr = OptionDescription('tiramisu', '', [gcdummy]) diff --git a/test/test_permissive.py b/test/test_permissive.py index 38a8bcf..20e6535 100644 --- a/test/test_permissive.py +++ b/test/test_permissive.py @@ -9,7 +9,8 @@ from tiramisu.error import PropertiesOptionError def make_description(): u1 = IntOption('u1', '', properties=('frozen', 'mandatory', 'disabled', )) - return OptionDescription('od1', '', [u1]) + u2 = IntOption('u2', '', properties=('frozen', 'mandatory', 'disabled', )) + return OptionDescription('od1', '', [u1, u2]) def test_permissive(): @@ -91,3 +92,116 @@ def test_invalid_permissive(): setting = config.cfgimpl_get_settings() config.read_write() raises(TypeError, "setting.setpermissive(['frozen', 'disabled',])") + + +def test_permissive_option(): + descr = make_description() + u1 = descr.u1 + config = Config(descr) + setting = config.cfgimpl_get_settings() + config.read_write() + + props = [] + try: + config.u1 + except PropertiesOptionError as err: + props = err.proptype + assert props == ['disabled'] + props = [] + try: + config.u2 + except PropertiesOptionError as err: + props = err.proptype + assert props == ['disabled'] + + setting.setpermissive(('disabled',), u1) + props = [] + try: + config.u1 + except PropertiesOptionError as err: + props = err.proptype + assert props == ['disabled'] + props = [] + try: + config.u2 + except PropertiesOptionError as err: + props = err.proptype + assert props == ['disabled'] + + setting.append('permissive') + config.u1 + props = [] + try: + config.u2 + except PropertiesOptionError as err: + props = err.proptype + assert props == ['disabled'] + + setting.remove('permissive') + props = [] + try: + config.u1 + except PropertiesOptionError as err: + props = err.proptype + assert props == ['disabled'] + props = [] + try: + config.u2 + except PropertiesOptionError as err: + props = err.proptype + assert props == ['disabled'] + + +def test_permissive_option_mandatory(): + descr = make_description() + u1 = descr.u1 + config = Config(descr) + setting = config.cfgimpl_get_settings() + config.read_only() + props = [] + try: + config.u1 + except PropertiesOptionError as err: + props = err.proptype + assert set(props) == set(['disabled', 'mandatory']) + setting.setpermissive(('mandatory', 'disabled',), u1) + setting.append('permissive') + config.u1 + setting.remove('permissive') + try: + config.u1 + except PropertiesOptionError as err: + props = err.proptype + assert set(props) == set(['disabled', 'mandatory']) + + +def test_permissive_option_frozen(): + descr = make_description() + config = Config(descr) + u1 = descr.u1 + setting = config.cfgimpl_get_settings() + config.read_write() + setting.setpermissive(('frozen', 'disabled'), u1) + try: + config.u1 = 1 + except PropertiesOptionError as err: + props = err.proptype + assert set(props) == set(['frozen', 'disabled']) + setting.append('permissive') + config.u1 = 1 + assert config.u1 == 1 + setting.remove('permissive') + try: + config.u1 = 1 + except PropertiesOptionError as err: + props = err.proptype + assert set(props) == set(['frozen', 'disabled']) + + +def test_invalid_option_permissive(): + descr = make_description() + u1 = descr.u1 + config = Config(descr) + setting = config.cfgimpl_get_settings() + config.read_write() + raises(TypeError, "setting.setpermissive(['frozen', 'disabled',], u1)") diff --git a/tiramisu/autolib.py b/tiramisu/autolib.py index a176c8d..ffdbb0a 100644 --- a/tiramisu/autolib.py +++ b/tiramisu/autolib.py @@ -243,5 +243,4 @@ def calculate(callback, args, kwargs): :param kwargs: in the callback's arity, the named parameters """ - print args, kwargs, callback(*args, **kwargs) return callback(*args, **kwargs) diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 684ec74..e8feae5 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -406,10 +406,11 @@ class Settings(object): """ # opt properties properties = copy(self._getproperties(opt_or_descr, path)) - # remove opt permissive - properties -= self._p_.getpermissive(path) - # remove global permissive if need self_properties = copy(self._getproperties()) + # remove opt permissive + if force_permissive is True or 'permissive' in self_properties: + properties -= self._p_.getpermissive(path) + # remove global permissive if need if force_permissive is True or 'permissive' in self_properties: properties -= self._p_.getpermissive() if force_permissives is not None: