Skip to content

Commit 696b021

Browse files
committed
Add a test.
1 parent 46887d5 commit 696b021

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Lib/test/test_sys.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,25 @@ def check_exit_message(code, expected, **env_vars):
272272
r'import sys; sys.exit("h\xe9")',
273273
b"h\xe9", PYTHONIOENCODING='latin-1')
274274

275+
@support.requires_subprocess()
276+
def test_exit_codes_under_repl(self):
277+
import tempfile
278+
279+
cases = [
280+
("exit", 123),
281+
("exit", 0),
282+
("__import__('sys').exit", 123),
283+
("__import__('sys').exit", 0)
284+
]
285+
286+
for exitfunc, return_code in cases:
287+
with self.subTest(exitfunc=exitfunc, return_code=return_code):
288+
with tempfile.TemporaryFile("w+") as stdin:
289+
stdin.write(f"{exitfunc}({return_code})\n")
290+
stdin.seek(0)
291+
proc = subprocess.run([sys.executable], stdin=stdin)
292+
self.assertEqual(proc.returncode, return_code)
293+
275294
def test_getdefaultencoding(self):
276295
self.assertRaises(TypeError, sys.getdefaultencoding, 42)
277296
# can't check more than the type, as the user might have changed it

0 commit comments

Comments
 (0)