diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-04-25 05:58:25 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-04-25 05:58:25 (GMT) |
commit | 685fbed7f9bbff7426aaef68581fddc64c4a71e3 (patch) | |
tree | 045f98f87994e95a4639e1867944ce455efba1d4 /Lib/unittest/test | |
parent | 5b6f0aa71c8f91a970eeb06eb8c636c8c69a569f (diff) | |
download | cpython-685fbed7f9bbff7426aaef68581fddc64c4a71e3.zip cpython-685fbed7f9bbff7426aaef68581fddc64c4a71e3.tar.gz cpython-685fbed7f9bbff7426aaef68581fddc64c4a71e3.tar.bz2 |
Issue #26837: assertSequenceEqual() now correctly outputs non-stringified
differing items (like bytes in the -b mode). This affects assertListEqual()
and assertTupleEqual().
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r-- | Lib/unittest/test/test_case.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index ada733b..1fb95dc 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -1121,6 +1121,82 @@ test case error = str(e).split('\n', 1)[1] self.assertEqual(sample_text_error, error) + def testEqualityBytesWarning(self): + if sys.flags.bytes_warning: + def bytes_warning(): + return self.assertWarnsRegex(BytesWarning, + 'Comparison between bytes and string') + else: + def bytes_warning(): + return contextlib.ExitStack() + + with bytes_warning(), self.assertRaises(self.failureException): + self.assertEqual('a', b'a') + with bytes_warning(): + self.assertNotEqual('a', b'a') + + a = [0, 'a'] + b = [0, b'a'] + with bytes_warning(), self.assertRaises(self.failureException): + self.assertListEqual(a, b) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertTupleEqual(tuple(a), tuple(b)) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertSequenceEqual(a, tuple(b)) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertSequenceEqual(tuple(a), b) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertSequenceEqual('a', b'a') + with bytes_warning(), self.assertRaises(self.failureException): + self.assertSetEqual(set(a), set(b)) + + with self.assertRaises(self.failureException): + self.assertListEqual(a, tuple(b)) + with self.assertRaises(self.failureException): + self.assertTupleEqual(tuple(a), b) + + a = [0, b'a'] + b = [0] + with self.assertRaises(self.failureException): + self.assertListEqual(a, b) + with self.assertRaises(self.failureException): + self.assertTupleEqual(tuple(a), tuple(b)) + with self.assertRaises(self.failureException): + self.assertSequenceEqual(a, tuple(b)) + with self.assertRaises(self.failureException): + self.assertSequenceEqual(tuple(a), b) + with self.assertRaises(self.failureException): + self.assertSetEqual(set(a), set(b)) + + a = [0] + b = [0, b'a'] + with self.assertRaises(self.failureException): + self.assertListEqual(a, b) + with self.assertRaises(self.failureException): + self.assertTupleEqual(tuple(a), tuple(b)) + with self.assertRaises(self.failureException): + self.assertSequenceEqual(a, tuple(b)) + with self.assertRaises(self.failureException): + self.assertSequenceEqual(tuple(a), b) + with self.assertRaises(self.failureException): + self.assertSetEqual(set(a), set(b)) + + with bytes_warning(), self.assertRaises(self.failureException): + self.assertDictEqual({'a': 0}, {b'a': 0}) + with self.assertRaises(self.failureException): + self.assertDictEqual({}, {b'a': 0}) + with self.assertRaises(self.failureException): + self.assertDictEqual({b'a': 0}, {}) + + with self.assertRaises(self.failureException): + self.assertCountEqual([b'a', b'a'], [b'a', b'a', b'a']) + with bytes_warning(): + self.assertCountEqual(['a', b'a'], ['a', b'a']) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertCountEqual(['a', 'a'], [b'a', b'a']) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertCountEqual(['a', 'a', []], [b'a', b'a', []]) + def testAssertIsNone(self): self.assertIsNone(None) self.assertRaises(self.failureException, self.assertIsNone, False) |