adopt to new jsonify of string/blob/arrayof datatyes
+ further fixes Change-Id: I6411a689436ba246bcf572b420ca2a0385b033a2
This commit is contained in:
parent
ba59448442
commit
7a50ff2603
@ -212,10 +212,16 @@ class EnumType(DataType):
|
||||
class BLOBType(DataType):
|
||||
|
||||
def __init__(self, minsize=0, maxsize=None):
|
||||
# if only one arg is given it is maxsize!
|
||||
if maxsize is None and minsize:
|
||||
maxsize = minsize
|
||||
minsize = 0
|
||||
self.minsize = minsize
|
||||
self.maxsize = maxsize
|
||||
if minsize or maxsize:
|
||||
self.as_json = ['blob', minsize, maxsize]
|
||||
if minsize:
|
||||
self.as_json = ['blob', maxsize, minsize]
|
||||
elif maxsize:
|
||||
self.as_json = ['blob', maxsize]
|
||||
else:
|
||||
self.as_json = ['blob']
|
||||
if minsize is not None and maxsize is not None and minsize > maxsize:
|
||||
@ -255,12 +261,17 @@ class StringType(DataType):
|
||||
as_json = ['string']
|
||||
|
||||
def __init__(self, minsize=0, maxsize=None):
|
||||
# if only one arg is given it is maxsize!
|
||||
if maxsize is None and minsize:
|
||||
maxsize = minsize
|
||||
minsize = 0
|
||||
self.as_json = ['string', maxsize]
|
||||
elif maxsize or minsize:
|
||||
self.as_json = ['string', maxsize, minsize]
|
||||
else:
|
||||
self.as_json = ['string']
|
||||
self.minsize = minsize
|
||||
self.maxsize = maxsize
|
||||
if (minsize, maxsize) == (0, None):
|
||||
self.as_json = ['string']
|
||||
else:
|
||||
self.as_json = ['string', minsize, maxsize]
|
||||
if minsize is not None and maxsize is not None and minsize > maxsize:
|
||||
raise ValueError('maxsize must be bigger than minsize!')
|
||||
|
||||
@ -342,7 +353,7 @@ class ArrayOf(DataType):
|
||||
'ArrayOf only works with DataType objs as first argument!')
|
||||
self.subtype = subtype
|
||||
self.as_json = ['array', self.subtype.as_json,
|
||||
self.minsize, self.maxsize]
|
||||
self.maxsize, self.minsize]
|
||||
if self.minsize is not None and self.minsize < 0:
|
||||
raise ValueError('Minimum size must be >= 0!')
|
||||
if self.maxsize is not None and self.maxsize < 1:
|
||||
@ -549,6 +560,8 @@ def get_datatype(json):
|
||||
return json
|
||||
if not isinstance(json, list):
|
||||
import mlzlog
|
||||
if mlzlog.log is None:
|
||||
mlzlog.initLogging('xxxxxxxxx')
|
||||
mlzlog.getLogger('datatypes').warning(
|
||||
"WARNING: invalid datatype specified! trying fallback mechanism. ymmv!")
|
||||
return get_datatype([json])
|
||||
|
@ -199,6 +199,8 @@ class ReadableWidget(QWidget):
|
||||
return params[pname].value
|
||||
try:
|
||||
# if queried, we get the qualifiers as well, but don't want them here
|
||||
import mlzlog
|
||||
mlzlog.getLogger('cached values').warn('no cached value for %s:%s' % (self._module, pname))
|
||||
val = self._node.getParameter(self._module, pname)[0]
|
||||
return val
|
||||
except Exception:
|
||||
|
@ -116,7 +116,7 @@ def test_EnumType():
|
||||
def test_BLOBType():
|
||||
# test constructor catching illegal arguments
|
||||
dt = BLOBType(3, 10)
|
||||
assert dt.as_json == ['blob', 3, 10]
|
||||
assert dt.as_json == ['blob', 10, 3]
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
dt.validate(9)
|
||||
@ -136,7 +136,7 @@ def test_BLOBType():
|
||||
def test_StringType():
|
||||
# test constructor catching illegal arguments
|
||||
dt = StringType(4, 11)
|
||||
assert dt.as_json == ['string', 4, 11]
|
||||
assert dt.as_json == ['string', 11, 4]
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
dt.validate(9)
|
||||
@ -179,7 +179,7 @@ def test_ArrayOf():
|
||||
with pytest.raises(ValueError):
|
||||
ArrayOf(int)
|
||||
dt = ArrayOf(IntRange(-10,10),1,3)
|
||||
assert dt.as_json == ['array', ['int', -10, 10], 1, 3]
|
||||
assert dt.as_json == ['array', ['int', -10, 10], 3, 1]
|
||||
with pytest.raises(ValueError):
|
||||
dt.validate(9)
|
||||
with pytest.raises(ValueError):
|
||||
|
Loading…
x
Reference in New Issue
Block a user