-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
gh-108996: fix and enable test_msvcrt #109226
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c8d3c3f
gh-108996: fix and enable test_msvcrt
aisk 5832f2b
close console io after each test
aisk 351baac
call input flush in function
aisk e2a7481
update news
aisk 822901e
Merge branch 'main' into fix-test-msvcrt
aisk b80cca0
add flush_console_input_buffer to replace ctypes in tests
aisk f620ad8
Merge branch 'main' into fix-test-msvcrt
aisk d436f23
Merge branch 'main' into fix-test-msvcrt
aisk 8046eac
Merge branch 'main' into fix-test-msvcrt
aisk dfd3992
do not update the sys.stdin in console tests
aisk File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import ctypes | ||
import os | ||
import sys | ||
import unittest | ||
|
||
raise unittest.SkipTest("FIXME! broken test see: https://github.com/python/cpython/pull/109004") | ||
|
||
from test.support import os_helper | ||
from test.support.os_helper import TESTFN, TESTFN_ASCII | ||
|
||
|
@@ -64,35 +63,43 @@ def test_get_osfhandle(self): | |
|
||
class TestConsoleIO(unittest.TestCase): | ||
def test_kbhit(self): | ||
h = msvcrt.get_osfhandle(sys.stdin.fileno()) | ||
ctypes.windll.kernel32.FlushConsoleInputBuffer(h) | ||
self.assertEqual(msvcrt.kbhit(), 0) | ||
|
||
def test_getch(self): | ||
msvcrt.ungetch(b'c') | ||
self.assertEqual(msvcrt.getch(), b'c') | ||
|
||
def test_getwch(self): | ||
stdin = open('CONIN$', 'r') | ||
old_stdin = sys.stdin | ||
try: | ||
sys.stdin = stdin | ||
write_input(stdin.buffer.raw, c_encoded) | ||
self.assertEqual(msvcrt.getwch(), c) | ||
finally: | ||
sys.stdin = old_stdin | ||
with open('CONIN$', 'rb', buffering=0) as stdin: | ||
h = msvcrt.get_osfhandle(stdin.fileno()) | ||
ctypes.windll.kernel32.FlushConsoleInputBuffer(h) | ||
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. Maybe it should be exposed in msvcrt, maybe as a private function just for testing. |
||
|
||
old_stdin = sys.stdin | ||
try: | ||
sys.stdin = stdin | ||
write_input(stdin, c_encoded) | ||
self.assertEqual(msvcrt.getwch(), c) | ||
finally: | ||
sys.stdin = old_stdin | ||
|
||
def test_getche(self): | ||
msvcrt.ungetch(b'c') | ||
self.assertEqual(msvcrt.getche(), b'c') | ||
|
||
def test_getwche(self): | ||
stdin = open('CONIN$', 'r') | ||
old_stdin = sys.stdin | ||
try: | ||
sys.stdin = stdin | ||
write_input(stdin.buffer.raw, c_encoded) | ||
self.assertEqual(msvcrt.getwche(), c) | ||
finally: | ||
sys.stdin = old_stdin | ||
with open('CONIN$', 'rb', buffering=0) as stdin: | ||
h = msvcrt.get_osfhandle(stdin.fileno()) | ||
ctypes.windll.kernel32.FlushConsoleInputBuffer(h) | ||
|
||
old_stdin = sys.stdin | ||
try: | ||
sys.stdin = stdin | ||
zooba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
write_input(stdin, c_encoded) | ||
self.assertEqual(msvcrt.getwche(), c) | ||
finally: | ||
sys.stdin = old_stdin | ||
|
||
def test_putch(self): | ||
msvcrt.putch(b'c') | ||
|
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Tests/2023-09-10-23-05-50.gh-issue-108996.tJBru6.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix and enable ``test_msvcrt``. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctypes is not always available. Please use
try: import ctypes except ImportError: ctypes = None
, and then skip tests using ctypes if ctypes is None.