Skip to content

Commit

Permalink
Fix the issue that raises a bunch of OSError exceptions in the test s…
Browse files Browse the repository at this point in the history
…cript (magmax#93)
  • Loading branch information
sakkyoi committed Aug 10, 2024
1 parent 75e8db1 commit 32969ab
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions tests/windows/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pytest


if sys.platform in ("win32", "cygwin"):
import msvcrt
# if sys.platform in ("win32", "cygwin"):
# import msvcrt


# ignore all tests in this folder if not on windows
Expand All @@ -14,10 +14,16 @@ def pytest_ignore_collect(path, config):


@pytest.fixture
def patched_stdin():
def patched_stdin(monkeypatch):
class mocked_stdin:
def push(self, string):
for c in string:
msvcrt.ungetch(ord(c).to_bytes(1, "big"))
# Create an iterator from the string
characters = iter(string)

# Patch msvcrt.getwch to return the next character from the iterator.
# Don't use next(iter(string)) as it creates a new iterator each time.
# For example,
# if you use a new iterator, cursor_up (\x00\x48) will be read as \x00\x00.
monkeypatch.setattr("msvcrt.getwch", lambda: next(characters))

return mocked_stdin()

0 comments on commit 32969ab

Please sign in to comment.