diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-01-17 12:51:09 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-01-17 12:51:09 -0500 |
commit | 9b484ffa3f480889f6478d34d84987beddc08ba6 (patch) | |
tree | 94c89f650e3f2550aec42306adb9e685388f74a3 | |
parent | 360c7725d4a82e5ad7b9ebc2e9aa459b39f5c2b4 (diff) | |
download | python-coveragepy-git-9b484ffa3f480889f6478d34d84987beddc08ba6.tar.gz |
Plain-text output no longer includes trailing spaces
-rw-r--r-- | CHANGES.rst | 2 | ||||
-rw-r--r-- | coverage/summary.py | 17 | ||||
-rw-r--r-- | tests/test_plugins.py | 2 | ||||
-rw-r--r-- | tests/test_summary.py | 33 |
4 files changed, 22 insertions, 32 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index a0f62caa..8352fe3a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -17,6 +17,8 @@ Unreleased unhelpful "missing branch" reports in a number of circumstances. Now they no longer are considered returns. +- ``coverage report`` won't produce trailing whitespace. + Version 4.1b1 --- 2016-01-10 ---------------------------- diff --git a/coverage/summary.py b/coverage/summary.py index 5ddbb380..94c44584 100644 --- a/coverage/summary.py +++ b/coverage/summary.py @@ -30,8 +30,8 @@ class SummaryReporter(Reporter): # Prepare the formatting strings max_name = max([len(fr.relative_filename()) for fr in self.file_reporters] + [5]) fmt_name = u"%%- %ds " % max_name - fmt_err = u"%s %s: %s\n" - fmt_skip_covered = u"\n%s file%s skipped due to complete coverage.\n" + fmt_err = u"%s %s: %s" + fmt_skip_covered = u"\n%s file%s skipped due to complete coverage." header = (fmt_name % "Name") + u" Stmts Miss" fmt_coverage = fmt_name + u"%6d %6d" @@ -44,17 +44,16 @@ class SummaryReporter(Reporter): if self.config.show_missing: header += u" Missing" fmt_coverage += u" %s" - rule = u"-" * len(header) + u"\n" - header += u"\n" - fmt_coverage += u"\n" + rule = u"-" * len(header) if outfile is None: outfile = sys.stdout - if env.PY2: - writeout = lambda u: outfile.write(u.encode(output_encoding())) - else: - writeout = outfile.write + def writeout(line): + if env.PY2: + line = line.encode(output_encoding()) + outfile.write(line.rstrip()) + outfile.write("\n") # Write the header writeout(header) diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 54f26a7f..2129076a 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -416,7 +416,7 @@ class GoodPluginTest(FileTracerTest): 'bar_4.html 4 2 0 0 50% 1, 4', 'foo_7.html 7 5 0 0 29% 1-3, 6-7', '--------------------------------------------------------', - 'TOTAL 11 7 0 0 36% ', + 'TOTAL 11 7 0 0 36%', ] self.assertEqual(report, expected) self.assertAlmostEqual(total, 36.36, places=2) diff --git a/tests/test_summary.py b/tests/test_summary.py index 9d7a6fe7..0cb9c24b 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -218,28 +218,17 @@ class SummaryTest(CoverageTest): out = self.run_command("coverage run --branch main.py") self.assertEqual(out, 'x\ny\n') report = self.report_from_command("coverage report --show-missing") - - # Name Stmts Miss Branch BrPart Cover Missing - # ------------------------------------------------------- - # main.py 1 0 0 0 100% - # mybranch.py 10 2 8 3 61% 7-8, 2->4, 4->6, 6->7 - # ------------------------------------------------------- - # TOTAL 11 2 8 3 63% - - self.assertEqual(self.line_count(report), 6) - squeezed = self.squeezed_lines(report) - self.assertEqual( - squeezed[2], - "main.py 1 0 0 0 100%" - ) - self.assertEqual( - squeezed[3], - "mybranch.py 10 2 8 3 61% 7-8, 2->4, 4->6, 6->7" - ) - self.assertEqual( - squeezed[5], - "TOTAL 11 2 8 3 63%" - ) + report_lines = report.splitlines() + + expected = [ + 'Name Stmts Miss Branch BrPart Cover Missing', + '---------------------------------------------------------', + 'main.py 1 0 0 0 100%', + 'mybranch.py 10 2 8 3 61% 7-8, 2->4, 4->6, 6->7', + '---------------------------------------------------------', + 'TOTAL 11 2 8 3 63%', + ] + self.assertEqual(report_lines, expected) def test_report_skip_covered_no_branches(self): self.make_file("main.py", """ |