[Python-Dev] unittest assertRaisesRegex bug? (original) (raw)
Thomas Wouters thomas at python.org
Thu Mar 20 00:41:10 CET 2014
- Previous message: [Python-Dev] unittest assertRaisesRegex bug?
- Next message: [Python-Dev] unittest assertRaisesRegex bug?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Mar 19, 2014 at 4:13 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
On 03/19/2014 03:57 PM, Antoine Pitrou wrote:
On Wed, 19 Mar 2014 15:17:53 -0700 Ethan Furman <ethan at stoneleaf.us> wrote:
On 03/19/2014 03:13 PM, Antoine Pitrou wrote:
On Wed, 19 Mar 2014 14:37:42 -0700 Ethan Furman <ethan at stoneleaf.us> wrote:
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: testformatting (test.testunicode.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/testunicode.py", line 1156, in testformatting self.assertRaisesRegex(TypeError, '%c'.mod, pi),
This is certainly not the code you are showing above. More words, please! :) I mean the line shown just above in the traceback does not match the code you presented at the top, and that line clearly has a missing regex pattern. A regex pattern can be a literal, yes? In which case exception -> TypeError regex -> '%x format: an integer is required, not PsuedoFloat' callable -> '%x'.mod *args -> pi **kwargs -> None So, unless you can point to where I've gone wrong with the above (which is why I posted in the first place), I think we have a bug in unittest. Also: self.assertRaisesRegex(TypeError, '%x format: an integer is required, not float','%x'.mod, 3.14), self.assertRaisesRegex(TypeError, '%X format: an integer is required, not float','%X'.mod, 2.11), self.assertRaisesRegex(TypeError, '%o format: an integer is required, not float','%o'.mod, 1.79), these lines all work just fine.
What Antoine is trying to tell you is that the traceback you pasted shows this:
File "/home/ethan/source/python/issue19995/Lib/test/test_unicode.py", line 1156, in test_formatting self.assertRaisesRegex(TypeError, '%c'.mod, pi),
... which is passing '%c'.mod as the 'regex' argument. '%c'.mod is a method of a builtin type, a 'method-wrapper' object, which is why you get the error you're getting: AttributeError: 'method-wrapper' object has no attribute 'search'.
-- Thomas Wouters <thomas at python.org>
Hi! I'm an email virus! Think twice before sending your email to help me spread! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20140319/e6102ab9/attachment-0001.html>
- Previous message: [Python-Dev] unittest assertRaisesRegex bug?
- Next message: [Python-Dev] unittest assertRaisesRegex bug?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]