summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMartin Domke <mdomke@jackbird.local>2016-07-26 15:57:13 +0200
committerMartin Domke <mdomke@jackbird.local>2016-07-26 15:57:13 +0200
commitc782060a0620135b01eb64e15508cca581cb09be (patch)
tree36feb56558630a3b5727485150b3709efa6d2d4b /tests
parentf82b5d62d0c4e48b95466bb259f3401aecf28de7 (diff)
downloadflake8-c782060a0620135b01eb64e15508cca581cb09be.tar.gz
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).
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_base_formatter.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/tests/unit/test_base_formatter.py b/tests/unit/test_base_formatter.py
index f148806..9da8c65 100644
--- a/tests/unit/test_base_formatter.py
+++ b/tests/unit/test_base_formatter.py
@@ -1,4 +1,5 @@
"""Tests for the BaseFormatter object."""
+import io
import optparse
import mock
@@ -11,6 +12,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 +78,22 @@ def test_show_source_updates_physical_line_appropriately(line, column):
assert pointer.count(' ') == column
-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'
+ line = u'Something to write'
+ source = u'source'
filemock = mock.Mock()
- formatter = base.BaseFormatter(options())
- formatter.output_fd = filemock
- formatter.write(line, source)
+ with mock.patch('sys.stdout', new_callable=io.StringIO) as stdout:
+ formatter = base.BaseFormatter(options(tee=tee))
+ formatter.output_fd = filemock
+ formatter.write(line, source)
+ if tee:
+ output = line + formatter.newline + source + formatter.newline
+ else:
+ output = ''
+ assert stdout.getvalue() == output
assert filemock.write.called is True
assert filemock.write.call_count == 2