summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Stapleton Cordasco <graffatcolmingov@gmail.com>2017-12-31 18:50:59 -0600
committerIan Stapleton Cordasco <graffatcolmingov@gmail.com>2017-12-31 18:50:59 -0600
commit49f0fbcf1ee5cfe724a3a6d8658e404627c55e98 (patch)
tree989408f994e419bc563fe48183c7f8ddbbd98ebb
parent3530870679ddb93ade9326d9e5d932596b66e8b9 (diff)
downloadflake8-49f0fbcf1ee5cfe724a3a6d8658e404627c55e98.tar.gz
Respect a formatter's newline setting when printing
In working on flake8-json, I noticed that setting newline was only helpful for writing to an ouput-file but not to standard-out. It makes sense for this setting to apply to both branches otherwise plugins need to override the method to get the behaviour they expect.
-rw-r--r--src/flake8/formatting/base.py2
-rw-r--r--tests/unit/test_base_formatter.py8
2 files changed, 5 insertions, 5 deletions
diff --git a/src/flake8/formatting/base.py b/src/flake8/formatting/base.py
index c4c67d5..1443e4c 100644
--- a/src/flake8/formatting/base.py
+++ b/src/flake8/formatting/base.py
@@ -172,7 +172,7 @@ class BaseFormatter(object):
if self.output_fd is not None:
self.output_fd.write(output + self.newline)
if self.output_fd is None or self.options.tee:
- print(output)
+ print(output, end=self.newline)
def write(self, line, source):
"""Write the line either to the output file or stdout.
diff --git a/tests/unit/test_base_formatter.py b/tests/unit/test_base_formatter.py
index 87b5fee..e4dab2e 100644
--- a/tests/unit/test_base_formatter.py
+++ b/tests/unit/test_base_formatter.py
@@ -92,8 +92,8 @@ def test_write_uses_an_output_file(tee):
if tee:
assert print_func.called
assert print_func.mock_calls == [
- mock.call(line),
- mock.call(source),
+ mock.call(line, end='\n'),
+ mock.call(source, end='\n'),
]
else:
assert not print_func.called
@@ -118,8 +118,8 @@ def test_write_uses_print(print_function):
assert print_function.called is True
assert print_function.call_count == 2
assert print_function.mock_calls == [
- mock.call(line),
- mock.call(source),
+ mock.call(line, end='\n'),
+ mock.call(source, end='\n'),
]