226: check_type() and check_isinstance() now return the value; updated corresponding unit tests

This commit is contained in:
Jason Gerard DeRose 2008-09-02 15:15:03 +00:00
parent 2fa8d3be74
commit 5af91df9a5
2 changed files with 7 additions and 5 deletions

View File

@ -71,6 +71,7 @@ def check_type(name, type_, value, allow_None=False):
return
if type(value) is not type_:
raise_TypeError(name, type_, value)
return value
def check_isinstance(name, type_, value, allow_None=False):
@ -81,6 +82,7 @@ def check_isinstance(name, type_, value, allow_None=False):
return
if not isinstance(value, type_):
raise_TypeError(name, type_, value)
return value
class IPAError(Exception):

View File

@ -71,8 +71,8 @@ def test_check_type():
value = 'How are you?'
# Should pass:
f(name, str, value)
f(name, str, None, allow_None=True)
assert value is f(name, str, value)
assert None is f(name, str, None, allow_None=True)
# Should raise TypeError
check_TypeError(f, name, str, None)
@ -104,9 +104,9 @@ def test_check_isinstance():
value = 'How are you?'
# Should pass:
f(name, str, value)
f(name, basestring, value)
f(name, str, None, allow_None=True)
assert value is f(name, str, value)
assert value is f(name, basestring, value)
assert None is f(name, str, None, allow_None=True)
# Should raise TypeError
check_TypeError(f, name, str, None)