mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-46328: Add sys.exception() (GH-30514)
This commit is contained in:
parent
9c2ebb906d
commit
c590b581bb
7 changed files with 147 additions and 19 deletions
|
@ -71,6 +71,69 @@ class DisplayHookTest(unittest.TestCase):
|
|||
code = compile("42", "<string>", "single")
|
||||
self.assertRaises(ValueError, eval, code)
|
||||
|
||||
class ActiveExceptionTests(unittest.TestCase):
|
||||
def test_exc_info_no_exception(self):
|
||||
self.assertEqual(sys.exc_info(), (None, None, None))
|
||||
|
||||
def test_sys_exception_no_exception(self):
|
||||
self.assertEqual(sys.exception(), None)
|
||||
|
||||
def test_exc_info_with_exception_instance(self):
|
||||
def f():
|
||||
raise ValueError(42)
|
||||
|
||||
try:
|
||||
f()
|
||||
except Exception as e_:
|
||||
e = e_
|
||||
exc_info = sys.exc_info()
|
||||
|
||||
self.assertIsInstance(e, ValueError)
|
||||
self.assertIs(exc_info[0], ValueError)
|
||||
self.assertIs(exc_info[1], e)
|
||||
self.assertIs(exc_info[2], e.__traceback__)
|
||||
|
||||
def test_exc_info_with_exception_type(self):
|
||||
def f():
|
||||
raise ValueError
|
||||
|
||||
try:
|
||||
f()
|
||||
except Exception as e_:
|
||||
e = e_
|
||||
exc_info = sys.exc_info()
|
||||
|
||||
self.assertIsInstance(e, ValueError)
|
||||
self.assertIs(exc_info[0], ValueError)
|
||||
self.assertIs(exc_info[1], e)
|
||||
self.assertIs(exc_info[2], e.__traceback__)
|
||||
|
||||
def test_sys_exception_with_exception_instance(self):
|
||||
def f():
|
||||
raise ValueError(42)
|
||||
|
||||
try:
|
||||
f()
|
||||
except Exception as e_:
|
||||
e = e_
|
||||
exc = sys.exception()
|
||||
|
||||
self.assertIsInstance(e, ValueError)
|
||||
self.assertIs(exc, e)
|
||||
|
||||
def test_sys_exception_with_exception_type(self):
|
||||
def f():
|
||||
raise ValueError
|
||||
|
||||
try:
|
||||
f()
|
||||
except Exception as e_:
|
||||
e = e_
|
||||
exc = sys.exception()
|
||||
|
||||
self.assertIsInstance(e, ValueError)
|
||||
self.assertIs(exc, e)
|
||||
|
||||
|
||||
class ExceptHookTest(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue