-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-110147: run console io test in new process #110268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c88252e
32f0209
db2b10b
7ee4a1f
1f6e6ca
4ecbd84
93ca648
2e7cd6d
a469eae
a0d2972
44ef80a
f222132
a3d0008
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
import unittest | ||
|
||
|
@@ -11,8 +12,6 @@ | |
import _winapi | ||
import msvcrt; | ||
|
||
from _testconsole import write_input, flush_console_input_buffer | ||
vstinner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class TestFileOperations(unittest.TestCase): | ||
def test_locking(self): | ||
|
@@ -62,33 +61,45 @@ def test_get_osfhandle(self): | |
|
||
class TestConsoleIO(unittest.TestCase): | ||
def test_kbhit(self): | ||
h = msvcrt.get_osfhandle(sys.stdin.fileno()) | ||
flush_console_input_buffer(h) | ||
self.assertEqual(msvcrt.kbhit(), 0) | ||
# Run test in a seprated process to avoid stdin conflicts. | ||
# See: gh-110147 | ||
cmd = [sys.executable, '-c', | ||
'import msvcrt;' | ||
'assert msvcrt.kbhit() == 0;' | ||
] | ||
subprocess.run(cmd, check=True, capture_output=True) | ||
aisk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def test_getch(self): | ||
msvcrt.ungetch(b'c') | ||
self.assertEqual(msvcrt.getch(), b'c') | ||
|
||
def test_getwch(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test_getwche() looks like a copy/paste, you just replaced getwch() with getwche(). Can you rename the function to check_getwch(func), so test_getwch() would call check_getwch("getwch") and test_getwch() would call check_getwch("getwche")? |
||
with open('CONIN$', 'rb', buffering=0) as stdin: | ||
h = msvcrt.get_osfhandle(stdin.fileno()) | ||
flush_console_input_buffer(h) | ||
|
||
write_input(stdin, c_encoded) | ||
self.assertEqual(msvcrt.getwch(), c) | ||
# Run test in a seprated process to avoid stdin conflicts. | ||
# See: gh-110147 | ||
cmd = [sys.executable, '-c', | ||
aisk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'import msvcrt;' | ||
'from _testconsole import write_input;' | ||
'stdin = open("CONIN$", "rb", buffering=0);' | ||
f'write_input(stdin, {c_encoded});' | ||
f'assert msvcrt.getwch() == "{c}";' | ||
] | ||
subprocess.run(cmd, check=True, capture_output=True) | ||
|
||
def test_getche(self): | ||
msvcrt.ungetch(b'c') | ||
self.assertEqual(msvcrt.getche(), b'c') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be safer to run this test in a subprocess with a new console, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it would, but it's annoying. We might want to put it behind a resource marker, as the new console will pop up new GUI when it runs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would CREATE_NO_WINDOW flag prevent popups?
says: https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems it should work, I'll try it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Means no console and the test is irrelevant.
This is the flag that you'd use to make the test more reliable, and it's incompatible with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, and added the For the tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hum, ok. Let's see if CI will agree with you :-) I'm fine with keeping them in the same process for now. |
||
|
||
def test_getwche(self): | ||
with open('CONIN$', 'rb', buffering=0) as stdin: | ||
h = msvcrt.get_osfhandle(stdin.fileno()) | ||
flush_console_input_buffer(h) | ||
|
||
write_input(stdin, c_encoded) | ||
self.assertEqual(msvcrt.getwche(), c) | ||
# Run test in a seprated process to avoid stdin conflicts. | ||
# See: gh-110147 | ||
cmd = [sys.executable, '-c', | ||
'import msvcrt;' | ||
'from _testconsole import write_input;' | ||
'stdin = open("CONIN$", "rb", buffering=0);' | ||
f'write_input(stdin, {c_encoded});' | ||
f'assert msvcrt.getwche() == "{c}";' | ||
] | ||
subprocess.run(cmd, check=True, capture_output=True) | ||
|
||
def test_putch(self): | ||
msvcrt.putch(b'c') | ||
|
Uh oh!
There was an error while loading. Please reload this page.