int datatype must not accept fractional floats
- added also test for this Change-Id: I1c3ad92bc10131d6cd096496230222c999f0097e Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/22737 Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
parent
434ef4a423
commit
8c9d5d4e5c
@ -259,8 +259,9 @@ class IntRange(DataType):
|
|||||||
|
|
||||||
def __call__(self, value):
|
def __call__(self, value):
|
||||||
try:
|
try:
|
||||||
|
fvalue = float(value)
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if not (self.min <= value <= self.max) or int(value) != value:
|
if not self.min <= value <= self.max or round(fvalue) != fvalue:
|
||||||
raise BadValueError('%r should be an int between %d and %d' %
|
raise BadValueError('%r should be an int between %d and %d' %
|
||||||
(value, self.min, self.max))
|
(value, self.min, self.max))
|
||||||
return value
|
return value
|
||||||
|
@ -109,8 +109,13 @@ def test_IntRange():
|
|||||||
dt('XX')
|
dt('XX')
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
dt([19, 'X'])
|
dt([19, 'X'])
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
dt(1.3)
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
dt('1.3')
|
||||||
dt(1)
|
dt(1)
|
||||||
dt(0)
|
dt(0)
|
||||||
|
dt('1')
|
||||||
with pytest.raises(ProgrammingError):
|
with pytest.raises(ProgrammingError):
|
||||||
IntRange('xc', 'Yx')
|
IntRange('xc', 'Yx')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user