datatypes: fix serialisation for unlimited types
Change-Id: If2d972a35a6da872be8571e27ad4c1156b0a98f4
This commit is contained in:
parent
7e03fd2d9d
commit
50fc67c818
@ -52,7 +52,10 @@ class FloatRange(DataType):
|
||||
self.max = None if max is None else float(max)
|
||||
# note: as we may compare to Inf all comparisons would be false
|
||||
if (self.min or float('-inf')) <= (self.max or float('+inf')):
|
||||
self.as_json = ['double', min, max]
|
||||
if min == None and max == None:
|
||||
self.as_json = ['double']
|
||||
else:
|
||||
self.as_json = ['double', min, max]
|
||||
else:
|
||||
raise ValueError('Max must be larger then min!')
|
||||
|
||||
@ -91,7 +94,10 @@ class IntRange(DataType):
|
||||
self.max = int(max) if max is not None else max
|
||||
if self.min is not None and self.max is not None and self.min > self.max:
|
||||
raise ValueError('Max must be larger then min!')
|
||||
self.as_json = ['int', self.min, self.max]
|
||||
if self.min == None and self.max == None:
|
||||
self.as_json = ['int']
|
||||
else:
|
||||
self.as_json = ['int', self.min, self.max]
|
||||
|
||||
def validate(self, value):
|
||||
try:
|
||||
|
@ -59,6 +59,9 @@ def test_FloatRange():
|
||||
with pytest.raises(ValueError):
|
||||
FloatRange('x','Y')
|
||||
|
||||
dt = FloatRange()
|
||||
assert dt.as_json == ['double']
|
||||
|
||||
def test_IntRange():
|
||||
dt = IntRange(-3, 3)
|
||||
assert dt.as_json == ['int', -3, 3]
|
||||
@ -76,6 +79,8 @@ def test_IntRange():
|
||||
with pytest.raises(ValueError):
|
||||
IntRange('xc','Yx')
|
||||
|
||||
dt = IntRange()
|
||||
assert dt.as_json == ['int']
|
||||
|
||||
def test_EnumType():
|
||||
# test constructor catching illegal arguments
|
||||
|
Loading…
x
Reference in New Issue
Block a user