File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -507,11 +507,15 @@ async def delete(self) -> int:
507507 return len (rm_paths )
508508
509509 async def drop (self , * , collection_id = None , collection_path = None ):
510- collection_id = collection_id or get_collection_id (
511- str (collection_path or self ._configs .project_root )
512- )
510+ project_root = str (collection_path or self ._configs .project_root )
511+ collection_id = collection_id or get_collection_id (project_root )
513512 async with _Chroma0ClientManager ().get_client (self ._configs ) as client :
514- await client .delete_collection (collection_id )
513+ try :
514+ await client .delete_collection (collection_id )
515+ except ValueError as e :
516+ raise CollectionNotFoundError (
517+ f"Collection at { project_root } is not found."
518+ ) from e
515519
516520 async def get_chunks (self , file_path ) -> list [Chunk ]:
517521 file_path = os .path .abspath (file_path )
Original file line number Diff line number Diff line change @@ -220,6 +220,26 @@ async def test_drop(mock_config):
220220 mock_client .delete_collection .assert_called_once_with ("collection_id" )
221221
222222
223+ @pytest .mark .asyncio
224+ async def test_drop_invalid_collection (mock_config ):
225+ """Test the drop method."""
226+ connector = ChromaDB0Connector (mock_config )
227+ with (
228+ patch (
229+ "vectorcode.database.chroma0._Chroma0ClientManager.get_client"
230+ ) as mock_get_client ,
231+ patch (
232+ "vectorcode.database.chroma0.get_collection_id" ,
233+ return_value = "collection_id" ,
234+ ),
235+ ):
236+ mock_client = AsyncMock ()
237+ mock_get_client .return_value .__aenter__ .return_value = mock_client
238+ mock_client .delete_collection .side_effect = ValueError
239+ with pytest .raises (CollectionNotFoundError ):
240+ await connector .drop ()
241+
242+
223243@pytest .mark .asyncio
224244async def test_get_chunks (mock_config ):
225245 """Test the get_chunks method."""
You can’t perform that action at this time.
0 commit comments