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