forked from magmax/python-readchar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
42 lines (30 loc) · 993 Bytes
/
conftest.py
File metadata and controls
42 lines (30 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sys
import pytest
if sys.platform.startswith("linux"):
import termios
# ignore all tests in this folder if not on linux
def pytest_ignore_collect(collection_path, config):
if not sys.platform.startswith("linux"):
return True
@pytest.fixture
def patched_stdin():
class mocked_stdin:
buffer = []
def push(self, string):
for c in string:
self.buffer.append(c)
def read(self, n):
string = ""
for i in range(n):
string += self.buffer.pop(0)
return string
def mock_tcgetattr(fd):
return [0, 0, 0, 0, None, None, None]
def mock_tcsetattr(fd, TCSADRAIN, old_settings):
return None
mock = mocked_stdin()
with pytest.MonkeyPatch.context() as mp:
mp.setattr(sys.stdin, "read", mock.read)
mp.setattr(termios, "tcgetattr", mock_tcgetattr)
mp.setattr(termios, "tcsetattr", mock_tcsetattr)
yield mock