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

View file

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

View file

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