diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2022-01-22 15:19:23 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-01-22 16:48:59 -0500 |
commit | 3f221e0339b74137bbf45289497955700dc49feb (patch) | |
tree | 59530795e7037508e4590264561adc281e2f28ab | |
parent | cbe2e205dac99f20afff4ccdeca21fd10d596565 (diff) | |
download | python-coveragepy-git-3f221e0339b74137bbf45289497955700dc49feb.tar.gz |
fix: small fixes to lcov, and changes.rst mention.
-rw-r--r-- | CHANGES.rst | 3 | ||||
-rw-r--r-- | CONTRIBUTORS.txt | 1 | ||||
-rw-r--r-- | coverage/config.py | 5 | ||||
-rw-r--r-- | coverage/lcovreport.py | 6 | ||||
-rw-r--r-- | doc/cmd.rst | 2 | ||||
-rw-r--r-- | tests/test_lcov.py | 10 |
6 files changed, 16 insertions, 11 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index b3f398a7..d9af1e44 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -22,6 +22,9 @@ This list is detailed and covers changes in each pre-release version. Unreleased ---------- +- Feature: Added the `lcov` command to generate reports in LCOV format. + Thanks, Bradley Burns. + - Dropped support for Python 3.6, which reached end-of-life on 2021-12-23. - Updated Python 3.11 support to 3.11.0a4, fixing `issue 1294`_. diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 81080d51..e422cd2a 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -24,6 +24,7 @@ Ben Carlsson Ben Finney Bernát Gábor Bill Hart +Bradley Burns Brandon Rhodes Brett Cannon Bruno P. Kinoshita diff --git a/coverage/config.py b/coverage/config.py index 75217def..9909c530 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -227,7 +227,7 @@ class CoverageConfig: self.json_pretty_print = False self.json_show_contexts = False - # Default output filename for lcov_reporter + # Defaults for [lcov] self.lcov_output = "coverage.lcov" # Defaults for [paths] @@ -400,6 +400,9 @@ class CoverageConfig: ('json_output', 'json:output'), ('json_pretty_print', 'json:pretty_print', 'boolean'), ('json_show_contexts', 'json:show_contexts', 'boolean'), + + # [lcov] + ('lcov_output', 'lcov:output'), ] def _set_attr_from_config_option(self, cp, attr, where, type_=''): diff --git a/coverage/lcovreport.py b/coverage/lcovreport.py index 5a49ac4a..770f7a25 100644 --- a/coverage/lcovreport.py +++ b/coverage/lcovreport.py @@ -61,10 +61,8 @@ class LcovReporter: hashed = str(base64.b64encode(md5(line).digest())[:-2], encoding="utf-8") outfile.write(f"DA:{covered},1,{hashed}\n") for missed in sorted(analysis.missing): - if source_lines: - line = source_lines[missed - 1].encode("utf-8") - else: - line = b"" + assert source_lines + line = source_lines[missed-1].encode("utf-8") hashed = str(base64.b64encode(md5(line).digest())[:-2], encoding="utf-8") outfile.write(f"DA:{missed},0,{hashed}\n") outfile.write(f"LF:{len(analysis.statements)}\n") diff --git a/doc/cmd.rst b/doc/cmd.rst index f4cbff34..5bb0bd34 100644 --- a/doc/cmd.rst +++ b/doc/cmd.rst @@ -792,7 +792,7 @@ can be nicely formatted by specifying the ``--pretty-print`` switch. LCOV reporting: ``coverage lcov`` --------------------------------- -The **json** command writes coverage data to a "coverage.lcov" file. +The **lcov** command writes coverage data to a "coverage.lcov" file. .. [[[cog show_help("lcov") ]]] .. code:: diff --git a/tests/test_lcov.py b/tests/test_lcov.py index 9d2f8ec6..fcb17f93 100644 --- a/tests/test_lcov.py +++ b/tests/test_lcov.py @@ -49,9 +49,8 @@ class LcovTest(CoverageTest): """, ) - def get_lcov_report_content(self): - """Return the content of the LCOV report.""" - filename = "coverage.lcov" + def get_lcov_report_content(self, filename="coverage.lcov"): + """Return the content of an LCOV report.""" with open(filename, "r") as file: file_contents = file.read() return file_contents @@ -96,10 +95,11 @@ class LcovTest(CoverageTest): and matches the output of the file below.""" self.create_initial_files() self.assert_doesnt_exist(".coverage") + self.make_file(".coveragerc", "[lcov]\noutput = data.lcov\n") cov = coverage.Coverage(source=".") self.start_import_stop(cov, "test_file") cov.lcov_report() - self.assert_exists("coverage.lcov") + self.assert_exists("data.lcov") expected_result = """\ TN: SF:main_file.py @@ -125,7 +125,7 @@ class LcovTest(CoverageTest): end_of_record """ expected_result = textwrap.dedent(expected_result) - actual_result = self.get_lcov_report_content() + actual_result = self.get_lcov_report_content(filename="data.lcov") assert expected_result == actual_result def test_branch_coverage_one_file(self): |