2121## These functions are used as monkey-patched implementations for the actual functions.
2222## In Monkey-Patching, we temporarily replace the original function with a dummy function for testing purposes.
2323
24-
2524# A fake implementation for find_python_files
2625def fake_find_python_files (project_path : str ):
2726 # Return a list with a single file in the project path.
@@ -59,18 +58,15 @@ def dummy_build_python_index(project_path: str):
5958 parsed_files ,
6059 )
6160
62-
6361# Dummy snippet generator.
6462def dummy_get_code_snippets (file_name , start , end ):
6563 return f"code from { file_name } lines { start } -{ end } "
6664
67-
6865class TestSearchBackend :
6966
7067 def test_build_index (self , monkeypatch ):
7168 # Create an instance of SearchBackend with a dummy project_path.
7269 sb = SearchBackend (project_path = "dummy_project" )
73-
7470 # Clear the indices to start fresh.
7571 sb .class_index = {}
7672 sb .class_func_index = {}
@@ -96,7 +92,6 @@ def test_build_index(self, monkeypatch):
9692 def test_update_indices (self ):
9793 # Create a SearchBackend instance with a dummy project path.
9894 sb = SearchBackend (project_path = "dummy_project" )
99-
10095 # Reset indexes to empty to start with a known state.
10196 sb .class_index = {}
10297 sb .class_func_index = {}
@@ -112,7 +107,6 @@ def test_update_indices(self):
112107 dummy_function_index = {"func" : [("file2.py" , (20 , 30 ))]}
113108 dummy_class_relation_index = {"A" : ["B" , "C" ]}
114109 dummy_parsed_files = ["file1.py" , "file2.py" ]
115-
116110 # Call _update_indices with dummy data.
117111 sb ._update_indices (
118112 dummy_class_index ,
@@ -121,7 +115,6 @@ def test_update_indices(self):
121115 dummy_class_relation_index ,
122116 dummy_parsed_files ,
123117 )
124-
125118 # Verify that the attributes have been updated as expected.
126119 assert sb .class_index == dummy_class_index
127120 assert sb .class_func_index == dummy_class_func_index
@@ -295,7 +288,6 @@ def test_search_func_in_all_classes(self, monkeypatch):
295288 assert res_a .class_name == "ClassA"
296289 assert res_a .func_name == "common"
297290 assert res_a .code == expected_code_a
298-
299291 # Verify result from ClassB.
300292 res_b = next (r for r in results if r .file_path == dummy_file2 )
301293 expected_code_b = dummy_get_code_snippets (dummy_file2 , 25 , 35 )
@@ -408,14 +400,12 @@ def top_func(self):
408400 assert res_top .class_name is None
409401 assert res_top .func_name == "top_func"
410402 assert res_top .code == expected_top
411-
412403 # Verify ClassX method result.
413404 res_classx = next (r for r in results if r .file_path == str (file2 ))
414405 expected_classx = dummy_get_code_snippets (str (file2 ), 2 , 4 )
415406 assert res_classx .class_name == "ClassX"
416407 assert res_classx .func_name == "top_func"
417408 assert res_classx .code == expected_classx
418-
419409 # Verify ClassY method result.
420410 res_classy = next (r for r in results if r .file_path == str (file3 ))
421411 expected_classy = dummy_get_code_snippets (str (file3 ), 2 , 4 )
@@ -425,15 +415,13 @@ def top_func(self):
425415
426416 def test_get_candidate_matched_py_files (self ):
427417 sb = SearchBackend (project_path = "dummy_project" )
428-
429418 # Set up parsed_files with absolute paths (using various cases)
430419 sb .parsed_files = [
431420 "/abs/path/Foo.py" ,
432421 "/abs/path/bar.PY" ,
433422 "/abs/path/Baz.txt" ,
434423 "/abs/path/otherfoo.Py" ,
435424 ]
436-
437425 # Test 1: Find files ending with "foo.py" (case-insensitive).
438426 # Expected candidates: "/abs/path/Foo.py" and "/abs/path/otherfoo.Py"
439427 candidates = sb ._get_candidate_matched_py_files ("foo.py" )
@@ -464,7 +452,6 @@ def test_get_class_full_snippet_not_found(self):
464452
465453 # Call get_class_full_snippet with a class name that doesn't exist.
466454 result , search_res , flag = sb .get_class_full_snippet ("NonExisting" )
467-
468455 # Expect a message indicating that the class was not found, no search results, and flag False.
469456 expected_message = "Could not find class NonExisting in the codebase."
470457 assert result == expected_message
@@ -1540,7 +1527,6 @@ def test_get_file_content_found(self, monkeypatch):
15401527 sb .parsed_files = [dummy_path ]
15411528 # Patch Path.read_text to return dummy content.
15421529 from pathlib import Path
1543-
15441530 monkeypatch .setattr (Path , "read_text" , lambda self : "line1\n line2\n line3" )
15451531 tool_output , results , flag = sb .get_file_content ("existing.py" )
15461532 expected = f"<file>existing.py</file> <code>line1\n line2\n line3</code>"
@@ -1683,12 +1669,10 @@ def test_get_bug_loc_snippets_new_with_method_and_class(
16831669 temp_file = temp_dir / "temp_file.py"
16841670 # Write multiple lines so that line indices 5 to 15 are valid.
16851671 temp_file .write_text ("\n " .join ([f"line { i } " for i in range (1 , 21 )]))
1686-
16871672 # Use the absolute temporary directory as the project path.
16881673 sb = SearchBackend (project_path = str (temp_dir ))
16891674 # Ensure parsed_files contains the temporary file.
16901675 sb .parsed_files = [str (temp_file )]
1691-
16921676 bug_loc = {
16931677 "file" : "temp_file.py" , # should match the end of the temp file path
16941678 "method" : "do_work" ,
0 commit comments