mirror of
https://github.com/python/cpython.git
synced 2025-10-21 06:02:21 +00:00
gh-106300: Improve assertRaises(Exception)
usages in tests (GH-106302)
This commit is contained in:
parent
80b9b3a517
commit
6e6a4cd523
7 changed files with 20 additions and 12 deletions
|
@ -2822,14 +2822,15 @@ class TransformCodecTest(unittest.TestCase):
|
|||
def test_custom_zlib_error_is_noted(self):
|
||||
# Check zlib codec gives a good error for malformed input
|
||||
msg = "decoding with 'zlib_codec' codec failed"
|
||||
with self.assertRaises(Exception) as failure:
|
||||
with self.assertRaises(zlib.error) as failure:
|
||||
codecs.decode(b"hello", "zlib_codec")
|
||||
self.assertEqual(msg, failure.exception.__notes__[0])
|
||||
|
||||
def test_custom_hex_error_is_noted(self):
|
||||
# Check hex codec gives a good error for malformed input
|
||||
import binascii
|
||||
msg = "decoding with 'hex_codec' codec failed"
|
||||
with self.assertRaises(Exception) as failure:
|
||||
with self.assertRaises(binascii.Error) as failure:
|
||||
codecs.decode(b"hello", "hex_codec")
|
||||
self.assertEqual(msg, failure.exception.__notes__[0])
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue