1919from unittest .mock import AsyncMock , MagicMock , patch
2020
2121import grpc
22-
2322from dapr .ext .workflow ._durabletask import client
2423from dapr .ext .workflow .aio .mcp import DaprMCPClient as AioDaprMCPClient
2524from dapr .ext .workflow .mcp import MCP_WORKFLOW_PREFIX , DaprMCPClient , MCPToolDef
@@ -440,9 +439,7 @@ def test_retries_on_unavailable(self):
440439 def test_non_transient_propagates_immediately (self ):
441440 """A non-CANCELLED/UNAVAILABLE error must not be retried."""
442441 mock_wf = MagicMock ()
443- mock_wf .schedule_new_workflow .side_effect = _StubRpcError (
444- grpc .StatusCode .PERMISSION_DENIED
445- )
442+ mock_wf .schedule_new_workflow .side_effect = _StubRpcError (grpc .StatusCode .PERMISSION_DENIED )
446443
447444 mcp_client = DaprMCPClient (timeout_in_seconds = 30 , wf_client = mock_wf )
448445 with patch ('dapr.ext.workflow.mcp.time.sleep' ) as sleep_mock :
@@ -455,16 +452,17 @@ def test_non_transient_propagates_immediately(self):
455452 def test_deadline_exhausted_raises_last_error (self ):
456453 """When the timeout budget runs out mid-retry, propagate the last error."""
457454 mock_wf = MagicMock ()
458- mock_wf .schedule_new_workflow .side_effect = _StubRpcError (
459- grpc .StatusCode .CANCELLED
460- )
455+ mock_wf .schedule_new_workflow .side_effect = _StubRpcError (grpc .StatusCode .CANCELLED )
461456
462457 mcp_client = DaprMCPClient (timeout_in_seconds = 1 , wf_client = mock_wf )
463458 # Patch monotonic to advance past the deadline immediately so we don't
464459 # actually sleep for a second in tests.
465- with patch ('dapr.ext.workflow.mcp.time.sleep' ), patch (
466- 'dapr.ext.workflow.mcp.time.monotonic' ,
467- side_effect = [0.0 , 2.0 ],
460+ with (
461+ patch ('dapr.ext.workflow.mcp.time.sleep' ),
462+ patch (
463+ 'dapr.ext.workflow.mcp.time.monotonic' ,
464+ side_effect = [0.0 , 2.0 ],
465+ ),
468466 ):
469467 with self .assertRaises (grpc .RpcError ):
470468 mcp_client .connect ('weather' )
@@ -482,9 +480,12 @@ def test_budget_exhausted_after_schedule_succeeds(self):
482480 mcp_client = DaprMCPClient (timeout_in_seconds = 1 , wf_client = mock_wf )
483481 # monotonic: 0.0 → deadline = 1.0; 0.4 → sleep_for = 0.5 (still in budget);
484482 # 2.0 → post-loop remaining = -1.0 → raise.
485- with patch ('dapr.ext.workflow.mcp.time.sleep' ), patch (
486- 'dapr.ext.workflow.mcp.time.monotonic' ,
487- side_effect = [0.0 , 0.4 , 2.0 ],
483+ with (
484+ patch ('dapr.ext.workflow.mcp.time.sleep' ),
485+ patch (
486+ 'dapr.ext.workflow.mcp.time.monotonic' ,
487+ side_effect = [0.0 , 0.4 , 2.0 ],
488+ ),
488489 ):
489490 with self .assertRaises (RuntimeError ) as ctx :
490491 mcp_client .connect ('weather' )
@@ -514,14 +515,15 @@ async def test_retries_then_succeeds_on_cancelled(self):
514515
515516 async def test_deadline_exhausted_raises (self ):
516517 mock_wf = AsyncMock ()
517- mock_wf .schedule_new_workflow .side_effect = _StubRpcError (
518- grpc .StatusCode .CANCELLED
519- )
518+ mock_wf .schedule_new_workflow .side_effect = _StubRpcError (grpc .StatusCode .CANCELLED )
520519
521520 mcp_client = AioDaprMCPClient (timeout_in_seconds = 1 , wf_client = mock_wf )
522- with patch ('dapr.ext.workflow.aio.mcp.asyncio.sleep' , new = AsyncMock ()), patch (
523- 'dapr.ext.workflow.aio.mcp.time.monotonic' ,
524- side_effect = [0.0 , 2.0 ],
521+ with (
522+ patch ('dapr.ext.workflow.aio.mcp.asyncio.sleep' , new = AsyncMock ()),
523+ patch (
524+ 'dapr.ext.workflow.aio.mcp.time.monotonic' ,
525+ side_effect = [0.0 , 2.0 ],
526+ ),
525527 ):
526528 with self .assertRaises (grpc .RpcError ):
527529 await mcp_client .connect ('weather' )
@@ -535,9 +537,12 @@ async def test_budget_exhausted_after_schedule_succeeds(self):
535537 ]
536538
537539 mcp_client = AioDaprMCPClient (timeout_in_seconds = 1 , wf_client = mock_wf )
538- with patch ('dapr.ext.workflow.aio.mcp.asyncio.sleep' , new = AsyncMock ()), patch (
539- 'dapr.ext.workflow.aio.mcp.time.monotonic' ,
540- side_effect = [0.0 , 0.4 , 2.0 ],
540+ with (
541+ patch ('dapr.ext.workflow.aio.mcp.asyncio.sleep' , new = AsyncMock ()),
542+ patch (
543+ 'dapr.ext.workflow.aio.mcp.time.monotonic' ,
544+ side_effect = [0.0 , 0.4 , 2.0 ],
545+ ),
541546 ):
542547 with self .assertRaises (RuntimeError ) as ctx :
543548 await mcp_client .connect ('weather' )
0 commit comments