From: Jeffrey Yasskin Date: Thu, 6 Sep 2007 18:55:17 +0000 (+0000) Subject: Extend unittest's fail*AlmostEqual methods to work on complex numbers. X-Git-Tag: v3.0a2~431 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1cc5544345a6cfbe034f2c804c54660763320220;p=thirdparty%2FPython%2Fcpython.git Extend unittest's fail*AlmostEqual methods to work on complex numbers. --- diff --git a/Lib/unittest.py b/Lib/unittest.py index 7dac499b1621..a023c671d29d 100644 --- a/Lib/unittest.py +++ b/Lib/unittest.py @@ -339,7 +339,7 @@ class TestCase: Note that decimal places (from zero) are usually not the same as significant digits (measured from the most signficant digit). """ - if round(second-first, places) != 0: + if round(abs(second-first), places) != 0: raise self.failureException(msg or '%r != %r within %r places' % (first, second, places)) @@ -351,7 +351,7 @@ class TestCase: Note that decimal places (from zero) are usually not the same as significant digits (measured from the most signficant digit). """ - if round(second-first, places) == 0: + if round(abs(second-first), places) == 0: raise self.failureException(msg or '%r == %r within %r places' % (first, second, places))