Skip to content

Commit

Permalink
Merge branch 'master' into blacken
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCat467 authored Jun 13, 2024
2 parents ae69a91 + 6a004bb commit e18e907
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ async def test_serve(nursery):
# The server nursery begins with one task (server.listen).
assert len(nursery.child_tasks) == 1
no_clients_nursery_count = len(task.child_nurseries)
async with open_websocket(HOST, port, RESOURCE, use_ssl=False) as conn:
async with open_websocket(HOST, port, RESOURCE, use_ssl=False):
# The server nursery has the same number of tasks, but there is now
# one additional nested nursery.
assert len(nursery.child_tasks) == 1
Expand All @@ -222,7 +222,6 @@ async def test_serve_ssl(nursery):


async def test_serve_handler_nursery(nursery):
task = current_task()
async with trio.open_nursery() as handler_nursery:
serve_with_nursery = partial(
serve_websocket,
Expand All @@ -236,17 +235,15 @@ async def test_serve_handler_nursery(nursery):
port = server.port
# The server nursery begins with one task (server.listen).
assert len(nursery.child_tasks) == 1
no_clients_nursery_count = len(task.child_nurseries)
async with open_websocket(HOST, port, RESOURCE, use_ssl=False) as conn:
async with open_websocket(HOST, port, RESOURCE, use_ssl=False):
# The handler nursery should have one task in it
# (conn._reader_task).
assert len(handler_nursery.child_tasks) == 1


async def test_serve_with_zero_listeners(nursery):
task = current_task()
async def test_serve_with_zero_listeners():
with pytest.raises(ValueError):
server = WebSocketServer(echo_request_handler, [])
WebSocketServer(echo_request_handler, [])


async def test_serve_non_tcp_listener(nursery):
Expand Down Expand Up @@ -369,7 +366,7 @@ async def handler(request):
assert not request.local.is_ssl
assert str(request.remote.address) == HOST
assert not request.remote.is_ssl
conn = await request.accept()
await request.accept()

server = await nursery.start(serve_websocket, handler, HOST, 0, None)
async with open_websocket(HOST, server.port, RESOURCE, use_ssl=False) as client_ws:
Expand Down Expand Up @@ -425,7 +422,7 @@ async def handler(request):
@fail_after(1)
async def test_handshake_server_headers(nursery):
async def handler(request):
headers = [("X-Test-Header", "My test header")]
headers = [('X-Test-Header', 'My test header')]
server_ws = await request.accept(extra_headers=headers)

server = await nursery.start(serve_websocket, handler, HOST, 0, None)
Expand Down Expand Up @@ -502,7 +499,7 @@ async def handler(stream):
assert exc.body is None


async def test_handshake_protocol_error(nursery, echo_server):
async def test_handshake_protocol_error(echo_server):
"""
If a client connects to a trio-websocket server and tries to speak HTTP
instead of WebSocket, the server should reject the connection. (If the
Expand Down Expand Up @@ -721,7 +718,7 @@ async def handler(request):

old_task_count = len(nursery.child_tasks)
# This stream is not a WebSocket, so it won't send a handshake:
stream = await trio.open_tcp_stream(HOST, server.port)
await trio.open_tcp_stream(HOST, server.port)
# Checkpoint so the server's handler task can spawn:
await trio.sleep(0)
assert (
Expand Down Expand Up @@ -850,7 +847,7 @@ async def handler(stream):

async def test_server_handler_exit(nursery, autojump_clock):
async def handler(request):
server_ws = await request.accept()
await request.accept()
await trio.sleep(1)

server = await nursery.start(
Expand Down

0 comments on commit e18e907

Please sign in to comment.