Fix EncodedFile.writelines
This is implemented by the underlying stream already, which additionally checks if the stream is not closed, and calls `write` per line. Ref/via: https://github.com/pytest-dev/pytest/pull/6558#issuecomment-578210807
This commit is contained in:
@@ -1497,3 +1497,15 @@ def test_typeerror_encodedfile_write(testdir):
|
||||
def test_stderr_write_returns_len(capsys):
|
||||
"""Write on Encoded files, namely captured stderr, should return number of characters written."""
|
||||
assert sys.stderr.write("Foo") == 3
|
||||
|
||||
|
||||
def test_encodedfile_writelines(tmpfile) -> None:
|
||||
ef = capture.EncodedFile(tmpfile, "utf-8")
|
||||
with pytest.raises(AttributeError):
|
||||
ef.writelines([b"line1", b"line2"]) # type: ignore[list-item] # noqa: F821
|
||||
assert ef.writelines(["line1", "line2"]) is None # type: ignore[func-returns-value] # noqa: F821
|
||||
tmpfile.seek(0)
|
||||
assert tmpfile.read() == b"line1line2"
|
||||
tmpfile.close()
|
||||
with pytest.raises(ValueError):
|
||||
ef.read()
|
||||
|
||||
Reference in New Issue
Block a user