| 1 |
__test__ = False |
| 2 |
|
| 3 |
if __name__ == '__main__': |
| 4 |
import eventlet |
| 5 |
eventlet.monkey_patch() |
| 6 |
|
| 7 |
import io |
| 8 |
import os |
| 9 |
import tempfile |
| 10 |
|
| 11 |
with tempfile.NamedTemporaryFile() as tmp: |
| 12 |
with open(tmp.name, "wb") as fp: |
| 13 |
fp.write(b"content") |
| 14 |
|
| 15 |
# test BufferedReader.read() |
| 16 |
fd = os.open(tmp.name, os.O_RDONLY) |
| 17 |
fp = os.fdopen(fd, "rb") |
| 18 |
with fp: |
| 19 |
content = fp.read() |
| 20 |
assert content == b'content' |
| 21 |
|
| 22 |
# test FileIO.read() |
| 23 |
fd = os.open(tmp.name, os.O_RDONLY) |
| 24 |
fp = os.fdopen(fd, "rb", 0) |
| 25 |
with fp: |
| 26 |
content = fp.read() |
| 27 |
assert content == b'content' |
| 28 |
|
| 29 |
# test FileIO.readall() |
| 30 |
fd = os.open(tmp.name, os.O_RDONLY) |
| 31 |
fp = os.fdopen(fd, "rb", 0) |
| 32 |
with fp: |
| 33 |
content = fp.readall() |
| 34 |
assert content == b'content' |
| 35 |
|
| 36 |
# test FileIO.readall() (for Python 2 and Python 3) |
| 37 |
with open(tmp.name, "rb", 0) as fp: |
| 38 |
content = fp.readall() |
| 39 |
assert content == b'content' |
| 40 |
|
| 41 |
print("pass") |