From 1745749cd2745c94c3f852e9c02dfde19d8d9c20 Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Fri, 28 Mar 2025 20:53:41 +0100 Subject: Fix ruff errors and warnings in hello_world service --- servers/hello_world/tests/test_remote.py | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 servers/hello_world/tests/test_remote.py (limited to 'servers/hello_world/tests/test_remote.py') diff --git a/servers/hello_world/tests/test_remote.py b/servers/hello_world/tests/test_remote.py new file mode 100644 index 0000000..c98d129 --- /dev/null +++ b/servers/hello_world/tests/test_remote.py @@ -0,0 +1,63 @@ +import pytest +import asyncio +from unittest.mock import AsyncMock, MagicMock, patch +import sys + +class TestTransport: + """Test the transport functionality.""" + + @pytest.mark.asyncio + async def test_transport_selection(self): + """Test that the server selects the correct transport based on the argument.""" + # Import the main function here to avoid issues with the mocking + from mcp_server_hello_world.server import main + + # Mock the run_stdio_async method + with patch('mcp.server.fastmcp.FastMCP.run_stdio_async') as mock_run_stdio: + + # Set up the mocks + mock_run_stdio.return_value = AsyncMock() + + # Start the server with stdio transport + task = asyncio.create_task(main("stdio", "0.0.0.0", 8080)) + + # Wait for the server to start + await asyncio.sleep(0.1) + + # Check that run_stdio_async was called + mock_run_stdio.assert_called_once() + + # Cancel the task + task.cancel() + try: + await task + except asyncio.CancelledError: + pass + + @pytest.mark.asyncio + async def test_remote_transport(self): + """Test that the server can be started with remote transport.""" + # Import the main function here to avoid issues with the mocking + from mcp_server_hello_world.server import main + + # Mock the run_sse_async method + with patch('mcp.server.fastmcp.FastMCP.run_sse_async') as mock_run_sse: + + # Set up the mocks + mock_run_sse.return_value = AsyncMock() + + # Start the server with remote transport + task = asyncio.create_task(main("remote", "0.0.0.0", 8080)) + + # Wait for the server to start + await asyncio.sleep(0.1) + + # Check that run_sse_async was called without parameters + mock_run_sse.assert_called_once_with() + + # Cancel the task + task.cancel() + try: + await task + except asyncio.CancelledError: + pass -- cgit v1.2.3