| 1 |
import pytest |
| 2 |
import sys |
| 3 |
|
| 4 |
msvcrt = pytest.importorskip('msvcrt') |
| 5 |
|
| 6 |
|
| 7 |
class TestMsvcrt: |
| 8 |
|
| 9 |
def test_locking(self, tmpdir): |
| 10 |
filename = tmpdir / 'locking_test' |
| 11 |
filename.ensure() |
| 12 |
|
| 13 |
import os, errno |
| 14 |
|
| 15 |
fd = os.open(str(filename), 0) |
| 16 |
try: |
| 17 |
msvcrt.locking(fd, 1, 1) |
| 18 |
|
| 19 |
|
| 20 |
with pytest.raises(IOError) as e: |
| 21 |
msvcrt.locking(fd, 1, 1) |
| 22 |
assert e.value.errno == errno.EDEADLOCK |
| 23 |
|
| 24 |
|
| 25 |
msvcrt.locking(fd, 0, 1) |
| 26 |
msvcrt.locking(fd, 1, 1) |
| 27 |
finally: |
| 28 |
os.close(fd) |
| 29 |
|
| 30 |
def test_getch(self): |
| 31 |
with pytest.raises(TypeError): |
| 32 |
msvcrt.ungetch('a') |
| 33 |
msvcrt.ungetch(b'a') |
| 34 |
k = msvcrt.getch() |
| 35 |
assert k == b'a' |
| 36 |
|
| 37 |
def test_getwch(self): |
| 38 |
msvcrt.ungetwch('a') |
| 39 |
k = msvcrt.getwch() |
| 40 |
assert k == u'a' |