1- import json
21import os
32import tempfile
43from typing import Any , Dict
@@ -201,7 +200,18 @@ async def test_load_config_file_invalid_json():
201200 with open (config_path , "w" ) as f :
202201 f .write ("invalid json" )
203202
204- with pytest .raises (json .JSONDecodeError ):
203+ with pytest .raises (ValueError ):
204+ await load_config_file (config_path )
205+
206+
207+ @pytest .mark .asyncio
208+ async def test_load_config_file_invalid_config ():
209+ with tempfile .TemporaryDirectory () as temp_dir :
210+ config_path = os .path .join (temp_dir , "config.json" )
211+ with open (config_path , "w" ) as f :
212+ f .write ('"hello world"' )
213+
214+ with pytest .raises (ValueError ):
205215 await load_config_file (config_path )
206216
207217
@@ -225,8 +235,7 @@ async def test_load_config_file_empty_file():
225235 with open (config_path , "w" ) as f :
226236 f .write ("" )
227237
228- with pytest .raises (json .JSONDecodeError ):
229- await load_config_file (config_path )
238+ assert await load_config_file (config_path ) == Config ()
230239
231240
232241@pytest .mark .asyncio
@@ -399,8 +408,22 @@ async def test_get_project_config_local_config(tmp_path):
399408 assert config .host == "test_host"
400409 assert config .port == 9999
401410
402- # Clean up the temporary directory
403- # shutil.rmtree(tmp_path) # Use tmp_path fixture, no need to remove manually
411+
412+ @pytest .mark .asyncio
413+ async def test_get_project_config_local_config_json5 (tmp_path ):
414+ # Create a temporary directory and a .vectorcode subdirectory
415+ project_root = tmp_path / "project"
416+ vectorcode_dir = project_root / ".vectorcode"
417+ vectorcode_dir .mkdir (parents = True )
418+
419+ # Create a config.json file inside .vectorcode with some custom settings
420+ config_file = vectorcode_dir / "config.json5"
421+ config_file .write_text ('{"host": "test_host", "port": 9999}' )
422+
423+ # Call get_project_config and check if it returns the custom settings
424+ config = await get_project_config (project_root )
425+ assert config .host == "test_host"
426+ assert config .port == 9999
404427
405428
406429def test_find_project_root_file_input (tmp_path ):
0 commit comments