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:
parent
0d4f479aa8
commit
5e15c86cc6
1
AUTHORS
1
AUTHORS
|
@ -256,6 +256,7 @@ Tim Hoffmann
|
||||||
Tim Strazny
|
Tim Strazny
|
||||||
Tom Dalton
|
Tom Dalton
|
||||||
Tom Viner
|
Tom Viner
|
||||||
|
Tomáš Gavenčiak
|
||||||
Tomer Keren
|
Tomer Keren
|
||||||
Trevor Bekolay
|
Trevor Bekolay
|
||||||
Tyler Goodlet
|
Tyler Goodlet
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Make capture output streams ``.write()`` method return the same return value from original streams.
|
|
@ -424,7 +424,7 @@ class EncodedFile:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
"write() argument must be str, not {}".format(type(obj).__name__)
|
"write() argument must be str, not {}".format(type(obj).__name__)
|
||||||
)
|
)
|
||||||
self.buffer.write(obj)
|
return self.buffer.write(obj)
|
||||||
|
|
||||||
def writelines(self, linelist):
|
def writelines(self, linelist):
|
||||||
data = "".join(linelist)
|
data = "".join(linelist)
|
||||||
|
|
|
@ -1492,3 +1492,8 @@ def test_typeerror_encodedfile_write(testdir):
|
||||||
result_with_capture.stdout.fnmatch_lines(
|
result_with_capture.stdout.fnmatch_lines(
|
||||||
["E * TypeError: write() argument must be str, not bytes"]
|
["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
|
||||||
|
|
Loading…
Reference in New Issue