mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-23 15:40:01 -06:00
222: Fixed broken assertion in IPATypeError; did more work on docstrings in same
This commit is contained in:
parent
8dc0e263da
commit
03daa91d1c
@ -24,18 +24,22 @@ All custom errors raised by `ipalib` package.
|
||||
|
||||
class IPATypeError(TypeError):
|
||||
"""
|
||||
TypeError subclass with standard message for easier debugging.
|
||||
A TypeError subclass with with a standard message.
|
||||
|
||||
Also has two custom attributes:
|
||||
|
||||
``type`` - The type being tested against.
|
||||
``value`` - The offending value that caused the exception.
|
||||
|
||||
There is no edict that all TypeError should be raised with IPATypeError,
|
||||
but when it fits, use it... it makes the unit tests faster to write and
|
||||
the debugging easier to read.
|
||||
"""
|
||||
|
||||
format = 'need a %r; got %r'
|
||||
|
||||
def __init__(self, type_, value):
|
||||
assert type(value) is not type, 'no error: %r, %r' % (type_, value)
|
||||
assert type(value) is not type_, '%r is a %r' % (value, type_)
|
||||
self.type = type_
|
||||
self.value = value
|
||||
TypeError.__init__(self, self.format % (self.type, self.value))
|
||||
|
@ -21,7 +21,7 @@
|
||||
Unit tests for `ipalib.errors` module.
|
||||
"""
|
||||
|
||||
from tstutil import raises, getitem, no_set, no_del, read_only, ClassChecker
|
||||
from tstutil import raises, ClassChecker
|
||||
from ipalib import errors
|
||||
|
||||
|
||||
@ -38,9 +38,14 @@ class test_IPATypeError(ClassChecker):
|
||||
"""
|
||||
Tests the `errors.IPATypeError.__init__` method.
|
||||
"""
|
||||
t = unicode
|
||||
v = 'hello'
|
||||
e = self.cls(t, v)
|
||||
assert e.type is t
|
||||
assert e.value is v
|
||||
assert str(e) == 'need a %r; got %r' % (t, v)
|
||||
type_ = unicode
|
||||
okay = 'hello'
|
||||
e = self.cls(type_, okay)
|
||||
assert e.type is type_
|
||||
assert e.value is okay
|
||||
assert str(e) == 'need a %r; got %r' % (type_, okay)
|
||||
|
||||
# Check that AssertionError is raised when type(value) is type_:
|
||||
fail = u'hello'
|
||||
e = raises(AssertionError, self.cls, type_, fail)
|
||||
assert str(e) == '%r is a %r' % (fail, type_)
|
||||
|
Loading…
Reference in New Issue
Block a user