summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-10-25 21:34:43 +0000
committerIan Cordasco <graffatcolmingov@gmail.com>2016-10-25 21:34:43 +0000
commita9e15afbf50b3181af45a64f5736d432731eb40d (patch)
tree6daa2e8e89a2881c7fce439a27255ebff8236137 /tests
parent86819c153b4eafba1549ce93bc084ef9100c0ac1 (diff)
parenta71941e9fe047cc0dd586a3449cc22fec6999144 (diff)
downloadflake8-a9e15afbf50b3181af45a64f5736d432731eb40d.tar.gz
Merge branch 'master' into 'master'
Add --tee option to split report output stream. The `--tee` option allows the linter report to be written to stdout, even though it is being redirected to a file with the` --output-file` option. This is useful if I want to store the report in a separate file for later analysis but also be able to print the output on screen (e.g when running in a CI environment). See merge request !90
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_base_formatter.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/tests/unit/test_base_formatter.py b/tests/unit/test_base_formatter.py
index 8a99fa6..bb54358 100644
--- a/tests/unit/test_base_formatter.py
+++ b/tests/unit/test_base_formatter.py
@@ -11,6 +11,7 @@ from flake8.formatting import base
def options(**kwargs):
"""Create an optparse.Values instance."""
kwargs.setdefault('output_file', None)
+ kwargs.setdefault('tee', False)
return optparse.Values(kwargs)
@@ -76,15 +77,26 @@ def test_show_source_updates_physical_line_appropriately(line, column):
assert pointer.count(' ') == (column - 1)
-def test_write_uses_an_output_file():
+@pytest.mark.parametrize('tee', [False, True])
+def test_write_uses_an_output_file(tee):
"""Verify that we use the output file when it's present."""
line = 'Something to write'
source = 'source'
filemock = mock.Mock()
- formatter = base.BaseFormatter(options())
+ formatter = base.BaseFormatter(options(tee=tee))
formatter.output_fd = filemock
- formatter.write(line, source)
+
+ with mock.patch('flake8.formatting.base.print') as print_func:
+ formatter.write(line, source)
+ if tee:
+ assert print_func.called
+ assert print_func.mock_calls == [
+ mock.call(line),
+ mock.call(source),
+ ]
+ else:
+ assert not print_func.called
assert filemock.write.called is True
assert filemock.write.call_count == 2