MCPcopy
hub / github.com/encode/starlette / test_websocket_close_reason

Function test_websocket_close_reason

tests/test_websockets.py:537–548  ·  view source on GitHub ↗
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

535
536
537def test_websocket_close_reason(test_client_factory: TestClientFactory) -> None:
538 async def app(scope: Scope, receive: Receive, send: Send) -> None:
539 websocket = WebSocket(scope, receive=receive, send=send)
540 await websocket.accept()
541 await websocket.close(code=status.WS_1001_GOING_AWAY, reason="Going Away")
542
543 client = test_client_factory(app)
544 with client.websocket_connect("/") as websocket:
545 with pytest.raises(WebSocketDisconnect) as exc:
546 websocket.receive_text()
547 assert exc.value.code == status.WS_1001_GOING_AWAY
548 assert exc.value.reason == "Going Away"
549
550
551def test_send_json_invalid_mode(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 3

receive_textMethod · 0.95
test_client_factoryFunction · 0.85
websocket_connectMethod · 0.80

Tested by

no test coverage detected