summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-06-05 21:01:08 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-06-05 21:01:08 (GMT)
commitda562f65e985b59e292916955aa18b9dd58ba26f (patch)
tree20341483453095bf8c2cdcaf0607afc5550e887f /Lib/unittest/test
parenta7a42cb639455812dd02b5eba24710193f93372c (diff)
downloadcpython-da562f65e985b59e292916955aa18b9dd58ba26f.zip
cpython-da562f65e985b59e292916955aa18b9dd58ba26f.tar.gz
cpython-da562f65e985b59e292916955aa18b9dd58ba26f.tar.bz2
Merged revisions 81763 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r81763 | michael.foord | 2010-06-05 21:33:43 +0100 (Sat, 05 Jun 2010) | 1 line Tests for unittest.TestCase.maxDiff. ........
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r--Lib/unittest/test/test_case.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py
index 8345443..b7dfa68 100644
--- a/Lib/unittest/test/test_case.py
+++ b/Lib/unittest/test/test_case.py
@@ -597,6 +597,8 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
seq2 = 'b' + 'x' * 80**2
diff = '\n'.join(difflib.ndiff(pprint.pformat(seq1).splitlines(),
pprint.pformat(seq2).splitlines()))
+ # the +1 is the leading \n added by assertSequenceEqual
+ omitted = unittest.case.DIFF_OMITTED % (len(diff) + 1,)
self.maxDiff = len(diff)//2
try:
@@ -607,6 +609,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
else:
self.fail('assertSequenceEqual did not fail.')
self.assertTrue(len(msg) < len(diff))
+ self.assertIn(omitted, msg)
self.maxDiff = len(diff) * 2
try:
@@ -616,6 +619,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
else:
self.fail('assertSequenceEqual did not fail.')
self.assertTrue(len(msg) > len(diff))
+ self.assertNotIn(omitted, msg)
self.maxDiff = None
try:
@@ -625,6 +629,41 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
else:
self.fail('assertSequenceEqual did not fail.')
self.assertTrue(len(msg) > len(diff))
+ self.assertNotIn(omitted, msg)
+
+ def testTruncateMessage(self):
+ self.maxDiff = 1
+ message = self._truncateMessage('foo', 'bar')
+ omitted = unittest.case.DIFF_OMITTED % len('bar')
+ self.assertEqual(message, 'foo' + omitted)
+
+ self.maxDiff = None
+ message = self._truncateMessage('foo', 'bar')
+ self.assertEqual(message, 'foobar')
+
+ def testAssertDictEqualTruncates(self):
+ test = unittest.TestCase('assertEqual')
+ def truncate(msg, diff):
+ return 'foo'
+ test._truncateMessage = truncate
+ try:
+ test.assertDictEqual({}, {1: 0})
+ except self.failureException as e:
+ self.assertEqual(str(e), 'foo')
+ else:
+ self.fail('assertDictEqual did not fail')
+
+ def testAssertMultiLineEqualTruncates(self):
+ test = unittest.TestCase('assertEqual')
+ def truncate(msg, diff):
+ return 'foo'
+ test._truncateMessage = truncate
+ try:
+ test.assertMultiLineEqual('foo', 'bar')
+ except self.failureException as e:
+ self.assertEqual(str(e), 'foo')
+ else:
+ self.fail('assertMultiLineEqual did not fail')
def testAssertItemsEqual(self):
a = object()