Skip to content

Commit 36ea19a

Browse files
committed
test: force asyncio.run fallback path in compute-bridge tests
1 parent 99d0bd9 commit 36ea19a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/praisonai-agents/tests/managed/test_managed_factory.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ def test_compute_bridge_tool_execute_command(self):
472472
original_func = lambda command: "original result"
473473
bridge_tool = agent._create_compute_bridge_tool("execute_command", original_func)
474474

475-
with patch.object(agent._compute, 'execute') as mock_execute, \
475+
with patch.object(agent._compute, 'execute'), \
476+
patch('asyncio.get_event_loop', side_effect=RuntimeError('no loop')), \
476477
patch('asyncio.run') as mock_asyncio_run:
477478

478479
mock_asyncio_run.return_value = {"exit_code": 0, "stdout": "compute result"}
@@ -527,7 +528,8 @@ def test_bridge_file_tool_read(self):
527528
agent = LocalManagedAgent(compute="local")
528529
agent._compute_instance_id = "test_instance"
529530

530-
with patch('asyncio.run') as mock_asyncio_run:
531+
with patch('asyncio.get_event_loop', side_effect=RuntimeError('no loop')), \
532+
patch('asyncio.run') as mock_asyncio_run:
531533
mock_asyncio_run.return_value = {"exit_code": 0, "stdout": "file contents"}
532534

533535
result = agent._bridge_file_tool("read_file", "/test/file")
@@ -541,7 +543,8 @@ def test_bridge_file_tool_write(self):
541543
agent = LocalManagedAgent(compute="local")
542544
agent._compute_instance_id = "test_instance"
543545

544-
with patch('asyncio.run') as mock_asyncio_run:
546+
with patch('asyncio.get_event_loop', side_effect=RuntimeError('no loop')), \
547+
patch('asyncio.run') as mock_asyncio_run:
545548
mock_asyncio_run.return_value = {"exit_code": 0, "stdout": ""}
546549

547550
result = agent._bridge_file_tool("write_file", "/test/file", "content")
@@ -555,7 +558,8 @@ def test_bridge_file_tool_list(self):
555558
agent = LocalManagedAgent(compute="local")
556559
agent._compute_instance_id = "test_instance"
557560

558-
with patch('asyncio.run') as mock_asyncio_run:
561+
with patch('asyncio.get_event_loop', side_effect=RuntimeError('no loop')), \
562+
patch('asyncio.run') as mock_asyncio_run:
559563
mock_asyncio_run.return_value = {"exit_code": 0, "stdout": "file1\nfile2\n"}
560564

561565
result = agent._bridge_file_tool("list_files", "/test/dir")

0 commit comments

Comments
 (0)