From c2a6772ec2b2622741eb58ff8682b8a8f5245fb2 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 26 Nov 2015 19:42:33 +0100 Subject: [PATCH] impl_get_values with calculated values and no context should return [] --- test/test_choice_option.py | 2 ++ tiramisu/option/baseoption.py | 4 ++++ tiramisu/option/option.py | 21 ++++++++++++--------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/test/test_choice_option.py b/test/test_choice_option.py index f636acc..8565be9 100644 --- a/test/test_choice_option.py +++ b/test/test_choice_option.py @@ -35,6 +35,8 @@ def test_choiceoption_function(): assert cfg.getowner(ch) == owners.default raises(ValueError, "cfg.ch='no'") assert cfg.getowner(ch) == owners.default + assert ch.impl_get_values(None) == [] + assert ch.impl_get_values(cfg) == ['val1', 'val2'] def test_choiceoption_calc_function(): diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index 8629672..3373106 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -782,6 +782,10 @@ class Option(OnlyOption): return DynSymLinkOption(name, self, dyn=path) def _validate_callback(self, callback, callback_params): + """callback_params: + * None + * {'': ((option, permissive),), 'ip': ((None,), (option, permissive)) + """ if callback is None: return default_multi = self.impl_getdefault_multi() diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index 623f668..7b669aa 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -71,15 +71,18 @@ class ChoiceOption(Option): #FIXME cache? but in context... values = self._choice_values if isinstance(values, FunctionType): - values_params = self._choice_values_params - if values_params is None: - values_params = {} - values = carry_out_calculation(self, context=context, - callback=values, - callback_params=values_params) - if not isinstance(values, list): # pragma: optional cover - raise ConfigError(_('calculated values for {0} is not a list' - '').format(self.impl_getname())) + if context is None: + values = [] + else: + values_params = self._choice_values_params + if values_params is None: + values_params = {} + values = carry_out_calculation(self, context=context, + callback=values, + callback_params=values_params) + if not isinstance(values, list): # pragma: optional cover + raise ConfigError(_('calculated values for {0} is not a list' + '').format(self.impl_getname())) return values def _validate(self, value, context=undefined):