Jeremiah Lowin commited on
Commit
4a050cf
·
1 Parent(s): 0bf61b1

Ensure tests use stateless mode

Browse files
tests/client/test_streamable_http.py CHANGED
@@ -2,7 +2,7 @@ import asyncio
2
  import json
3
  import sys
4
  from collections.abc import AsyncGenerator
5
- from unittest.mock import AsyncMock
6
 
7
  import pytest
8
  import uvicorn
@@ -53,6 +53,7 @@ def fastmcp_server():
53
  async def greet_with_progress(name: str, ctx: Context) -> str:
54
  """Report progress for a greeting."""
55
  await ctx.report_progress(0.5, 1.0, "Greeting in progress")
 
56
  return f"Hello, {name}!"
57
 
58
  # Add a resource
@@ -108,8 +109,9 @@ def run_nested_server(host: str, port: int) -> None:
108
 
109
  @pytest.fixture()
110
  async def streamable_http_server(
111
- stateless_http: bool = False,
112
  ) -> AsyncGenerator[str, None]:
 
113
  with run_server_in_process(
114
  run_server, stateless_http=stateless_http, transport="http"
115
  ) as url:
@@ -176,16 +178,25 @@ async def test_greet_with_progress_tool(streamable_http_server: str):
176
  result = await client.call_tool("greet_with_progress", {"name": "Alice"})
177
  assert result.data == "Hello, Alice!"
178
 
179
- progress_handler.assert_called_once_with(0.5, 1.0, "Greeting in progress")
 
 
 
 
 
180
 
181
 
182
  @pytest.mark.parametrize("streamable_http_server", [True, False], indirect=True)
183
- async def test_elicitation_tool(streamable_http_server: str):
184
  """Test calling the elicitation tool in both stateless and stateful modes."""
185
 
186
  async def elicitation_handler(message, response_type, params, ctx):
187
  return {"value": "Alice"}
188
 
 
 
 
 
189
  async with Client(
190
  transport=StreamableHttpTransport(streamable_http_server),
191
  elicitation_handler=elicitation_handler,
 
2
  import json
3
  import sys
4
  from collections.abc import AsyncGenerator
5
+ from unittest.mock import AsyncMock, call
6
 
7
  import pytest
8
  import uvicorn
 
53
  async def greet_with_progress(name: str, ctx: Context) -> str:
54
  """Report progress for a greeting."""
55
  await ctx.report_progress(0.5, 1.0, "Greeting in progress")
56
+ await ctx.report_progress(0.75, 1.0, "Almost there!")
57
  return f"Hello, {name}!"
58
 
59
  # Add a resource
 
109
 
110
  @pytest.fixture()
111
  async def streamable_http_server(
112
+ request,
113
  ) -> AsyncGenerator[str, None]:
114
+ stateless_http = getattr(request, "param", False)
115
  with run_server_in_process(
116
  run_server, stateless_http=stateless_http, transport="http"
117
  ) as url:
 
178
  result = await client.call_tool("greet_with_progress", {"name": "Alice"})
179
  assert result.data == "Hello, Alice!"
180
 
181
+ progress_handler.assert_has_calls(
182
+ [
183
+ call(0.5, 1.0, "Greeting in progress"),
184
+ call(0.75, 1.0, "Almost there!"),
185
+ ]
186
+ )
187
 
188
 
189
  @pytest.mark.parametrize("streamable_http_server", [True, False], indirect=True)
190
+ async def test_elicitation_tool(streamable_http_server: str, request):
191
  """Test calling the elicitation tool in both stateless and stateful modes."""
192
 
193
  async def elicitation_handler(message, response_type, params, ctx):
194
  return {"value": "Alice"}
195
 
196
+ stateless_http = request.node.callspec.params.get("streamable_http_server", False)
197
+ if stateless_http:
198
+ pytest.xfail("Elicitation is not supported in stateless HTTP mode")
199
+
200
  async with Client(
201
  transport=StreamableHttpTransport(streamable_http_server),
202
  elicitation_handler=elicitation_handler,