diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2009-09-13 16:40:02 +0000 |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2009-09-13 16:40:02 +0000 |
commit | c3f79373e89cfe926b6e1f9e2f73dada1cbfff8e (patch) | |
tree | 4a11186cdbaef8d375972f162e32bcd2169a73f8 /Lib/unittest/case.py | |
parent | 60931a5a580321b4b225bec9e133ed3998eb7d1a (diff) | |
download | cpython-git-c3f79373e89cfe926b6e1f9e2f73dada1cbfff8e.tar.gz |
Objects that compare equal automatically pass or fail assertAlmostEqual and assertNotAlmostEqual tests on unittest.TestCase. Issue 6567.
Diffstat (limited to 'Lib/unittest/case.py')
-rw-r--r-- | Lib/unittest/case.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index d52bc8d850..cac28421bf 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) |