Skip to content

Commit

Permalink
refactor: keep Analysis private
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Apr 23, 2024
1 parent 40a052e commit b115ed3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions coverage/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ def analysis2(
coverage data.
"""
analysis = self.analyze(morf)
analysis = self._analyze(morf)
return (
analysis.filename,
sorted(analysis.statements),
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion coverage/report_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions tests/coveragetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b115ed3

Please sign in to comment.