[Python-Dev] unittest assertRaisesRegex bug? (original) (raw)
Ethan Furman ethan at stoneleaf.us
Wed Mar 19 22:37:42 CET 2014
- Previous message: [Python-Dev] Making proxy types easier to write and maintain
- Next message: [Python-Dev] unittest assertRaisesRegex bug?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Here's the code in question:
class PsuedoFloat:
def __init__(self, value):
self.value = float(value)
def __int__(self):
return int(self.value)
pi = PsuedoFloat(3.1415)
self.assertRaisesRegex(TypeError, '%x format: an integer is required, not PsuedoFloat', '%x'.__mod__, pi),
Here's the exception:
====================================================================== ERROR: test_formatting (test.test_unicode.UnicodeTest)
TypeError: 'PsuedoFloat' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/home/ethan/source/python/issue19995/Lib/test/test_unicode.py", line 1156, in test_formatting self.assertRaisesRegex(TypeError, '%c'.mod, pi), File "/home/ethan/source/python/issue19995/Lib/unittest/case.py", line 1235, in assertRaisesRegex return context.handle('assertRaisesRegex', callable_obj, args, kwargs) File "/home/ethan/source/python/issue19995/Lib/unittest/case.py", line 161, in handle callable_obj(*args, **kwargs) File "/home/ethan/source/python/issue19995/Lib/unittest/case.py", line 190, in exit if not expected_regex.search(str(exc_value)): AttributeError: 'method-wrapper' object has no attribute 'search'
At worst, I was expecting a difference in the TypeError exception message; I have no idea why pi
is being called.
From the docs:
---- http://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRaisesRegex ---- assertRaisesRegex(exception, regex, callable, *args, **kwds)
Like assertRaises() but also tests that regex matches on the string representation
of the raised exception. regex may be a regular expression object or a string
containing a regular expression suitable for use by re.search(). Examples:
self.assertRaisesRegex(ValueError, "invalid literal for.*XYZ'$", int, 'XYZ')
Am I correct in thinking this is a bug?
--
Ethan
- Previous message: [Python-Dev] Making proxy types easier to write and maintain
- Next message: [Python-Dev] unittest assertRaisesRegex bug?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]