mirror of
https://github.com/python/cpython.git
synced 2025-10-28 17:13:08 +00:00
gh-129900: Fix SystemExit return codes when the REPL is started from the command line (#129901)
This commit is contained in:
parent
8ada7a9e14
commit
90b82f2b61
3 changed files with 23 additions and 2 deletions
|
|
@ -285,6 +285,27 @@ class SysModuleTest(unittest.TestCase):
|
|||
r'import sys; sys.exit("h\xe9")',
|
||||
b"h\xe9", PYTHONIOENCODING='latin-1')
|
||||
|
||||
@support.requires_subprocess()
|
||||
def test_exit_codes_under_repl(self):
|
||||
# GH-129900: SystemExit, or things that raised it, didn't
|
||||
# get their return code propagated by the REPL
|
||||
import tempfile
|
||||
|
||||
exit_ways = [
|
||||
"exit",
|
||||
"__import__('sys').exit",
|
||||
"raise SystemExit"
|
||||
]
|
||||
|
||||
for exitfunc in exit_ways:
|
||||
for return_code in (0, 123):
|
||||
with self.subTest(exitfunc=exitfunc, return_code=return_code):
|
||||
with tempfile.TemporaryFile("w+") as stdin:
|
||||
stdin.write(f"{exitfunc}({return_code})\n")
|
||||
stdin.seek(0)
|
||||
proc = subprocess.run([sys.executable], stdin=stdin)
|
||||
self.assertEqual(proc.returncode, return_code)
|
||||
|
||||
def test_getdefaultencoding(self):
|
||||
self.assertRaises(TypeError, sys.getdefaultencoding, 42)
|
||||
# can't check more than the type, as the user might have changed it
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue