mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-07 05:26:53 +00:00
only write to stdout buffer when buffer object is available
This commit is contained in:
parent
bcb88c4c3e
commit
9cde73f106
2 changed files with 36 additions and 1 deletions
|
|
@ -136,6 +136,33 @@ def test_write_produces_stdout(capsys):
|
|||
assert capsys.readouterr().out == f"{line}\n{source}\n"
|
||||
|
||||
|
||||
def test_write_without_stdout_buffer():
|
||||
"""Verify that stdout writes when it has no buffer."""
|
||||
line = "Something to write"
|
||||
source = "source"
|
||||
|
||||
buffer_side_effect = AttributeError(
|
||||
"'_io.StringIO' object has no \
|
||||
attribute 'buffer'"
|
||||
)
|
||||
buffer_write_mock = mock.Mock(side_effect=buffer_side_effect)
|
||||
|
||||
write_mock = mock.Mock()
|
||||
mock.patch("flake8.formatting.base.sys.stdout.write", write_mock)
|
||||
|
||||
with mock.patch(
|
||||
"flake8.formatting.base.sys.stdout.buffer.write", buffer_write_mock
|
||||
):
|
||||
formatter = base.BaseFormatter(options())
|
||||
formatter.write(line, source)
|
||||
assert write_mock.called is True
|
||||
assert write_mock.call_count == 2
|
||||
assert write_mock.mock_calls == [
|
||||
mock.call(line + formatter.newline),
|
||||
mock.call(source + formatter.newline),
|
||||
]
|
||||
|
||||
|
||||
class AfterInitFormatter(base.BaseFormatter):
|
||||
"""Subclass for testing after_init."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue