Objects that compare equal automatically pass or fail assertAlmostEqual and assertNotAlmostEqual tests on unittest.TestCase. Issue 6567.

This commit is contained in:
Michael Foord 2009-09-13 16:40:02 +00:00
parent 60931a5a58
commit c3f79373e8
4 changed files with 24 additions and 1 deletions

View file

@ -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)