From 098beb03f40e008e1011d591ea1d07292f5949b2 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 23 Dec 2017 21:18:19 +0100 Subject: [PATCH] add test_option_type --- test/new_api/test_option_type.py | 134 +++++++++++++++++++++++++++++++ tiramisu/value.py | 2 - 2 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 test/new_api/test_option_type.py diff --git a/test/new_api/test_option_type.py b/test/new_api/test_option_type.py new file mode 100644 index 0000000..c55c663 --- /dev/null +++ b/test/new_api/test_option_type.py @@ -0,0 +1,134 @@ +# coding: utf-8 +"frozen and hidden values" +from .autopath import do_autopath +do_autopath() + +from py.test import raises + +from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ + PasswordOption, StrOption, DateOption, OptionDescription, Config, getapi +from tiramisu.error import PropertiesOptionError + + +def make_description(): + gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref') + gcdummy = BoolOption('dummy', 'dummy', default=False, properties=(('hidden'),)) + objspaceoption = ChoiceOption('objspace', 'Object space', + ('std', 'thunk'), ['std'], multi=True) + booloption = BoolOption('bool', 'Test boolean option', default=True) + intoption = IntOption('int', 'Test int option', default=0) + floatoption = FloatOption('float', 'Test float option', default=2.3) + stroption = StrOption('str', 'Test string option', default="abc") + + wantref_option = BoolOption('wantref', 'Test requires', default=False, + requires=({'option': gcoption, 'expected': 'ref', 'action': 'hidden'},)) + wantframework_option = BoolOption('wantframework', 'Test requires', + default=False, + requires=({'option': gcoption, 'expected': 'framework', 'action': 'hidden'},)) + + # ____________________________________________________________ + booloptiontwo = BoolOption('booltwo', 'Test boolean option two', default=False) + subgroup = OptionDescription('subgroup', '', [booloptiontwo]) + # ____________________________________________________________ + + gcgroup = OptionDescription('gc', '', [subgroup, gcoption, gcdummy, floatoption]) + descr = OptionDescription('trs', '', [gcgroup, booloption, objspaceoption, + wantref_option, stroption, + wantframework_option, + intoption]) + return descr + + +# ____________________________________________________________ +def test_is_hidden(): + descr = make_description() + api = getapi(Config(descr)) + api.property.read_write() + assert not 'frozen' in api.option('gc.dummy').property.get() + # setattr + raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == False") + # getattr + raises(PropertiesOptionError, "api.option('gc.dummy').value.get()") + + +def test_group_is_hidden(): + descr = make_description() + api = getapi(Config(descr)) + api.property.read_write() + api.option('gc').property.add('hidden') + raises(PropertiesOptionError, "api.option('gc.dummy').value.get()") + assert 'hidden' in api.option('gc').property.get() + raises(PropertiesOptionError, "api.option('gc.float').value.get()") + # manually set the subconfigs to "show" + api.option('gc').property.pop('hidden') + assert not 'hidden' in api.option('gc').property.get() + assert api.option('gc.float').value.get() == 2.3 + #dummy est en hide + prop = [] + try: + api.option('gc.dummy').value.set(False) + except PropertiesOptionError as err: + prop = err.proptype + assert 'hidden' in prop + + +def test_group_is_hidden_multi(): + descr = make_description() + api = getapi(Config(descr)) + api.property.read_write() + api.option('objspace').property.add('hidden') + raises(PropertiesOptionError, "api.option('objspace').value.get()") + assert 'hidden' in api.option('objspace').property.get() + prop = [] + try: + api.option('objspace').value.set(['std']) + except PropertiesOptionError as err: + prop = err.proptype + assert 'hidden' in prop + api.option('objspace').property.pop('hidden') + assert not 'hidden' in api.option('objspace').property.get() + api.option('objspace').value.set(['std', 'std']) + + +def test_global_show(): + descr = make_description() + api = getapi(Config(descr)) + api.property.read_write() + api.option('gc.dummy').property.add('hidden') + assert 'hidden' in api.option('gc.dummy').property.get() + raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == False") + + +def test_with_many_subgroups(): + descr = make_description() + api = getapi(Config(descr)) + #booltwo = config.unwrap_from_path('gc.subgroup.booltwo') + #setting = config.cfgimpl_get_settings() + assert not 'hidden' in api.option('gc.subgroup.booltwo').property.get() + assert api.option('gc.subgroup.booltwo').value.get() is False + api.option('gc.subgroup.booltwo').property.add('hidden') + + +def test_password_option(): + o = PasswordOption('o', '') + d = OptionDescription('d', '', [o]) + api = getapi(Config(d)) + + api.option('o').value.set('a_valid_password') + raises(ValueError, "api.option('o').value.set(1)") + + +def test_date_option(): + o = DateOption('o', '') + d = OptionDescription('d', '', [o]) + api = getapi(Config(d)) + + api.option('o').value.set('2017-02-04') + api.option('o').value.set('2017-2-4') + raises(ValueError, "api.option('o').value.set(1)") + raises(ValueError, "api.option('o').value.set('2017-13-20')") + raises(ValueError, "api.option('o').value.set('2017-11-31')") + raises(ValueError, "api.option('o').value.set('2017-12-32')") + raises(ValueError, "api.option('o').value.set('2017-2-29')") + raises(ValueError, "api.option('o').value.set('2-2-2017')") + raises(ValueError, "api.option('o').value.set('2017/2/2')") diff --git a/tiramisu/value.py b/tiramisu/value.py index 628610b..fa47d4d 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -78,7 +78,6 @@ class Values(object): :param self_properties: properties for this `Option` :param index: index for a slave `Option` :param display_warnings: display warnings or not - :param trusted_cached_properties: get value from cache but not store it to value :returns: value """ @@ -703,7 +702,6 @@ class Values(object): setting_properties.update(['mandatory', 'empty']) config_bag.setting_properties = frozenset(setting_properties) config_bag.force_permissive = True - config_bag.trusted_cached_properties = False config_bag.display_warnings = False def _mandatory_warnings(description, currpath, config): is_masterslaves = description.is_masterslaves()