mirror of
https://github.com/Textualize/rich.git
synced 2025-08-04 01:58:24 +00:00
Implementing null file
This commit is contained in:
parent
46ef6283a0
commit
9009e16b1a
2 changed files with 28 additions and 2 deletions
|
@ -12,7 +12,7 @@ class NullFile(IO[str]):
|
|||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return ""
|
||||
return "NullFile"
|
||||
|
||||
def closed(self) -> bool:
|
||||
return False
|
||||
|
@ -57,7 +57,7 @@ class NullFile(IO[str]):
|
|||
return ""
|
||||
|
||||
def __iter__(self) -> Iterator[AnyStr]:
|
||||
pass
|
||||
return iter([""])
|
||||
|
||||
def __enter__(self) -> IO[AnyStr]:
|
||||
pass
|
||||
|
|
26
tests/test_null_file.py
Normal file
26
tests/test_null_file.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from rich._null_file import NullFile
|
||||
|
||||
|
||||
def test_null_file():
|
||||
file = NullFile()
|
||||
with file:
|
||||
assert file.write("abc") == 0
|
||||
assert file.mode == ""
|
||||
assert file.name == "NullFile"
|
||||
assert not file.closed()
|
||||
assert file.close() is None
|
||||
assert not file.isatty()
|
||||
assert file.read() == ""
|
||||
assert not file.readable()
|
||||
assert file.readline() == ""
|
||||
assert file.readlines() == []
|
||||
assert file.seek(0, 0) == 0
|
||||
assert not file.seekable()
|
||||
assert file.tell() == 0
|
||||
assert file.truncate() == 0
|
||||
assert file.writable() == False
|
||||
assert file.writelines([""]) is None
|
||||
assert next(file) == ""
|
||||
assert next(iter(file)) == ""
|
||||
assert file.fileno() == -1
|
||||
assert file.flush() is None
|
Loading…
Add table
Add a link
Reference in a new issue