(test_client_factory: TestClientFactory)
| 239 | |
| 240 | |
| 241 | def test_client_close(test_client_factory: TestClientFactory) -> None: |
| 242 | close_code = None |
| 243 | close_reason = None |
| 244 | |
| 245 | async def app(scope: Scope, receive: Receive, send: Send) -> None: |
| 246 | nonlocal close_code, close_reason |
| 247 | websocket = WebSocket(scope, receive=receive, send=send) |
| 248 | await websocket.accept() |
| 249 | try: |
| 250 | await websocket.receive_text() |
| 251 | except WebSocketDisconnect as exc: |
| 252 | close_code = exc.code |
| 253 | close_reason = exc.reason |
| 254 | |
| 255 | client = test_client_factory(app) |
| 256 | with client.websocket_connect("/") as websocket: |
| 257 | websocket.close(code=status.WS_1001_GOING_AWAY, reason="Going Away") |
| 258 | assert close_code == status.WS_1001_GOING_AWAY |
| 259 | assert close_reason == "Going Away" |
| 260 | |
| 261 | |
| 262 | @pytest.mark.anyio |
nothing calls this directly
no test coverage detected