mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
226: check_type() and check_isinstance() now return the value; updated corresponding unit tests
This commit is contained in:
parent
2fa8d3be74
commit
5af91df9a5
@ -71,6 +71,7 @@ def check_type(name, type_, value, allow_None=False):
|
|||||||
return
|
return
|
||||||
if type(value) is not type_:
|
if type(value) is not type_:
|
||||||
raise_TypeError(name, type_, value)
|
raise_TypeError(name, type_, value)
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
def check_isinstance(name, type_, value, allow_None=False):
|
def check_isinstance(name, type_, value, allow_None=False):
|
||||||
@ -81,6 +82,7 @@ def check_isinstance(name, type_, value, allow_None=False):
|
|||||||
return
|
return
|
||||||
if not isinstance(value, type_):
|
if not isinstance(value, type_):
|
||||||
raise_TypeError(name, type_, value)
|
raise_TypeError(name, type_, value)
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
class IPAError(Exception):
|
class IPAError(Exception):
|
||||||
|
@ -71,8 +71,8 @@ def test_check_type():
|
|||||||
value = 'How are you?'
|
value = 'How are you?'
|
||||||
|
|
||||||
# Should pass:
|
# Should pass:
|
||||||
f(name, str, value)
|
assert value is f(name, str, value)
|
||||||
f(name, str, None, allow_None=True)
|
assert None is f(name, str, None, allow_None=True)
|
||||||
|
|
||||||
# Should raise TypeError
|
# Should raise TypeError
|
||||||
check_TypeError(f, name, str, None)
|
check_TypeError(f, name, str, None)
|
||||||
@ -104,9 +104,9 @@ def test_check_isinstance():
|
|||||||
value = 'How are you?'
|
value = 'How are you?'
|
||||||
|
|
||||||
# Should pass:
|
# Should pass:
|
||||||
f(name, str, value)
|
assert value is f(name, str, value)
|
||||||
f(name, basestring, value)
|
assert value is f(name, basestring, value)
|
||||||
f(name, str, None, allow_None=True)
|
assert None is f(name, str, None, allow_None=True)
|
||||||
|
|
||||||
# Should raise TypeError
|
# Should raise TypeError
|
||||||
check_TypeError(f, name, str, None)
|
check_TypeError(f, name, str, None)
|
||||||
|
Loading…
Reference in New Issue
Block a user