Skip to content

Commit

Permalink
tests: adding # pragma: no branch in middleware/test_base and `te…
Browse files Browse the repository at this point in the history
…st_routing` (#2807)

Co-authored-by: Marcelo Trylesinski <[email protected]>
  • Loading branch information
lealre and Kludex authored Dec 21, 2024
1 parent 827de43 commit f884b66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions tests/middleware/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ async def receive() -> Message:

async def send(message: Message) -> None:
if message["type"] == "http.response.body":
if not message.get("more_body", False):
if not message.get("more_body", False): # pragma: no branch
response_complete.set()

await app(scope, receive, send)
Expand Down Expand Up @@ -402,7 +402,7 @@ async def receive() -> Message:

async def send(message: Message) -> None:
if message["type"] == "http.response.body":
if not message.get("more_body", False):
if not message.get("more_body", False): # pragma: no branch
response_complete.set()

await app(scope, receive, send)
Expand Down Expand Up @@ -456,7 +456,7 @@ async def cancel_on_disconnect(
task_status.started()
while True:
message = await receive()
if message["type"] == "http.disconnect":
if message["type"] == "http.disconnect": # pragma: no branch
task_group.cancel_scope.cancel()
break

Expand Down Expand Up @@ -717,7 +717,7 @@ async def dispatch(
async def test_read_request_stream_in_dispatch_wrapping_app_calls_body() -> None:
async def endpoint(scope: Scope, receive: Receive, send: Send) -> None:
request = Request(scope, receive)
async for chunk in request.stream():
async for chunk in request.stream(): # pragma: no branch
assert chunk == b"2"
break
await Response()(scope, receive, send)
Expand All @@ -730,7 +730,7 @@ async def dispatch(
) -> Response:
expected = b"1"
response: Response | None = None
async for chunk in request.stream():
async for chunk in request.stream(): # pragma: no branch
assert chunk == expected
if expected == b"1":
response = await call_next(request)
Expand Down Expand Up @@ -943,7 +943,7 @@ def modifying_middleware(app: ASGIApp) -> ASGIApp:
async def wrapped_app(scope: Scope, receive: Receive, send: Send) -> None:
async def wrapped_receive() -> Message:
msg = await receive()
if msg["type"] == "http.request":
if msg["type"] == "http.request": # pragma: no branch
msg["body"] = msg["body"] * 2
return msg

Expand Down
2 changes: 1 addition & 1 deletion tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ def __call__(self, request: Request) -> None: ... # pragma: no cover
id="staticmethod",
),
pytest.param(Endpoint(), "Endpoint", id="object"),
pytest.param(lambda request: ..., "<lambda>", id="lambda"),
pytest.param(lambda request: ..., "<lambda>", id="lambda"), # pragma: no branch
],
)
def test_route_name(endpoint: typing.Callable[..., Response], expected_name: str) -> None:
Expand Down

0 comments on commit f884b66

Please sign in to comment.