diff --git a/secop/datatypes.py b/secop/datatypes.py index c1c73ac..8fd0f9e 100644 --- a/secop/datatypes.py +++ b/secop/datatypes.py @@ -339,7 +339,7 @@ class EnumType(DataType): """return the validated (internal) value or raise""" try: return self._enum[value] - except KeyError: + except (KeyError, TypeError): # TypeError will be raised when value is not hashable raise BadValueError(u'%r is not a member of enum %r' % (value, self._enum)) def from_string(self, text): @@ -469,6 +469,10 @@ class TextType(StringType): def __repr__(self): return u'TextType(%d, %d)' % (self.minsize, self.maxsize) + def copy(self): + # DataType.copy will not work, because it is exported as 'string' + return TextType(self.maxsize) + # Bool is a special enum class BoolType(DataType): diff --git a/test/test_datatypes.py b/test/test_datatypes.py index a34bc64..4f1f497 100644 --- a/test/test_datatypes.py +++ b/test/test_datatypes.py @@ -174,7 +174,7 @@ def test_EnumType(): dt(-9) with pytest.raises(ValueError): dt(u'XX') - with pytest.raises(TypeError): + with pytest.raises(ValueError): dt([19, u'X']) assert dt(u'a') == 3