diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2017-01-11 17:53:17 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2017-01-11 17:53:17 -0500 |
commit | cb0da0af9a826adc86c49fd1429e1ab07d91b770 (patch) | |
tree | d8a626a35acd0f3e758f2d32d15b8594c5e6b5a8 | |
parent | 6c8a2e48c9d74f561216557ad5b07da2cae7c245 (diff) | |
download | python-coveragepy-git-cb0da0af9a826adc86c49fd1429e1ab07d91b770.tar.gz |
Delete html files when skipping covered files
-rw-r--r-- | CHANGES.rst | 6 | ||||
-rw-r--r-- | coverage/html.py | 12 | ||||
-rw-r--r-- | tests/test_html.py | 17 |
3 files changed, 31 insertions, 4 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 5a47e4f6..ffc754c6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -21,6 +21,12 @@ Unreleased function changed, measurement is likely wrong: None". This was spurious, and has been suppressed. +- Let's say you ran the HTML report over and over again in the same output + directory, with ``--skip-covered``. And imagine due to your heroic + test-writing efforts, a file just acheived the goal of 100% coverage. With + coverage.py 4.3, the old HTML file with the less-than-100% coverage would be + left behind. This file is now properly deleted. + .. _issue 549: https://bitbucket.org/ned/coveragepy/issues/549/skip-covered-with-100-coverage-throws-a-no diff --git a/coverage/html.py b/coverage/html.py index fd5a2391..b0c61649 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -12,7 +12,7 @@ import coverage from coverage import env from coverage.backward import iitems from coverage.files import flat_rootname -from coverage.misc import CoverageException, Hasher, isolate_module +from coverage.misc import CoverageException, file_be_gone, Hasher, isolate_module from coverage.report import Reporter from coverage.results import Numbers from coverage.templite import Templite @@ -172,20 +172,26 @@ class HtmlReporter(Reporter): def html_file(self, fr, analysis): """Generate an HTML file for one source file.""" + rootname = flat_rootname(fr.relative_filename()) + html_filename = rootname + ".html" + html_path = os.path.join(self.directory, html_filename) + # Get the numbers for this file. nums = analysis.numbers self.all_files_nums.append(nums) + if self.config.skip_covered: # Don't report on 100% files. no_missing_lines = (nums.n_missing == 0) no_missing_branches = (nums.n_partial_branches == 0) if no_missing_lines and no_missing_branches: + # If there's an existing file, remove it. + file_be_gone(html_path) return source = fr.source() # Find out if the file on disk is already correct. - rootname = flat_rootname(fr.relative_filename()) this_hash = self.file_hash(source.encode('utf-8'), fr) that_hash = self.status.file_hash(rootname) if this_hash == that_hash: @@ -277,8 +283,6 @@ class HtmlReporter(Reporter): 'time_stamp': self.time_stamp, }) - html_filename = rootname + ".html" - html_path = os.path.join(self.directory, html_filename) write_html(html_path, html) # Save this file's information for the index file. diff --git a/tests/test_html.py b/tests/test_html.py index 7c35b595..4057d290 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -205,6 +205,23 @@ class HtmlDeltaTest(HtmlTestHelpers, CoverageTest): fixed_index2 = index2.replace("XYZZY", self.real_coverage_version) self.assertMultiLineEqual(index1, fixed_index2) + def test_file_becomes_100(self): + self.create_initial_files() + self.run_coverage() + + # Now change a file and do it again + self.make_file("main_file.py", """\ + import helper1, helper2 + # helper1 is now 100% + helper1.func1(12) + helper1.func1(23) + """) + + self.run_coverage(htmlargs=dict(skip_covered=True)) + + # The 100% file, skipped, shouldn't be here. + self.assert_doesnt_exist("htmlcov/helper1_py.html") + def test_status_format_change(self): self.create_initial_files() self.run_coverage() |