summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_exceptions.py
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2021-11-22 16:56:23 (GMT)
committerGitHub <noreply@github.com>2021-11-22 16:56:23 (GMT)
commit4d6c0c0cce05befa06e0cad7351b1303ac048277 (patch)
treea6f2cc0e0428879ffd305c0c38cc4e240086247d /Lib/test/test_exceptions.py
parent0e1c2f3ef84572b79fa7d8498a69bc5a56ff0d8d (diff)
downloadcpython-4d6c0c0cce05befa06e0cad7351b1303ac048277.zip
cpython-4d6c0c0cce05befa06e0cad7351b1303ac048277.tar.gz
cpython-4d6c0c0cce05befa06e0cad7351b1303ac048277.tar.bz2
bpo-45871: Refactor except matcher validation into a separate function so that it can be reused. Add missing unit test. (GH-29711)
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r--Lib/test/test_exceptions.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 4c18a59..eee178c 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -2401,6 +2401,21 @@ class SyntaxErrorTests(unittest.TestCase):
self.assertRaises(TypeError, SyntaxError, "bad bad", args)
+class TestInvalidExceptionMatcher(unittest.TestCase):
+ def test_except_star_invalid_exception_type(self):
+ with self.assertRaises(TypeError):
+ try:
+ raise ValueError
+ except 42:
+ pass
+
+ with self.assertRaises(TypeError):
+ try:
+ raise ValueError
+ except (ValueError, 42):
+ pass
+
+
class PEP626Tests(unittest.TestCase):
def lineno_after_raise(self, f, *expected):