From b115ed34fcf65bdf444e4d79fc15a9a987aad24d Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 22 Apr 2024 08:09:30 -0400 Subject: [PATCH] refactor: keep Analysis private --- coverage/control.py | 6 +++--- coverage/report_core.py | 2 +- tests/coveragetest.py | 4 ++-- tests/test_api.py | 2 +- tests/test_plugins.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/coverage/control.py b/coverage/control.py index ab37a3c1a..dbca2013d 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -922,7 +922,7 @@ def analysis2( coverage data. """ - analysis = self.analyze(morf) + analysis = self._analyze(morf) return ( analysis.filename, sorted(analysis.statements), @@ -931,8 +931,8 @@ def analysis2( analysis.missing_formatted(), ) - def analyze(self, morf: TMorf) -> Analysis: - """A public API for getting Analysis. TODO!!! """ + 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 dc62ff04d..db0e7b280 100644 --- a/coverage/report_core.py +++ b/coverage/report_core.py @@ -97,7 +97,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/tests/coveragetest.py b/tests/coveragetest.py index 9eee21b4c..8d17860fb 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -209,7 +209,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): @@ -513,7 +513,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 653cc6d66..9f65166b9 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1023,7 +1023,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 8167293cc..9f0b0cc3f 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -409,7 +409,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