diff --git a/test/test_option.py b/test/test_option.py index e7039dd..4b77356 100644 --- a/test/test_option.py +++ b/test/test_option.py @@ -120,3 +120,16 @@ def test_asign_optiondescription(): api = Config(od2) raises(APIError, "api.option('od').value.set('test')") raises(APIError, "api.option('od').value.reset()") + + +def test_intoption(): + i1 = IntOption('test1', 'description', min_number=3) + i2 = IntOption('test2', 'description', max_number=3) + od = OptionDescription('od', '', [i1, i2]) + cfg = Config(od) + raises(ValueError, "cfg.option('test1').value.set(2)") + cfg.option('test1').value.set(3) + cfg.option('test1').value.set(4) + cfg.option('test2').value.set(2) + cfg.option('test2').value.set(3) + raises(ValueError, "cfg.option('test2').value.set(4)") diff --git a/tiramisu/option/intoption.py b/tiramisu/option/intoption.py index b895502..ec48b9e 100644 --- a/tiramisu/option/intoption.py +++ b/tiramisu/option/intoption.py @@ -39,7 +39,7 @@ class IntOption(Option): if min_number is not None: extra['min_number'] = min_number if max_number is not None: - extra['max_number'] = min_number + extra['max_number'] = max_number super().__init__(name, extra=extra, *args, **kwargs) @@ -50,8 +50,8 @@ class IntOption(Option): if not isinstance(value, int): raise ValueError() min_number = self._get_extra('min_number') - if min_number and value < min_number: + if min_number is not None and value < min_number: raise ValueError(_('value must be greater than "{0}"'.format(min_number))) max_number = self._get_extra('max_number') - if max_number and value > max_number: + if max_number is not None and value > max_number: raise ValueError(_('value must be less than "{0}"'.format(max_number)))