@@ -401,112 +401,4 @@ def test_get_prompt_sync_session_not_active():
401401 client .get_prompt_sync ("test_prompt_id" , {})
402402
403403
404- # Prompt Tests - Async Methods
405404
406-
407- @pytest .mark .asyncio
408- async def test_list_prompts_async (mock_transport , mock_session ):
409- """Test that list_prompts_async correctly retrieves prompts."""
410- mock_prompt = Prompt (name = "test_prompt" , description = "A test prompt" , id = "prompt_1" )
411- mock_result = ListPromptsResult (prompts = [mock_prompt ])
412- mock_session .list_prompts .return_value = mock_result
413-
414- with MCPClient (mock_transport ["transport_callable" ]) as client :
415- with (
416- patch ("asyncio.run_coroutine_threadsafe" ) as mock_run_coroutine_threadsafe ,
417- patch ("asyncio.wrap_future" ) as mock_wrap_future ,
418- ):
419- mock_future = MagicMock ()
420- mock_run_coroutine_threadsafe .return_value = mock_future
421-
422- async def mock_awaitable ():
423- return mock_result
424-
425- mock_wrap_future .return_value = mock_awaitable ()
426-
427- result = await client .list_prompts_async ()
428-
429- mock_run_coroutine_threadsafe .assert_called_once ()
430- mock_wrap_future .assert_called_once_with (mock_future )
431-
432- assert len (result .prompts ) == 1
433- assert result .prompts [0 ].name == "test_prompt"
434- assert result .nextCursor is None
435-
436-
437- @pytest .mark .asyncio
438- async def test_list_prompts_async_with_pagination (mock_transport , mock_session ):
439- """Test that list_prompts_async correctly handles pagination."""
440- mock_prompt = Prompt (name = "test_prompt" , description = "A test prompt" , id = "prompt_1" )
441- mock_result = ListPromptsResult (prompts = [mock_prompt ], nextCursor = "next_token" )
442- mock_session .list_prompts .return_value = mock_result
443-
444- with MCPClient (mock_transport ["transport_callable" ]) as client :
445- with (
446- patch ("asyncio.run_coroutine_threadsafe" ) as mock_run_coroutine_threadsafe ,
447- patch ("asyncio.wrap_future" ) as mock_wrap_future ,
448- ):
449- mock_future = MagicMock ()
450- mock_run_coroutine_threadsafe .return_value = mock_future
451-
452- async def mock_awaitable ():
453- return mock_result
454-
455- mock_wrap_future .return_value = mock_awaitable ()
456-
457- result = await client .list_prompts_async (pagination_token = "current_token" )
458-
459- mock_run_coroutine_threadsafe .assert_called_once ()
460- mock_wrap_future .assert_called_once_with (mock_future )
461-
462- assert len (result .prompts ) == 1
463- assert result .prompts [0 ].name == "test_prompt"
464- assert result .nextCursor == "next_token"
465-
466-
467- @pytest .mark .asyncio
468- async def test_list_prompts_async_session_not_active ():
469- """Test that list_prompts_async raises an error when session is not active."""
470- client = MCPClient (MagicMock ())
471-
472- with pytest .raises (MCPClientInitializationError , match = "client session is not running" ):
473- await client .list_prompts_async ()
474-
475-
476- @pytest .mark .asyncio
477- async def test_get_prompt_async (mock_transport , mock_session ):
478- """Test that get_prompt_async correctly retrieves a prompt."""
479- mock_message = PromptMessage (role = "assistant" , content = MCPTextContent (type = "text" , text = "This is a test prompt" ))
480- mock_result = GetPromptResult (messages = [mock_message ])
481- mock_session .get_prompt .return_value = mock_result
482-
483- with MCPClient (mock_transport ["transport_callable" ]) as client :
484- with (
485- patch ("asyncio.run_coroutine_threadsafe" ) as mock_run_coroutine_threadsafe ,
486- patch ("asyncio.wrap_future" ) as mock_wrap_future ,
487- ):
488- mock_future = MagicMock ()
489- mock_run_coroutine_threadsafe .return_value = mock_future
490-
491- async def mock_awaitable ():
492- return mock_result
493-
494- mock_wrap_future .return_value = mock_awaitable ()
495-
496- result = await client .get_prompt_async ("test_prompt_id" , {"key" : "value" })
497-
498- mock_run_coroutine_threadsafe .assert_called_once ()
499- mock_wrap_future .assert_called_once_with (mock_future )
500-
501- assert len (result .messages ) == 1
502- assert result .messages [0 ].role == "assistant"
503- assert result .messages [0 ].content .text == "This is a test prompt"
504-
505-
506- @pytest .mark .asyncio
507- async def test_get_prompt_async_session_not_active ():
508- """Test that get_prompt_async raises an error when session is not active."""
509- client = MCPClient (MagicMock ())
510-
511- with pytest .raises (MCPClientInitializationError , match = "client session is not running" ):
512- await client .get_prompt_async ("test_prompt_id" , {})
0 commit comments