diff --git a/secop/datatypes.py b/secop/datatypes.py index 883a9d7..e7d1a4d 100644 --- a/secop/datatypes.py +++ b/secop/datatypes.py @@ -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: diff --git a/test/test_datatypes.py b/test/test_datatypes.py index a0bcc59..c5f882b 100644 --- a/test/test_datatypes.py +++ b/test/test_datatypes.py @@ -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