summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/case.py35
-rw-r--r--Lib/unittest/test/test_assertions.py8
2 files changed, 26 insertions, 17 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index f4dbc52..993aaec 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -856,23 +856,28 @@ class TestCase(object):
if delta is not None and places is not None:
raise TypeError("specify delta or places not both")
+ diff = abs(first - second)
if delta is not None:
- if abs(first - second) <= delta:
+ if diff <= delta:
return
- standardMsg = '%s != %s within %s delta' % (safe_repr(first),
- safe_repr(second),
- safe_repr(delta))
+ standardMsg = '%s != %s within %s delta (%s difference)' % (
+ safe_repr(first),
+ safe_repr(second),
+ safe_repr(delta),
+ safe_repr(diff))
else:
if places is None:
places = 7
- if round(abs(second-first), places) == 0:
+ if round(diff, places) == 0:
return
- standardMsg = '%s != %s within %r places' % (safe_repr(first),
- safe_repr(second),
- places)
+ standardMsg = '%s != %s within %r places (%s difference)' % (
+ safe_repr(first),
+ safe_repr(second),
+ places,
+ safe_repr(diff))
msg = self._formatMessage(msg, standardMsg)
raise self.failureException(msg)
@@ -890,16 +895,19 @@ class TestCase(object):
"""
if delta is not None and places is not None:
raise TypeError("specify delta or places not both")
+ diff = abs(first - second)
if delta is not None:
- if not (first == second) and abs(first - second) > delta:
+ if not (first == second) and diff > delta:
return
- standardMsg = '%s == %s within %s delta' % (safe_repr(first),
- safe_repr(second),
- safe_repr(delta))
+ standardMsg = '%s == %s within %s delta (%s difference)' % (
+ safe_repr(first),
+ safe_repr(second),
+ safe_repr(delta),
+ safe_repr(diff))
else:
if places is None:
places = 7
- if not (first == second) and round(abs(second-first), places) != 0:
+ if not (first == second) and round(diff, places) != 0:
return
standardMsg = '%s == %s within %r places' % (safe_repr(first),
safe_repr(second),
@@ -908,7 +916,6 @@ class TestCase(object):
msg = self._formatMessage(msg, standardMsg)
raise self.failureException(msg)
-
def assertSequenceEqual(self, seq1, seq2, msg=None, seq_type=None):
"""An equality assertion for ordered sequences (like lists and tuples).
diff --git a/Lib/unittest/test/test_assertions.py b/Lib/unittest/test/test_assertions.py
index 31565da..b046669e 100644
--- a/Lib/unittest/test/test_assertions.py
+++ b/Lib/unittest/test/test_assertions.py
@@ -223,9 +223,11 @@ class TestLongMessage(unittest.TestCase):
"^1 == 1 : oops$"])
def testAlmostEqual(self):
- self.assertMessages('assertAlmostEqual', (1, 2),
- ["^1 != 2 within 7 places$", "^oops$",
- "^1 != 2 within 7 places$", "^1 != 2 within 7 places : oops$"])
+ self.assertMessages(
+ 'assertAlmostEqual', (1, 2),
+ ["^1 != 2 within 7 places \(1 difference\)$", "^oops$",
+ "^1 != 2 within 7 places \(1 difference\)$",
+ "^1 != 2 within 7 places \(1 difference\) : oops$"])
def testNotAlmostEqual(self):
self.assertMessages('assertNotAlmostEqual', (1, 1),