aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_cmd.py
diff options
context:
space:
mode:
authorTian Gao <gaogaotiantian@hotmail.com>2023-11-10 13:13:29 -0800
committerGitHub <noreply@github.com>2023-11-10 21:13:29 +0000
commit148af38cd0adc1c2dde3c937ebbda4ee60b27b33 (patch)
tree83b6f242e0671d5fa7fcfc6ac970170a52128ad2 /Lib/test/test_cmd.py
parentafac3c9b7eace4a3e503e93bb76eda32d8217ad7 (diff)
downloadcpython-148af38cd0adc1c2dde3c937ebbda4ee60b27b33.tar.gz
cpython-148af38cd0adc1c2dde3c937ebbda4ee60b27b33.zip
gh-80731: Avoid executing code in except block in cmd (GH-111740)
Diffstat (limited to 'Lib/test/test_cmd.py')
-rw-r--r--Lib/test/test_cmd.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_cmd.py b/Lib/test/test_cmd.py
index 28f80766677..951336fa085 100644
--- a/Lib/test/test_cmd.py
+++ b/Lib/test/test_cmd.py
@@ -244,6 +244,21 @@ class TestAlternateInput(unittest.TestCase):
"(Cmd) *** Unknown syntax: EOF\n"))
+class CmdPrintExceptionClass(cmd.Cmd):
+ """
+ GH-80731
+ cmd.Cmd should print the correct exception in default()
+ >>> mycmd = CmdPrintExceptionClass()
+ >>> try:
+ ... raise ValueError("test")
+ ... except ValueError:
+ ... mycmd.onecmd("not important")
+ (<class 'ValueError'>, ValueError('test'))
+ """
+
+ def default(self, line):
+ print(sys.exc_info()[:2])
+
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests