add test test_symlink_getproperties and test_symlink_getcallback
This commit is contained in:
parent
85857ea781
commit
4b01eb6497
@ -81,6 +81,7 @@ def value_values_index2(value, values, index, auto=False):
|
||||
value == 'val2' and values == ['val1', 'val2'] and index == 'val'):
|
||||
raise ValueError('error')
|
||||
|
||||
|
||||
def value_empty(value, empty, values):
|
||||
if not value == 'val' or empty is not False and not values == ['val']:
|
||||
raise ValueError('error')
|
||||
|
@ -11,6 +11,10 @@ from tiramisu.setting import groups, owners
|
||||
from py.test import raises
|
||||
|
||||
|
||||
def return_value():
|
||||
pass
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
def test_symlink_option():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
@ -31,6 +35,26 @@ def test_symlink_option():
|
||||
assert config.c is False
|
||||
|
||||
|
||||
def test_symlink_getproperties():
|
||||
boolopt = BoolOption('b', '', default=True, properties=('test',))
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == ('test',)
|
||||
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == False
|
||||
|
||||
|
||||
def test_symlink_getcallback():
|
||||
boolopt = BoolOption('b', '', callback=return_value)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == True
|
||||
assert boolopt.impl_get_callback() == linkopt.impl_get_callback() == (return_value, {})
|
||||
|
||||
|
||||
def test_symlink_requires():
|
||||
boolopt = BoolOption('b', '', default=True)
|
||||
stropt = StrOption('s', '', requires=[{'option': boolopt,
|
||||
|
@ -397,7 +397,7 @@ class BaseOption(Base):
|
||||
return getattr(self, '_subdyn', None) is not None
|
||||
|
||||
def _impl_valid_unicode(self, value):
|
||||
if sys.version_info[0] >= 3:
|
||||
if sys.version_info[0] >= 3: # pragma: no cover
|
||||
if not isinstance(value, str):
|
||||
return ValueError(_('invalid string'))
|
||||
else:
|
||||
@ -480,7 +480,7 @@ class Option(OnlyOption):
|
||||
returns_raise=True)
|
||||
if isinstance(opt_value, Exception):
|
||||
if isinstance(opt_value, PropertiesOptionError):
|
||||
if debug:
|
||||
if debug: # pragma: no cover
|
||||
log.debug('propertyerror in _launch_consistency: {0}'.format(opt_value))
|
||||
if transitive:
|
||||
return opt_value
|
||||
@ -508,11 +508,8 @@ class Option(OnlyOption):
|
||||
err = getattr(self, func)(current_opt, all_cons_opts, all_cons_vals, warnings_only)
|
||||
if err:
|
||||
if warnings_only:
|
||||
if isinstance(err, ValueError):
|
||||
msg = _('attention, "{0}" could be an invalid {1} for "{2}", {3}').format(
|
||||
value, self._display_name, current_opt.impl_get_display_name(), err)
|
||||
else:
|
||||
msg = '{}'.format(err)
|
||||
msg = _('attention, "{0}" could be an invalid {1} for "{2}", {3}').format(
|
||||
value, self._display_name, current_opt.impl_get_display_name(), err)
|
||||
warnings.warn_explicit(ValueWarning(msg, self),
|
||||
ValueWarning,
|
||||
self.__class__.__name__, 0)
|
||||
@ -582,7 +579,7 @@ class Option(OnlyOption):
|
||||
# option validation
|
||||
err = self._validate(_value, context, current_opt)
|
||||
if err:
|
||||
if debug:
|
||||
if debug: # pragma: no cover
|
||||
log.debug('do_validation: value: {0}, index: {1}, '
|
||||
'submulti_index: {2}'.format(_value, _index,
|
||||
submulti_index),
|
||||
@ -604,7 +601,7 @@ class Option(OnlyOption):
|
||||
if not error:
|
||||
error = self._second_level_validation(_value, self._is_warnings_only())
|
||||
if error:
|
||||
if debug:
|
||||
if debug: # pragma: no cover
|
||||
log.debug(_('do_validation for {0}: error in value').format(
|
||||
self.impl_getname()), exc_info=True)
|
||||
if self._is_warnings_only():
|
||||
@ -839,7 +836,7 @@ class Option(OnlyOption):
|
||||
else:
|
||||
equal.add(opt_)
|
||||
if equal:
|
||||
if debug:
|
||||
if debug: # pragma: no cover
|
||||
log.debug(_('_cons_not_equal: {} are not different').format(display_list(list(equal))))
|
||||
if is_current:
|
||||
if warnings_only:
|
||||
|
Loading…
Reference in New Issue
Block a user