Skip to content

Commit

Permalink
Add type hints to test_concurency.py (encode#2474)
Browse files Browse the repository at this point in the history
Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
  • Loading branch information
2 people authored and Rocky Allen committed Mar 18, 2024
1 parent a429b4d commit 29a6af0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions tests/test_concurrency.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from contextvars import ContextVar
from typing import Callable, Iterator

import anyio
import pytest
Expand All @@ -8,17 +9,20 @@
from starlette.requests import Request
from starlette.responses import Response
from starlette.routing import Route
from starlette.testclient import TestClient

TestClientFactory = Callable[..., TestClient]


@pytest.mark.anyio
async def test_run_until_first_complete():
async def test_run_until_first_complete() -> None:
task1_finished = anyio.Event()
task2_finished = anyio.Event()

async def task1():
async def task1() -> None:
task1_finished.set()

async def task2():
async def task2() -> None:
await task1_finished.wait()
await anyio.sleep(0) # pragma: nocover
task2_finished.set() # pragma: nocover
Expand All @@ -28,7 +32,9 @@ async def task2():
assert not task2_finished.is_set()


def test_accessing_context_from_threaded_sync_endpoint(test_client_factory) -> None:
def test_accessing_context_from_threaded_sync_endpoint(
test_client_factory: TestClientFactory,
) -> None:
ctxvar: ContextVar[bytes] = ContextVar("ctxvar")
ctxvar.set(b"data")

Expand All @@ -45,7 +51,7 @@ def endpoint(request: Request) -> Response:
@pytest.mark.anyio
async def test_iterate_in_threadpool() -> None:
class CustomIterable:
def __iter__(self):
def __iter__(self) -> Iterator[int]:
yield from range(3)

assert [v async for v in iterate_in_threadpool(CustomIterable())] == [0, 1, 2]

0 comments on commit 29a6af0

Please sign in to comment.