diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_unittest.py | 5 | ||||
-rw-r--r-- | Lib/unittest/case.py | 10 |
2 files changed, 14 insertions, 1 deletions
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py index 5c3921d..2fab7de 100644 --- a/Lib/test/test_unittest.py +++ b/Lib/test/test_unittest.py @@ -2989,6 +2989,11 @@ class Test_Assertions(TestCase): self.assertRaises(self.failureException, self.assertNotAlmostEqual, 0, .1+.1j, places=0) + self.assertAlmostEqual(float('inf'), float('inf')) + self.assertRaises(self.failureException, self.assertNotAlmostEqual, + float('inf'), float('inf')) + + def test_assertRaises(self): def _raise(e): raise e diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index d52bc8d..cac2842 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -457,7 +457,13 @@ class TestCase(object): Note that decimal places (from zero) are usually not the same as significant digits (measured from the most signficant digit). + + If the two objects compare equal then they will automatically + compare almost equal. """ + if first == second: + # shortcut for ite + return if round(abs(second-first), places) != 0: standardMsg = '%r != %r within %r places' % (first, second, places) msg = self._formatMessage(msg, standardMsg) @@ -470,8 +476,10 @@ class TestCase(object): Note that decimal places (from zero) are usually not the same as significant digits (measured from the most signficant digit). + + Objects that are equal automatically fail. """ - if round(abs(second-first), places) == 0: + if (first == second) or round(abs(second-first), places) == 0: standardMsg = '%r == %r within %r places' % (first, second, places) msg = self._formatMessage(msg, standardMsg) raise self.failureException(msg) |