| 1 |
import io |
| 2 |
import sys |
| 3 |
|
| 4 |
import pytest |
| 5 |
|
| •6 |
from progressbar2 import utils |
| 7 |
|
| 8 |
|
| 9 |
def test_wrappingio() -> None: |
| 10 |
|
| 11 |
fd = utils.WrappingIO(sys.stdout) |
| 12 |
assert fd.fileno() |
| 13 |
assert not fd.isatty() |
| 14 |
|
| 15 |
assert not fd.read() |
| 16 |
assert not fd.readline() |
| 17 |
assert not fd.readlines() |
| 18 |
assert fd.readable() |
| 19 |
|
| 20 |
assert not fd.seek(0) |
| 21 |
assert fd.seekable() |
| 22 |
assert not fd.tell() |
| 23 |
|
| 24 |
assert not fd.truncate() |
| 25 |
assert fd.writable() |
| 26 |
assert fd.write('test') |
| 27 |
assert not fd.writelines(['test']) |
| 28 |
|
| 29 |
with pytest.raises(StopIteration): |
| 30 |
next(fd) |
| 31 |
with pytest.raises(StopIteration): |
| 32 |
next(iter(fd)) |
| 33 |
|
| 34 |
|
| 35 |
def test_wrapping_stringio() -> None: |
| 36 |
|
| 37 |
string_io = io.StringIO() |
| 38 |
fd = utils.WrappingIO(string_io) |
| 39 |
with fd: |
| 40 |
with pytest.raises(io.UnsupportedOperation): |
| 41 |
fd.fileno() |
| 42 |
|
| 43 |
assert not fd.isatty() |
| 44 |
|
| 45 |
assert not fd.read() |
| 46 |
assert not fd.readline() |
| 47 |
assert not fd.readlines() |
| 48 |
assert fd.readable() |
| 49 |
|
| 50 |
assert not fd.seek(0) |
| 51 |
assert fd.seekable() |
| 52 |
assert not fd.tell() |
| 53 |
|
| 54 |
assert not fd.truncate() |
| 55 |
assert fd.writable() |
| 56 |
assert fd.write('test') |
| 57 |
assert not fd.writelines(['test']) |
| 58 |
|
| 59 |
with pytest.raises(StopIteration): |
| 60 |
next(fd) |
| 61 |
with pytest.raises(StopIteration): |
| 62 |
next(iter(fd)) |