Skip to content

Commit d8cc913

Browse files
committed
Add a test case to test_windows_console.py
1 parent 93c04f9 commit d8cc913

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lib/test/test_pyrepl/test_windows_console.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
raise unittest.SkipTest("test only relevant on win32")
66

77

8+
import subprocess
9+
from tempfile import TemporaryDirectory
10+
import os
11+
import time
812
import itertools
913
from functools import partial
1014
from test.support import force_not_colorized_test_class
@@ -577,5 +581,40 @@ def test_up_vt(self):
577581
self.assertEqual(self.mock.call_count, 3)
578582

579583

584+
class WindowsCommandLineTests(unittest.TestCase):
585+
def test_for_crash_traceback_with_redirected_stdout(self):
586+
"""python.bat -i -c "print('hlwd')" > file.txt"""
587+
script_command = "print('script has run')"
588+
589+
with TemporaryDirectory() as tmp_dir:
590+
stdout_path = os.path.join(tmp_dir, "WinCMDLineTests.txt")
591+
592+
with open(stdout_path, "w", encoding="utf-8") as stdout_file, \
593+
subprocess.Popen(
594+
[sys.executable, '-i', '-c', script_command],
595+
stdin=None,
596+
stdout=stdout_file,
597+
stderr=subprocess.PIPE,
598+
text=True, encoding='utf-8', errors='replace'
599+
) as process:
600+
601+
time.sleep(3)
602+
603+
if process.poll() is None:
604+
process.kill()
605+
606+
stderr_output = process.stderr.read()
607+
608+
has_crash_traceback = (
609+
"OSError" in stderr_output
610+
and len(stderr_output) > 1200
611+
)
612+
613+
if has_crash_traceback:
614+
self.fail(
615+
"Detected the endless OSError traceback.\n"
616+
f"Stderr was:\n{stderr_output[:1200]}"
617+
)
618+
580619
if __name__ == "__main__":
581620
unittest.main()

0 commit comments

Comments
 (0)