99)
1010from codeflash .models .models import TestsInFile , TestType
1111from codeflash .verification .verification_utils import TestConfig
12+ from codeflash .discovery .functions_to_optimize import FunctionToOptimize
1213
1314
1415def test_unit_test_discovery_pytest ():
@@ -832,8 +833,8 @@ def test_something():
832833 target_functions = {"target_function" }
833834 should_process , found_functions = analyze_imports_in_test_file (test_file , target_functions )
834835
835- assert should_process is True # Conservative approach with star imports
836- assert found_functions == set () # No specific functions identified
836+ assert should_process is False
837+ assert found_functions == set ()
837838
838839
839840def test_analyze_imports_module_import ():
@@ -907,13 +908,11 @@ def test_unrelated():
907908
908909 target_functions = {"target_function" , "another_function" }
909910 should_process , found_functions = analyze_imports_in_test_file (test_file , target_functions )
910-
911911 assert should_process is False
912912 assert found_functions == set ()
913913
914914
915- def test_analyze_imports_heuristic_matching ():
916- """Test heuristic module name matching."""
915+ def test_analyze_qualified_names ():
917916 with tempfile .TemporaryDirectory () as tmpdirname :
918917 test_file = Path (tmpdirname ) / "test_example.py"
919918 test_content = """
@@ -924,11 +923,11 @@ def test_target():
924923"""
925924 test_file .write_text (test_content )
926925
927- target_functions = {"target_function" } # Function name partially matches module name
926+ target_functions = {"target_module.some_function" }
928927 should_process , found_functions = analyze_imports_in_test_file (test_file , target_functions )
929-
930928 assert should_process is True
931- assert "target_function" in found_functions
929+ assert "target_module.some_function" in found_functions
930+
932931
933932
934933def test_analyze_imports_syntax_error ():
@@ -952,7 +951,6 @@ def test_target(
952951
953952
954953def test_filter_test_files_by_imports ():
955- """Test the complete filtering functionality."""
956954 with tempfile .TemporaryDirectory () as tmpdirname :
957955 tmpdir = Path (tmpdirname )
958956
@@ -974,7 +972,7 @@ def test_other():
974972 assert other_function() is True
975973""" )
976974
977- # Create test file with star import (should be processed)
975+ # Create test file with star import (should not be processed)
978976 star_test = tmpdir / "test_star.py"
979977 star_test .write_text ("""
980978from mymodule import *
@@ -983,7 +981,6 @@ def test_star():
983981 assert something() is True
984982""" )
985983
986- # Build file_to_test_map
987984 file_to_test_map = {
988985 relevant_test : [TestsInFile (test_file = relevant_test , test_function = "test_target" , test_class = None , test_type = TestType .EXISTING_UNIT_TEST )],
989986 irrelevant_test : [TestsInFile (test_file = irrelevant_test , test_function = "test_other" , test_class = None , test_type = TestType .EXISTING_UNIT_TEST )],
@@ -993,16 +990,15 @@ def test_star():
993990 target_functions = {"target_function" }
994991 filtered_map , import_results = filter_test_files_by_imports (file_to_test_map , target_functions )
995992
996- # Should filter out irrelevant_test but keep relevant_test and star_test
997- assert len (filtered_map ) == 2
993+ # Should filter out irrelevant_test
994+ assert len (filtered_map ) == 1
998995 assert relevant_test in filtered_map
999- assert star_test in filtered_map
1000996 assert irrelevant_test not in filtered_map
1001997
1002998 # Check import analysis results
1003999 assert "target_function" in import_results [relevant_test ]
10041000 assert len (import_results [irrelevant_test ]) == 0
1005- assert len (import_results [star_test ]) == 0 # Star import doesn't identify specific functions
1001+ assert len (import_results [star_test ]) == 0
10061002
10071003
10081004def test_filter_test_files_no_target_functions ():
@@ -1066,18 +1062,17 @@ def test_other():
10661062 tests_project_rootdir = tmpdir .parent ,
10671063 )
10681064
1069- # Test without filtering
10701065 all_tests , _ = discover_unit_tests (test_config )
1071- assert len (all_tests ) == 2 # Should find both functions
1072-
1073- # Test with filtering - create mock FunctionToOptimize objects
1074- from unittest .mock import Mock
1075- mock_function = Mock ()
1076- mock_function .qualified_name_with_modules_from_root .return_value = "mycode.target_function"
1077- mock_function .function_name = "target_function"
1078- mock_function .parents = [] # No parent classes
1066+ assert len (all_tests ) == 2
10791067
1080- filtered_tests , _ = discover_unit_tests (test_config , file_to_funcs_to_optimize = {code_file : [mock_function ]})
1068+
1069+ fto = FunctionToOptimize (
1070+ function_name = "target_function" ,
1071+ file_path = code_file ,
1072+ parents = [],
1073+ )
1074+
1075+ filtered_tests , _ = discover_unit_tests (test_config , file_to_funcs_to_optimize = {code_file : [fto ]})
10811076 assert len (filtered_tests ) >= 1
10821077 assert "mycode.target_function" in filtered_tests
10831078
@@ -1146,7 +1141,6 @@ def test_aliased():
11461141
11471142
11481143def test_analyze_imports_underscore_function_names ():
1149- """Test handling of function names with underscores in heuristic matching."""
11501144 with tempfile .TemporaryDirectory () as tmpdirname :
11511145 test_file = Path (tmpdirname ) / "test_example.py"
11521146 test_content = """
@@ -1157,12 +1151,11 @@ def test_bubble():
11571151"""
11581152 test_file .write_text (test_content )
11591153
1160- target_functions = {"bubble_sort" } # Function name parts match module
1154+ target_functions = {"bubble_sort" }
11611155 should_process , found_functions = analyze_imports_in_test_file (test_file , target_functions )
11621156
1163- assert should_process is True
1164- assert "bubble_sort" in found_functions
1165-
1157+ assert should_process is False
1158+ assert "bubble_sort" not in found_functions
11661159
11671160def test_discover_unit_tests_filtering_different_modules ():
11681161 """Test import filtering with test files from completely different modules."""
0 commit comments