Fix EncodedFile.write return value

Make EncodedFile, used for captured output streams, method .write return
the number of characters written. Add test for captured stderr write.
Fixes #6557.

Co-Authored-By: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
Tomáš Gavenčiak 2020-01-24 13:50:56 +01:00 committed by Tomas Gavenciak
parent 0d4f479aa8
commit 5e15c86cc6
4 changed files with 8 additions and 1 deletions

View File

@ -256,6 +256,7 @@ Tim Hoffmann
Tim Strazny
Tom Dalton
Tom Viner
Tomáš Gavenčiak
Tomer Keren
Trevor Bekolay
Tyler Goodlet

View File

@ -0,0 +1 @@
Make capture output streams ``.write()`` method return the same return value from original streams.

View File

@ -424,7 +424,7 @@ class EncodedFile:
raise TypeError(
"write() argument must be str, not {}".format(type(obj).__name__)
)
self.buffer.write(obj)
return self.buffer.write(obj)
def writelines(self, linelist):
data = "".join(linelist)

View File

@ -1492,3 +1492,8 @@ def test_typeerror_encodedfile_write(testdir):
result_with_capture.stdout.fnmatch_lines(
["E * TypeError: write() argument must be str, not bytes"]
)
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