Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new black #38

Merged
merged 3 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions asgineer/_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ async def iter_body(self):
if self._client_state != CONNECTED: # i.e. DONE or DISCONNECTED
break

async def get_body(self, limit=10 * 2 ** 20):
async def get_body(self, limit=10 * 2**20):
"""Async function to get the bytes of the body.
If the end of the stream is not reached before the byte limit
is reached (default 10MiB), raises an ``IOError``.
Expand All @@ -284,7 +284,7 @@ async def get_body(self, limit=10 * 2 ** 20):
self._body = b"".join(chunks)
return self._body

async def get_json(self, limit=10 * 2 ** 20):
async def get_json(self, limit=10 * 2**20):
"""Async function to get the body as a dict.
If the end of the stream is not reached before the byte limit
is reached (default 10MiB), raises an ``IOError``.
Expand Down
16 changes: 12 additions & 4 deletions tests/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import sys

import asgineer
from common import make_server
from common import make_server, get_backend
from pytest import skip


def test_websocket1():
Expand Down Expand Up @@ -231,6 +232,9 @@ async def client(ws):


def test_websocket_receive_after_close():
if get_backend() == "daphne":
skip("This test outcome is ill defined, skipping for daphne")

async def handle_ws1(request):
await request.accept()
await request.close()
Expand All @@ -242,11 +246,12 @@ async def client(ws):

with make_server(handle_ws1) as p:
p.ws_communicate("/", client)
out = p.out.strip()

# Acually, uvicorn gives empty string, daphne gives hello, not sure
# Acually, uvicorn gives empty string, daphne gives error, not sure
# what the official behavior is, I guess we'll allow both.
print("receive_after_close:", p.out.strip())
assert p.out.strip() in ("", "hellow")
print("receive_after_close:", out)
assert out in ("", "hellow")


def test_websocket_receive_after_disconnect1():
Expand Down Expand Up @@ -291,6 +296,9 @@ async def client(ws):


def test_websocket_send_invalid_data():
if get_backend() == "daphne":
skip("Skipping on daphne because it errors on the close mechanic")

async def handle_ws(request):
await request.accept()
await request.send(4)
Expand Down