MCPcopy Index your code
hub / github.com/python-websockets/websockets / test_select_subprotocol

Method test_select_subprotocol

tests/sync/test_server.py:72–86  ·  view source on GitHub ↗

Server selects a subprotocol with the select_subprotocol callable.

(self)

Source from the content-addressed store, hash-verified

70 self.assertEval(client, "ws.protocol.state.name", "OPEN")
71
72 def test_select_subprotocol(self):
73 """Server selects a subprotocol with the select_subprotocol callable."""
74
75 def select_subprotocol(ws, subprotocols):
76 ws.select_subprotocol_ran = True
77 assert "chat" in subprotocols
78 return "chat"
79
80 with run_server(
81 subprotocols=["chat"],
82 select_subprotocol=select_subprotocol,
83 ) as server:
84 with connect(get_uri(server), subprotocols=["chat"]) as client:
85 self.assertEval(client, "ws.select_subprotocol_ran", "True")
86 self.assertEval(client, "ws.subprotocol", "chat")
87
88 def test_select_subprotocol_rejects_handshake(self):
89 """Server rejects handshake if select_subprotocol raises NegotiationError."""

Callers

nothing calls this directly

Calls 4

connectFunction · 0.90
run_serverFunction · 0.85
get_uriFunction · 0.70
assertEvalMethod · 0.45

Tested by

no test coverage detected