diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-02-28 17:33:19 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-02-28 17:33:19 -0500 |
commit | a095d73938a3fee8b56d0de840e0e81bfa52739f (patch) | |
tree | 8abe4fa99b862fa9a978e2bcf0f77502b6939b26 /coverage/report.py | |
parent | 582b42a1bde6a5fd62b793fa2733d31669498a0f (diff) | |
download | python-coveragepy-git-a095d73938a3fee8b56d0de840e0e81bfa52739f.tar.gz |
refactor: remove unused code paths
Diffstat (limited to 'coverage/report.py')
-rw-r--r-- | coverage/report.py | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/coverage/report.py b/coverage/report.py index 64678ff9..4ed0c7ef 100644 --- a/coverage/report.py +++ b/coverage/report.py @@ -10,27 +10,29 @@ from coverage.misc import CoverageException, NoSource, NotPython, ensure_dir_for def render_report(output_path, reporter, morfs): - """Run the provided reporter ensuring any required setup and cleanup is done + """Run a report generator, managing the output file. + + This function ensures the output file is ready to be written to. Then writes + the report to it. Then closes the file and cleans up. - At a high level this method ensures the output file is ready to be written to. Then writes the - report to it. Then closes the file and deletes any garbage created if necessary. """ file_to_close = None delete_file = False - if output_path: - if output_path == '-': - outfile = sys.stdout - else: - # Ensure that the output directory is created; done here - # because this report pre-opens the output file. - # HTMLReport does this using the Report plumbing because - # its task is more complex, being multiple files. - ensure_dir_for_file(output_path) - open_kwargs = {} - if env.PY3: - open_kwargs['encoding'] = 'utf8' - outfile = open(output_path, "w", **open_kwargs) - file_to_close = outfile + + if output_path == "-": + outfile = sys.stdout + else: + # Ensure that the output directory is created; done here + # because this report pre-opens the output file. + # HTMLReport does this using the Report plumbing because + # its task is more complex, being multiple files. + ensure_dir_for_file(output_path) + open_kwargs = {} + if env.PY3: + open_kwargs["encoding"] = "utf8" + outfile = open(output_path, "w", **open_kwargs) + file_to_close = outfile + try: return reporter.report(morfs, outfile=outfile) except CoverageException: @@ -40,7 +42,7 @@ def render_report(output_path, reporter, morfs): if file_to_close: file_to_close.close() if delete_file: - file_be_gone(output_path) + file_be_gone(output_path) # pragma: part covered (doesn't return) def get_analysis_to_report(coverage, morfs): |