mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
[3.11] gh-106300: Improve assertRaises(Exception)
usages in tests (GH-106302). (GH-106545)
(cherry picked from commit 6e6a4cd523
)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
parent
1931c2a438
commit
6cd08a566f
7 changed files with 20 additions and 12 deletions
|
@ -2823,15 +2823,16 @@ class TransformCodecTest(unittest.TestCase):
|
|||
def test_custom_zlib_error_is_wrapped(self):
|
||||
# Check zlib codec gives a good error for malformed input
|
||||
msg = "^decoding with 'zlib_codec' codec failed"
|
||||
with self.assertRaisesRegex(Exception, msg) as failure:
|
||||
with self.assertRaises(zlib.error) as failure:
|
||||
codecs.decode(b"hello", "zlib_codec")
|
||||
self.assertIsInstance(failure.exception.__cause__,
|
||||
type(failure.exception))
|
||||
|
||||
def test_custom_hex_error_is_wrapped(self):
|
||||
# Check hex codec gives a good error for malformed input
|
||||
import binascii
|
||||
msg = "^decoding with 'hex_codec' codec failed"
|
||||
with self.assertRaisesRegex(Exception, msg) as failure:
|
||||
with self.assertRaises(binascii.Error) as failure:
|
||||
codecs.decode(b"hello", "hex_codec")
|
||||
self.assertIsInstance(failure.exception.__cause__,
|
||||
type(failure.exception))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue