Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update test_repl from cpython 3.10.6
  • Loading branch information
CPython Developers authored and youknowone committed Aug 14, 2022
commit 563f9ecd53ca6a91b78dbe72172add132c016e27
26 changes: 20 additions & 6 deletions Lib/test/test_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
# test.support.script_helper.
env = kw.setdefault('env', dict(os.environ))
env['TERM'] = 'vt100'
return subprocess.Popen(cmd_line, executable=sys.executable,
return subprocess.Popen(cmd_line,
executable=sys.executable,
text=True,
stdin=subprocess.PIPE,
stdout=stdout, stderr=stderr,
**kw)
Expand All @@ -49,12 +51,11 @@ def test_no_memory(self):
sys.exit(0)
"""
user_input = dedent(user_input)
user_input = user_input.encode()
p = spawn_repl()
with SuppressCrashReport():
p.stdin.write(user_input)
output = kill_python(p)
self.assertIn(b'After the exception.', output)
self.assertIn('After the exception.', output)
# Exit code 120: Py_FinalizeEx() failed to flush stdout and stderr.
self.assertIn(p.returncode, (1, 120))

Expand Down Expand Up @@ -86,13 +87,26 @@ def test_multiline_string_parsing(self):
</test>"""
'''
user_input = dedent(user_input)
user_input = user_input.encode()
p = spawn_repl()
with SuppressCrashReport():
p.stdin.write(user_input)
p.stdin.write(user_input)
output = kill_python(p)
self.assertEqual(p.returncode, 0)

def test_close_stdin(self):
user_input = dedent('''
import os
print("before close")
os.close(0)
''')
prepare_repl = dedent('''
from test.support import suppress_msvcrt_asserts
suppress_msvcrt_asserts()
''')
process = spawn_repl('-c', prepare_repl)
output = process.communicate(user_input)[0]
self.assertEqual(process.returncode, 0)
self.assertIn('before close', output)


if __name__ == "__main__":
unittest.main()