]> granicus.if.org Git - python/commitdiff
Extend unittest's fail*AlmostEqual methods to work on complex numbers.
authorJeffrey Yasskin <jyasskin@gmail.com>
Thu, 6 Sep 2007 18:55:17 +0000 (18:55 +0000)
committerJeffrey Yasskin <jyasskin@gmail.com>
Thu, 6 Sep 2007 18:55:17 +0000 (18:55 +0000)
Lib/unittest.py

index 7dac499b1621be6f45089a5339833bc946931405..a023c671d29df0bd5e45200fa6f1604c9885dab1 100644 (file)
@@ -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))