diff --git a/coverage/control.py b/coverage/control.py index b052d4b4c..50766548f 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -926,7 +926,7 @@ def analysis2( coverage data. """ - analysis = self._analyze(morf) + analysis = self.analyze(morf) return ( analysis.filename, sorted(analysis.statements), @@ -935,7 +935,7 @@ def analysis2( analysis.missing_formatted(), ) - def _analyze(self, morf: TMorf) -> Analysis: + def analyze(self, morf: TMorf) -> Analysis: """Analyze a module or file. Private for now.""" self._init() self._post_init() diff --git a/coverage/report_core.py b/coverage/report_core.py index 477034bae..db40e3ad1 100644 --- a/coverage/report_core.py +++ b/coverage/report_core.py @@ -98,7 +98,7 @@ def get_analysis_to_report( for fr, morf in sorted(fr_morfs): try: - analysis = coverage._analyze(morf) + analysis = coverage.analyze(morf) except NotPython: # Only report errors for .py files, and only if we didn't # explicitly suppress those errors. diff --git a/doc/api.rst b/doc/api.rst index 7d04f03ee..a39ffad30 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -55,4 +55,5 @@ only. :ref:`dbschema` explains more. api_module api_plugin api_coveragedata + api_analysis dbschema diff --git a/doc/api_analysis.rst b/doc/api_analysis.rst new file mode 100644 index 000000000..9424c2c95 --- /dev/null +++ b/doc/api_analysis.rst @@ -0,0 +1,10 @@ +.. Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +.. For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt + +.. _api_analysis: + +The Analysis class +------------------ + +.. autoclass:: coverage.results.Analysis + :members: branch_stats diff --git a/tests/coveragetest.py b/tests/coveragetest.py index 244a68a29..6c5e1acab 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -197,7 +197,7 @@ def check_coverage( del sys.modules[modname] # Get the analysis results, and check that they are right. - analysis = cov._analyze(mod) + analysis = cov.analyze(mod) statements = sorted(analysis.statements) if lines: if isinstance(lines[0], int): @@ -493,7 +493,7 @@ def get_missing_arc_description(self, cov: Coverage, start: TLineNo, end: TLineN assert self.last_module_name is not None filename = self.last_module_name + ".py" fr = cov._get_file_reporter(filename) - arcs_executed = cov._analyze(filename).arcs_executed + arcs_executed = cov.analyze(filename).arcs_executed return fr.missing_arc_description(start, end, arcs_executed) diff --git a/tests/test_api.py b/tests/test_api.py index ab738e3c3..5a744dc91 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1016,7 +1016,7 @@ def fun2(x): # Import the Python file, executing it. self.start_import_stop(cov, "missing") - nums = cov._analyze("missing.py").numbers + nums = cov.analyze("missing.py").numbers assert nums.n_files == 1 assert nums.n_statements == 7 assert nums.n_excluded == 1 diff --git a/tests/test_plugins.py b/tests/test_plugins.py index b3c8cd6f6..e6d720e7a 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -410,7 +410,7 @@ def test_plugin2_with_branch(self) -> None: # The way plugin2 works, a file named foo_7.html will be claimed to # have 7 lines in it. If render() was called with line number 4, # then the plugin will claim that lines 4 and 5 were executed. - analysis = cov._analyze("foo_7.html") + analysis = cov.analyze("foo_7.html") assert analysis.statements == {1, 2, 3, 4, 5, 6, 7} # Plugins don't do branch coverage yet. assert analysis.has_arcs is True