refactor: remove dead parameters from AsyncCallInstrumenter and inject_async_profiling

Drop unused module_path, mode, tests_project_root parameters and the
module_name_from_file_path import they required. Update all call sites.
This commit is contained in:
Kevin Turcios 2026-04-24 02:49:05 -05:00
parent c670d637c0
commit 24199efc63
3 changed files with 6 additions and 34 deletions

View file

@ -21,7 +21,6 @@ from .._model import (
TestingMode,
)
from ..analysis._formatter import sort_imports
from ..test_discovery.linking import module_name_from_file_path
from ._instrument_core import (
FunctionImportedAsVisitor,
node_in_call_position,
@ -39,11 +38,9 @@ class AsyncCallInstrumenter(ast.NodeTransformer):
def __init__(
self,
function: FunctionToOptimize,
module_path: str,
call_positions: list[CodePosition],
mode: TestingMode = TestingMode.BEHAVIOR,
) -> None:
"""Initialize with the target async function and testing mode."""
"""Initialize with the target async function and call positions."""
self.function_object = function
self.call_positions = call_positions
self.did_instrument = False
@ -268,8 +265,6 @@ def inject_async_profiling_into_existing_test(
test_path: Path,
call_positions: list[CodePosition],
function_to_optimize: FunctionToOptimize,
tests_project_root: Path,
mode: TestingMode = TestingMode.BEHAVIOR,
) -> tuple[bool, str | None]:
"""Inject profiling for async function calls in a test file."""
with test_path.open(encoding="utf8") as f:
@ -284,19 +279,11 @@ def inject_async_profiling_into_existing_test(
)
return False, None
test_module_path = module_name_from_file_path(
test_path, tests_project_root
)
import_visitor = FunctionImportedAsVisitor(function_to_optimize)
import_visitor.visit(tree)
func = import_visitor.imported_as
async_instrumenter = AsyncCallInstrumenter(
func,
test_module_path,
call_positions,
mode=mode,
)
async_instrumenter = AsyncCallInstrumenter(func, call_positions)
tree = async_instrumenter.visit(tree)
if not async_instrumenter.did_instrument:

View file

@ -640,8 +640,6 @@ def inject_profiling_into_existing_test(
test_path,
call_positions,
function_to_optimize,
tests_project_root,
mode,
)
with test_path.open(encoding="utf8") as f:

View file

@ -494,7 +494,6 @@ class TestAsyncCallInstrumenter:
)
transformer = AsyncCallInstrumenter(
function=func,
module_path="module",
call_positions=positions,
)
return transformer, tree
@ -1065,9 +1064,7 @@ class TestInjectAsyncProfilingIntoExistingTest:
def test_async_instrumentation(self, tmp_path: Path) -> None:
"""Instruments an async test file and adds import os."""
project_root = tmp_path / "project"
project_root.mkdir()
test_file = project_root / "test_async_ex.py"
test_file = tmp_path / "test_async_ex.py"
test_code = textwrap.dedent("""\
from module import target_func
@ -1083,7 +1080,6 @@ class TestInjectAsyncProfilingIntoExistingTest:
test_file,
positions,
func,
project_root,
)
assert ok is True
assert source is not None
@ -1091,9 +1087,7 @@ class TestInjectAsyncProfilingIntoExistingTest:
def test_no_instrumentation(self, tmp_path: Path) -> None:
"""Returns (False, None) when test does not call target."""
project_root = tmp_path / "project"
project_root.mkdir()
test_file = project_root / "test_no_call.py"
test_file = tmp_path / "test_no_call.py"
test_code = textwrap.dedent("""\
def test_something():
assert 1 == 1
@ -1107,16 +1101,13 @@ class TestInjectAsyncProfilingIntoExistingTest:
test_file,
positions,
func,
project_root,
)
assert ok is False
assert source is None
def test_syntax_error_returns_false(self, tmp_path: Path) -> None:
"""Returns (False, None) for a file with invalid Python."""
project_root = tmp_path / "project"
project_root.mkdir()
test_file = project_root / "test_bad.py"
test_file = tmp_path / "test_bad.py"
test_file.write_text(
"async def test_x(\n not valid !!!",
encoding="utf-8",
@ -1126,7 +1117,6 @@ class TestInjectAsyncProfilingIntoExistingTest:
test_file,
[CodePosition(line_no=1, col_no=0)],
func,
project_root,
)
assert ok is False
assert source is None
@ -1136,9 +1126,7 @@ class TestInjectAsyncProfilingIntoExistingTest:
tmp_path: Path,
) -> None:
"""Multiple awaited calls in one test get sequential counter IDs."""
project_root = tmp_path / "project"
project_root.mkdir()
test_file = project_root / "test_multi.py"
test_file = tmp_path / "test_multi.py"
test_code = textwrap.dedent("""\
from module import target_func
@ -1157,7 +1145,6 @@ class TestInjectAsyncProfilingIntoExistingTest:
test_file,
positions,
func,
project_root,
)
assert ok is True
assert source is not None