diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-02-18 21:37:07 (GMT) |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-02-18 21:37:07 (GMT) |
commit | c2294dd6ba5c05eb77876ffb03551737a154266d (patch) | |
tree | 6506a3d1739a2a2a7e240a9515000e75abefb833 /Lib | |
parent | 225a099fe500f4c3577b60ca657eb93a0cd1c735 (diff) | |
download | cpython-c2294dd6ba5c05eb77876ffb03551737a154266d.zip cpython-c2294dd6ba5c05eb77876ffb03551737a154266d.tar.gz cpython-c2294dd6ba5c05eb77876ffb03551737a154266d.tar.bz2 |
Fix unittest.TestCase.assertDictContainsSubset so it can't die with unicode issues when constructing failure messages. Issue 7956
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_unittest.py | 9 | ||||
-rw-r--r-- | Lib/unittest/case.py | 7 |
2 files changed, 7 insertions, 9 deletions
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py index 7b6922c..d3bab2a 100644 --- a/Lib/test/test_unittest.py +++ b/Lib/test/test_unittest.py @@ -2573,13 +2573,10 @@ class Test_TestCase(TestCase, TestEquality, TestHashing): with self.assertRaises(self.failureException): self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1}) - @unittest.expectedFailure - def test_crazy(self): one = ''.join(chr(i) for i in range(255)) - two = u'\uFFFD' - first = {'foo': one} - second = {'foo': two} - self.assertDictContainsSubset(first, second) + # this used to cause a UnicodeDecodeError constructing the failure msg + with self.assertRaises(self.failureException): + self.assertDictContainsSubset({'foo': one}, {'foo': u'\uFFFD'}) def testAssertEqual(self): equal_pairs = [ diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 1ee935a..8de36d7 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -163,7 +163,7 @@ class TestCase(object): try: testMethod = getattr(self, methodName) except AttributeError: - raise ValueError("no such test method in %s: %s" % \ + raise ValueError("no such test method in %s: %s" % (self.__class__, methodName)) self._testMethodDoc = testMethod.__doc__ self._cleanups = [] @@ -697,7 +697,7 @@ class TestCase(object): """Just like self.assertTrue(a is b), but with a nicer default message.""" if expr1 is not expr2: standardMsg = '%s is not %s' % (safe_repr(expr1), - safe_repr(expr2)) + safe_repr(expr2)) self.fail(self._formatMessage(msg, standardMsg)) def assertIsNot(self, expr1, expr2, msg=None): @@ -725,7 +725,8 @@ class TestCase(object): missing.append(key) elif value != actual[key]: mismatched.append('%s, expected: %s, actual: %s' % - (key, value, actual[key])) + (safe_repr(key), safe_repr(value), + safe_repr(actual[key]))) if not (missing or mismatched): return |