rich/tests/test_file_proxy.py
Henry Mai 0177b03700
Black formatting (#3035)
* fix: minor black formatting

* style: update CONTRIBUTORS.md

* fix: more black formatting

Default black with no arguments provided

---------

Co-authored-by: Darren Burns <darrenburns@users.noreply.github.com>
2023-11-07 17:57:21 +00:00

37 lines
917 B
Python

import io
import sys
import pytest
from rich.console import Console
from rich.file_proxy import FileProxy
def test_empty_bytes():
console = Console()
file_proxy = FileProxy(console, sys.stdout)
# File should raise TypeError when writing bytes
with pytest.raises(TypeError):
file_proxy.write(b"") # type: ignore
with pytest.raises(TypeError):
file_proxy.write(b"foo") # type: ignore
def test_flush():
file = io.StringIO()
console = Console(file=file)
file_proxy = FileProxy(console, file)
file_proxy.write("foo")
assert file.getvalue() == ""
file_proxy.flush()
assert file.getvalue() == "foo\n"
def test_new_lines():
file = io.StringIO()
console = Console(file=file)
file_proxy = FileProxy(console, file)
file_proxy.write("-\n-")
assert file.getvalue() == "-\n"
file_proxy.flush()
assert file.getvalue() == "-\n-\n"