add test test_symlink_getproperties and test_symlink_getcallback

This commit is contained in:
Emmanuel Garette 2017-01-26 21:55:10 +01:00
parent 85857ea781
commit 4b01eb6497
3 changed files with 32 additions and 10 deletions

View File

@ -81,6 +81,7 @@ def value_values_index2(value, values, index, auto=False):
value == 'val2' and values == ['val1', 'val2'] and index == 'val'): value == 'val2' and values == ['val1', 'val2'] and index == 'val'):
raise ValueError('error') raise ValueError('error')
def value_empty(value, empty, values): def value_empty(value, empty, values):
if not value == 'val' or empty is not False and not values == ['val']: if not value == 'val' or empty is not False and not values == ['val']:
raise ValueError('error') raise ValueError('error')

View File

@ -11,6 +11,10 @@ from tiramisu.setting import groups, owners
from py.test import raises from py.test import raises
def return_value():
pass
#____________________________________________________________ #____________________________________________________________
def test_symlink_option(): def test_symlink_option():
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
@ -31,6 +35,26 @@ def test_symlink_option():
assert config.c is False 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(): def test_symlink_requires():
boolopt = BoolOption('b', '', default=True) boolopt = BoolOption('b', '', default=True)
stropt = StrOption('s', '', requires=[{'option': boolopt, stropt = StrOption('s', '', requires=[{'option': boolopt,

View File

@ -397,7 +397,7 @@ class BaseOption(Base):
return getattr(self, '_subdyn', None) is not None return getattr(self, '_subdyn', None) is not None
def _impl_valid_unicode(self, value): 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): if not isinstance(value, str):
return ValueError(_('invalid string')) return ValueError(_('invalid string'))
else: else:
@ -480,7 +480,7 @@ class Option(OnlyOption):
returns_raise=True) returns_raise=True)
if isinstance(opt_value, Exception): if isinstance(opt_value, Exception):
if isinstance(opt_value, PropertiesOptionError): if isinstance(opt_value, PropertiesOptionError):
if debug: if debug: # pragma: no cover
log.debug('propertyerror in _launch_consistency: {0}'.format(opt_value)) log.debug('propertyerror in _launch_consistency: {0}'.format(opt_value))
if transitive: if transitive:
return opt_value return opt_value
@ -508,11 +508,8 @@ class Option(OnlyOption):
err = getattr(self, func)(current_opt, all_cons_opts, all_cons_vals, warnings_only) err = getattr(self, func)(current_opt, all_cons_opts, all_cons_vals, warnings_only)
if err: if err:
if warnings_only: if warnings_only:
if isinstance(err, ValueError):
msg = _('attention, "{0}" could be an invalid {1} for "{2}", {3}').format( msg = _('attention, "{0}" could be an invalid {1} for "{2}", {3}').format(
value, self._display_name, current_opt.impl_get_display_name(), err) value, self._display_name, current_opt.impl_get_display_name(), err)
else:
msg = '{}'.format(err)
warnings.warn_explicit(ValueWarning(msg, self), warnings.warn_explicit(ValueWarning(msg, self),
ValueWarning, ValueWarning,
self.__class__.__name__, 0) self.__class__.__name__, 0)
@ -582,7 +579,7 @@ class Option(OnlyOption):
# option validation # option validation
err = self._validate(_value, context, current_opt) err = self._validate(_value, context, current_opt)
if err: if err:
if debug: if debug: # pragma: no cover
log.debug('do_validation: value: {0}, index: {1}, ' log.debug('do_validation: value: {0}, index: {1}, '
'submulti_index: {2}'.format(_value, _index, 'submulti_index: {2}'.format(_value, _index,
submulti_index), submulti_index),
@ -604,7 +601,7 @@ class Option(OnlyOption):
if not error: if not error:
error = self._second_level_validation(_value, self._is_warnings_only()) error = self._second_level_validation(_value, self._is_warnings_only())
if error: if error:
if debug: if debug: # pragma: no cover
log.debug(_('do_validation for {0}: error in value').format( log.debug(_('do_validation for {0}: error in value').format(
self.impl_getname()), exc_info=True) self.impl_getname()), exc_info=True)
if self._is_warnings_only(): if self._is_warnings_only():
@ -839,7 +836,7 @@ class Option(OnlyOption):
else: else:
equal.add(opt_) equal.add(opt_)
if equal: if equal:
if debug: if debug: # pragma: no cover
log.debug(_('_cons_not_equal: {} are not different').format(display_list(list(equal)))) log.debug(_('_cons_not_equal: {} are not different').format(display_list(list(equal))))
if is_current: if is_current:
if warnings_only: if warnings_only: