test min/max value in IntOption

This commit is contained in:
Emmanuel Garette 2018-09-11 20:12:06 +02:00
parent c80adedc02
commit f779c8f36d
2 changed files with 16 additions and 3 deletions

View file

@ -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)")

View file

@ -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)))