From 4b01eb6497e5dee2700861096fc4a448c998c29d Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 26 Jan 2017 21:55:10 +0100 Subject: [PATCH] add test test_symlink_getproperties and test_symlink_getcallback --- test/test_option_validator.py | 1 + test/test_symlink.py | 24 ++++++++++++++++++++++++ tiramisu/option/baseoption.py | 17 +++++++---------- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/test/test_option_validator.py b/test/test_option_validator.py index df44b9c..0d35f1e 100644 --- a/test/test_option_validator.py +++ b/test/test_option_validator.py @@ -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') diff --git a/test/test_symlink.py b/test/test_symlink.py index 648d752..765f50a 100644 --- a/test/test_symlink.py +++ b/test/test_symlink.py @@ -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, diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index 0c5ed6a..b4883a2 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -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: