impl_get_values with calculated values and no context should return []
This commit is contained in:
parent
ab555966f7
commit
c2a6772ec2
|
@ -35,6 +35,8 @@ def test_choiceoption_function():
|
||||||
assert cfg.getowner(ch) == owners.default
|
assert cfg.getowner(ch) == owners.default
|
||||||
raises(ValueError, "cfg.ch='no'")
|
raises(ValueError, "cfg.ch='no'")
|
||||||
assert cfg.getowner(ch) == owners.default
|
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():
|
def test_choiceoption_calc_function():
|
||||||
|
|
|
@ -782,6 +782,10 @@ class Option(OnlyOption):
|
||||||
return DynSymLinkOption(name, self, dyn=path)
|
return DynSymLinkOption(name, self, dyn=path)
|
||||||
|
|
||||||
def _validate_callback(self, callback, callback_params):
|
def _validate_callback(self, callback, callback_params):
|
||||||
|
"""callback_params:
|
||||||
|
* None
|
||||||
|
* {'': ((option, permissive),), 'ip': ((None,), (option, permissive))
|
||||||
|
"""
|
||||||
if callback is None:
|
if callback is None:
|
||||||
return
|
return
|
||||||
default_multi = self.impl_getdefault_multi()
|
default_multi = self.impl_getdefault_multi()
|
||||||
|
|
|
@ -71,15 +71,18 @@ class ChoiceOption(Option):
|
||||||
#FIXME cache? but in context...
|
#FIXME cache? but in context...
|
||||||
values = self._choice_values
|
values = self._choice_values
|
||||||
if isinstance(values, FunctionType):
|
if isinstance(values, FunctionType):
|
||||||
values_params = self._choice_values_params
|
if context is None:
|
||||||
if values_params is None:
|
values = []
|
||||||
values_params = {}
|
else:
|
||||||
values = carry_out_calculation(self, context=context,
|
values_params = self._choice_values_params
|
||||||
callback=values,
|
if values_params is None:
|
||||||
callback_params=values_params)
|
values_params = {}
|
||||||
if not isinstance(values, list): # pragma: optional cover
|
values = carry_out_calculation(self, context=context,
|
||||||
raise ConfigError(_('calculated values for {0} is not a list'
|
callback=values,
|
||||||
'').format(self.impl_getname()))
|
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
|
return values
|
||||||
|
|
||||||
def _validate(self, value, context=undefined):
|
def _validate(self, value, context=undefined):
|
||||||
|
|
Loading…
Reference in New Issue