File tree Expand file tree Collapse file tree 3 files changed +17
-0
lines changed Expand file tree Collapse file tree 3 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -97,12 +97,16 @@ def run(
9797 async def parse (self , file_path : str , disable_cache : bool = False ) -> list [Text | Tool ]:
9898 out = await self ._run_basic_command ("parse" , {"file" : file_path , "disableCache" : disable_cache })
9999 parsed_nodes = json .loads (out )
100+ if parsed_nodes is None or parsed_nodes .get ("nodes" , None ) is None :
101+ return []
100102 return [Text (** node ["textNode" ]) if "textNode" in node else Tool (** node .get ("toolNode" , {}).get ("tool" , {})) for
101103 node in parsed_nodes .get ("nodes" , [])]
102104
103105 async def parse_tool (self , tool_def : str ) -> list [Text | Tool ]:
104106 out = await self ._run_basic_command ("parse" , {"content" : tool_def })
105107 parsed_nodes = json .loads (out )
108+ if parsed_nodes is None or parsed_nodes .get ("nodes" , None ) is None :
109+ return []
106110 return [Text (** node ["textNode" ]) if "textNode" in node else Tool (** node .get ("toolNode" , {}).get ("tool" , {})) for
107111 node in parsed_nodes .get ("nodes" , [])]
108112
Original file line number Diff line number Diff line change @@ -259,6 +259,19 @@ async def test_parse_simple_file(gptscript):
259259 "Unexpected output from parsing simple file"
260260
261261
262+ @pytest .mark .asyncio
263+ async def test_parse_empty_file (gptscript ):
264+ wd = os .getcwd ()
265+ tools = await gptscript .parse (wd + "/tests//fixtures/empty.gpt" )
266+ assert len (tools ) == 0 , "Unexpected number of tools for parsing emtpy file"
267+
268+
269+ @pytest .mark .asyncio
270+ async def test_parse_empty_str (gptscript ):
271+ tools = await gptscript .parse_tool ("" )
272+ assert len (tools ) == 0 , "Unexpected number of tools for parsing empty string"
273+
274+
262275@pytest .mark .asyncio
263276async def test_parse_tool_with_metadata (gptscript ):
264277 wd = os .getcwd ()
You can’t perform that action at this time.
0 commit comments