mirror of
https://github.com/python/cpython.git
synced 2025-09-15 13:16:12 +00:00
Objects that compare equal automatically pass or fail assertAlmostEqual and assertNotAlmostEqual tests on unittest.TestCase. Issue 6567.
This commit is contained in:
parent
60931a5a58
commit
c3f79373e8
4 changed files with 24 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue