@@ -64,8 +64,14 @@ def mock_config():
6464
6565@pytest .mark .asyncio
6666async def test_get_query_result_files (mock_collection , mock_config ):
67- # Mock the reranker
68- with patch ("vectorcode.subcommands.query.get_reranker" ) as mock_get_reranker :
67+ mock_embedding_function = MagicMock ()
68+ with (
69+ patch ("vectorcode.subcommands.query.get_reranker" ) as mock_get_reranker ,
70+ patch (
71+ "vectorcode.subcommands.query.get_embedding_function" ,
72+ return_value = mock_embedding_function ,
73+ ),
74+ ):
6975 mock_reranker_instance = MagicMock ()
7076 mock_reranker_instance .rerank = AsyncMock (
7177 return_value = [
@@ -82,9 +88,7 @@ async def test_get_query_result_files(mock_collection, mock_config):
8288 # Check that query was called with the right parameters
8389 mock_collection .query .assert_called_once ()
8490 args , kwargs = mock_collection .query .call_args
85- assert kwargs ["query_texts" ] == [
86- "test query"
87- ] # Assuming chunking produces this
91+ mock_embedding_function .assert_called_once_with (["test query" ])
8892 assert kwargs ["n_results" ] == 6 # n_result(3) * query_multiplier(2)
8993 assert IncludeEnum .metadatas in kwargs ["include" ]
9094 assert IncludeEnum .distances in kwargs ["include" ]
@@ -285,10 +289,14 @@ async def test_get_query_result_files_chunking(mock_collection, mock_config):
285289 mock_config .query = [
286290 "this is a longer query that should be chunked into multiple parts"
287291 ]
288-
292+ mock_embedding_function = MagicMock ()
289293 with (
290294 patch ("vectorcode.subcommands.query.StringChunker" ) as MockChunker ,
291295 patch ("vectorcode.subcommands.query.reranker.NaiveReranker" ) as MockReranker ,
296+ patch (
297+ "vectorcode.subcommands.query.get_embedding_function" ,
298+ return_value = mock_embedding_function ,
299+ ),
292300 ):
293301 # Set up MockChunker to chunk the query
294302 mock_chunker_instance = MagicMock ()
@@ -309,7 +317,7 @@ async def test_get_query_result_files_chunking(mock_collection, mock_config):
309317 # Check query was called with chunked query
310318 mock_collection .query .assert_called_once ()
311319 _ , kwargs = mock_collection .query .call_args
312- assert kwargs [ "query_texts" ] == [ " chunk1" , "chunk2" , "chunk3" ]
320+ mock_embedding_function . assert_called_once_with ([ " chunk1" , "chunk2" , "chunk3" ])
313321
314322 # Check the result
315323 assert result == ["file1.py" , "file2.py" ]
@@ -319,10 +327,14 @@ async def test_get_query_result_files_chunking(mock_collection, mock_config):
319327async def test_get_query_result_files_multiple_queries (mock_collection , mock_config ):
320328 # Set multiple query terms
321329 mock_config .query = ["term1" , "term2" , "term3" ]
322-
330+ mock_embedding_function = MagicMock ()
323331 with (
324332 patch ("vectorcode.subcommands.query.StringChunker" ) as MockChunker ,
325333 patch ("vectorcode.subcommands.query.reranker.NaiveReranker" ) as MockReranker ,
334+ patch (
335+ "vectorcode.subcommands.query.get_embedding_function" ,
336+ return_value = mock_embedding_function ,
337+ ),
326338 ):
327339 # Set up MockChunker to return the query terms as is
328340 mock_chunker_instance = MagicMock ()
@@ -342,7 +354,7 @@ async def test_get_query_result_files_multiple_queries(mock_collection, mock_con
342354 # Check query was called with all query terms
343355 mock_collection .query .assert_called_once ()
344356 _ , kwargs = mock_collection .query .call_args
345- assert set ( kwargs [ "query_texts" ]) == set (["term1" , "term2" , "term3" ])
357+ mock_embedding_function . assert_called_once_with (["term1" , "term2" , "term3" ])
346358
347359 # Check the result
348360 assert result == ["file1.py" , "file2.py" ]
0 commit comments