Skip to content

Commit defc4ca

Browse files
committed
Make branch coverage accessible via the API
1 parent 3ed5915 commit defc4ca

File tree

7 files changed

+18
-7
lines changed

7 files changed

+18
-7
lines changed

coverage/control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ def analysis2(
926926
coverage data.
927927
928928
"""
929-
analysis = self._analyze(morf)
929+
analysis = self.analyze(morf)
930930
return (
931931
analysis.filename,
932932
sorted(analysis.statements),
@@ -935,7 +935,7 @@ def analysis2(
935935
analysis.missing_formatted(),
936936
)
937937

938-
def _analyze(self, morf: TMorf) -> Analysis:
938+
def analyze(self, morf: TMorf) -> Analysis:
939939
"""Analyze a module or file. Private for now."""
940940
self._init()
941941
self._post_init()

coverage/report_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def get_analysis_to_report(
9898

9999
for fr, morf in sorted(fr_morfs):
100100
try:
101-
analysis = coverage._analyze(morf)
101+
analysis = coverage.analyze(morf)
102102
except NotPython:
103103
# Only report errors for .py files, and only if we didn't
104104
# explicitly suppress those errors.

doc/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ only. :ref:`dbschema` explains more.
5555
api_module
5656
api_plugin
5757
api_coveragedata
58+
api_analysis
5859
dbschema

doc/api_analysis.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
2+
.. For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
3+
4+
.. _api_analysis:
5+
6+
The Analysis class
7+
------------------
8+
9+
.. autoclass:: coverage.results.Analysis
10+
:members: branch_stats

tests/coveragetest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def check_coverage(
197197
del sys.modules[modname]
198198

199199
# Get the analysis results, and check that they are right.
200-
analysis = cov._analyze(mod)
200+
analysis = cov.analyze(mod)
201201
statements = sorted(analysis.statements)
202202
if lines:
203203
if isinstance(lines[0], int):
@@ -493,7 +493,7 @@ def get_missing_arc_description(self, cov: Coverage, start: TLineNo, end: TLineN
493493
assert self.last_module_name is not None
494494
filename = self.last_module_name + ".py"
495495
fr = cov._get_file_reporter(filename)
496-
arcs_executed = cov._analyze(filename).arcs_executed
496+
arcs_executed = cov.analyze(filename).arcs_executed
497497
return fr.missing_arc_description(start, end, arcs_executed)
498498

499499

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ def fun2(x):
10161016
# Import the Python file, executing it.
10171017
self.start_import_stop(cov, "missing")
10181018

1019-
nums = cov._analyze("missing.py").numbers
1019+
nums = cov.analyze("missing.py").numbers
10201020
assert nums.n_files == 1
10211021
assert nums.n_statements == 7
10221022
assert nums.n_excluded == 1

tests/test_plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def test_plugin2_with_branch(self) -> None:
410410
# The way plugin2 works, a file named foo_7.html will be claimed to
411411
# have 7 lines in it. If render() was called with line number 4,
412412
# then the plugin will claim that lines 4 and 5 were executed.
413-
analysis = cov._analyze("foo_7.html")
413+
analysis = cov.analyze("foo_7.html")
414414
assert analysis.statements == {1, 2, 3, 4, 5, 6, 7}
415415
# Plugins don't do branch coverage yet.
416416
assert analysis.has_arcs is True

0 commit comments

Comments
 (0)