Skip to content

Commit fee08a6

Browse files
committed
we don't use found_target_functions
1 parent a73d2d4 commit fee08a6

File tree

2 files changed

+20
-38
lines changed

2 files changed

+20
-38
lines changed

codeflash/discovery/discover_unit_tests.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ def visit_Attribute(self, node: ast.Attribute) -> None:
217217
self.generic_visit(node)
218218

219219

220-
def analyze_imports_in_test_file(test_file_path: Path | str, target_functions: set[str]) -> tuple[bool, set[str]]:
220+
def analyze_imports_in_test_file(test_file_path: Path | str, target_functions: set[str]) -> bool:
221221
"""Analyze imports in a test file to determine if it might test any target functions.
222222
223223
Args:
224224
test_file_path: Path to the test file
225225
target_functions: Set of function names we're looking for
226226
227227
Returns:
228-
Tuple of (should_process_with_jedi, found_function_names)
228+
bool: True if the test file should be processed (contains relevant imports), False otherwise
229229
230230
"""
231231
if isinstance(test_file_path, str):
@@ -239,14 +239,11 @@ def analyze_imports_in_test_file(test_file_path: Path | str, target_functions: s
239239
analyzer = ImportAnalyzer(target_functions)
240240
analyzer.visit(tree)
241241

242-
if analyzer.found_target_functions:
243-
return True, analyzer.found_target_functions
244-
245-
return False, set() # noqa: TRY300
242+
return bool(analyzer.found_target_functions)
246243

247244
except (SyntaxError, UnicodeDecodeError, OSError) as e:
248245
logger.debug(f"Failed to analyze imports in {test_file_path}: {e}")
249-
return True, set()
246+
return True
250247

251248

252249
def filter_test_files_by_imports(
@@ -268,16 +265,15 @@ def filter_test_files_by_imports(
268265
logger.debug(f"Target functions for import filtering: {target_functions}")
269266

270267
filtered_map = {}
271-
num_analyzed = 0
272268

273269
for test_file, test_functions in file_to_test_map.items():
274-
should_process, found_functions = analyze_imports_in_test_file(test_file, target_functions)
275-
num_analyzed += 1
276-
270+
should_process = analyze_imports_in_test_file(test_file, target_functions)
277271
if should_process:
278272
filtered_map[test_file] = test_functions
279273

280-
logger.debug(f"analyzed {num_analyzed} test files for imports, filtered down to {len(filtered_map)} relevant files")
274+
logger.debug(
275+
f"analyzed {len(file_to_test_map)} test files for imports, filtered down to {len(filtered_map)} relevant files"
276+
)
281277
return filtered_map
282278

283279

tests/test_unit_test_discovery.py

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -811,11 +811,9 @@ def test_target():
811811
test_file.write_text(test_content)
812812

813813
target_functions = {"target_function", "missing_function"}
814-
should_process, found_functions = analyze_imports_in_test_file(test_file, target_functions)
814+
should_process = analyze_imports_in_test_file(test_file, target_functions)
815815

816816
assert should_process is True
817-
assert "target_function" in found_functions
818-
assert "missing_function" not in found_functions
819817

820818

821819
def test_analyze_imports_star_import():
@@ -831,10 +829,9 @@ def test_something():
831829
test_file.write_text(test_content)
832830

833831
target_functions = {"target_function"}
834-
should_process, found_functions = analyze_imports_in_test_file(test_file, target_functions)
832+
should_process = analyze_imports_in_test_file(test_file, target_functions)
835833

836834
assert should_process is False
837-
assert found_functions == set()
838835

839836

840837
def test_analyze_imports_module_import():
@@ -850,10 +847,9 @@ def test_target():
850847
test_file.write_text(test_content)
851848

852849
target_functions = {"target_function"}
853-
should_process, found_functions = analyze_imports_in_test_file(test_file, target_functions)
850+
should_process = analyze_imports_in_test_file(test_file, target_functions)
854851

855852
assert should_process is True
856-
assert "target_function" in found_functions
857853

858854

859855
def test_analyze_imports_dynamic_import():
@@ -870,10 +866,9 @@ def test_dynamic():
870866
test_file.write_text(test_content)
871867

872868
target_functions = {"target_function"}
873-
should_process, found_functions = analyze_imports_in_test_file(test_file, target_functions)
869+
should_process = analyze_imports_in_test_file(test_file, target_functions)
874870

875871
assert should_process is True
876-
assert "target_function" in found_functions
877872

878873

879874
def test_analyze_imports_builtin_import():
@@ -888,10 +883,9 @@ def test_builtin_import():
888883
test_file.write_text(test_content)
889884

890885
target_functions = {"target_function"}
891-
should_process, found_functions = analyze_imports_in_test_file(test_file, target_functions)
886+
should_process = analyze_imports_in_test_file(test_file, target_functions)
892887

893888
assert should_process is True
894-
assert "target_function" in found_functions
895889

896890

897891
def test_analyze_imports_no_matching_imports():
@@ -907,9 +901,8 @@ def test_unrelated():
907901
test_file.write_text(test_content)
908902

909903
target_functions = {"target_function", "another_function"}
910-
should_process, found_functions = analyze_imports_in_test_file(test_file, target_functions)
904+
should_process = analyze_imports_in_test_file(test_file, target_functions)
911905
assert should_process is False
912-
assert found_functions == set()
913906

914907

915908
def test_analyze_qualified_names():
@@ -924,9 +917,8 @@ def test_target():
924917
test_file.write_text(test_content)
925918

926919
target_functions = {"target_module.some_function"}
927-
should_process, found_functions = analyze_imports_in_test_file(test_file, target_functions)
920+
should_process = analyze_imports_in_test_file(test_file, target_functions)
928921
assert should_process is True
929-
assert "target_module.some_function" in found_functions
930922

931923

932924

@@ -943,11 +935,10 @@ def test_target(
943935
test_file.write_text(test_content)
944936

945937
target_functions = {"target_function"}
946-
should_process, found_functions = analyze_imports_in_test_file(test_file, target_functions)
938+
should_process = analyze_imports_in_test_file(test_file, target_functions)
947939

948940
# Should be conservative with unparseable files
949941
assert should_process is True
950-
assert found_functions == set()
951942

952943

953944
def test_filter_test_files_by_imports():
@@ -1085,10 +1076,9 @@ def test_conditional():
10851076
test_file.write_text(test_content)
10861077

10871078
target_functions = {"target_function"}
1088-
should_process, found_functions = analyze_imports_in_test_file(test_file, target_functions)
1079+
should_process = analyze_imports_in_test_file(test_file, target_functions)
10891080

10901081
assert should_process is True
1091-
assert "target_function" in found_functions
10921082

10931083

10941084
def test_analyze_imports_function_name_in_code():
@@ -1108,10 +1098,9 @@ def test_indirect():
11081098
test_file.write_text(test_content)
11091099

11101100
target_functions = {"target_function"}
1111-
should_process, found_functions = analyze_imports_in_test_file(test_file, target_functions)
1101+
should_process = analyze_imports_in_test_file(test_file, target_functions)
11121102

11131103
assert should_process is True
1114-
assert "target_function" in found_functions
11151104

11161105

11171106
def test_analyze_imports_aliased_imports():
@@ -1128,11 +1117,9 @@ def test_aliased():
11281117
test_file.write_text(test_content)
11291118

11301119
target_functions = {"target_function", "missing_function"}
1131-
should_process, found_functions = analyze_imports_in_test_file(test_file, target_functions)
1120+
should_process = analyze_imports_in_test_file(test_file, target_functions)
11321121

11331122
assert should_process is True
1134-
assert "target_function" in found_functions
1135-
assert "missing_function" not in found_functions
11361123

11371124

11381125
def test_analyze_imports_underscore_function_names():
@@ -1147,10 +1134,9 @@ def test_bubble():
11471134
test_file.write_text(test_content)
11481135

11491136
target_functions = {"bubble_sort"}
1150-
should_process, found_functions = analyze_imports_in_test_file(test_file, target_functions)
1137+
should_process = analyze_imports_in_test_file(test_file, target_functions)
11511138

11521139
assert should_process is False
1153-
assert "bubble_sort" not in found_functions
11541140

11551141
def test_discover_unit_tests_filtering_different_modules():
11561142
"""Test import filtering with test files from completely different modules."""

0 commit comments

Comments
 (0)