mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
212: Type.__init__() now can also raise TypeError; added unit tests for Type.__init__()
This commit is contained in:
@@ -52,11 +52,11 @@ class Type(ReadOnly):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, type_):
|
def __init__(self, type_):
|
||||||
|
if type(type_) is not type:
|
||||||
|
raise TypeError('%r is not %r' % (type(type_), type))
|
||||||
allowed = (bool, int, float, unicode)
|
allowed = (bool, int, float, unicode)
|
||||||
if type_ not in allowed:
|
if type_ not in allowed:
|
||||||
raise ValueError(
|
raise ValueError('not an allowed type: %r' % type_)
|
||||||
'type_ must be in %r, got %r' % (type_, allowed)
|
|
||||||
)
|
|
||||||
self.type = type_
|
self.type = type_
|
||||||
lock(self)
|
lock(self)
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,24 @@ class test_Type(ClassChecker):
|
|||||||
def test_class(self):
|
def test_class(self):
|
||||||
assert self.cls.__bases__ == (plugable.ReadOnly,)
|
assert self.cls.__bases__ == (plugable.ReadOnly,)
|
||||||
|
|
||||||
|
def test_init(self):
|
||||||
|
okay = (bool, int, float, unicode)
|
||||||
|
for t in okay:
|
||||||
|
o = self.cls(t)
|
||||||
|
assert o.__islocked__() is True
|
||||||
|
assert read_only(o, 'type') is t
|
||||||
|
assert read_only(o, 'name') is 'Type'
|
||||||
|
|
||||||
|
type_errors = (None, True, 8, 8.0, u'hello')
|
||||||
|
for t in type_errors:
|
||||||
|
e = raises(TypeError, self.cls, t)
|
||||||
|
assert str(e) == '%r is not %r' % (type(t), type)
|
||||||
|
|
||||||
|
value_errors = (long, complex, str, tuple, list, dict, set, frozenset)
|
||||||
|
for t in value_errors:
|
||||||
|
e = raises(ValueError, self.cls, t)
|
||||||
|
assert str(e) == 'not an allowed type: %r' % t
|
||||||
|
|
||||||
|
|
||||||
class test_Int(ClassChecker):
|
class test_Int(ClassChecker):
|
||||||
_cls = ipa_types.Int
|
_cls = ipa_types.Int
|
||||||
|
|||||||
Reference in New Issue
Block a user