diff --git a/tests/utils/pubsub/test_item.py b/tests/utils/pubsub/test_item.py index f058f611..3bb8aa8c 100644 --- a/tests/utils/pubsub/test_item.py +++ b/tests/utils/pubsub/test_item.py @@ -8,19 +8,19 @@ from nextline.utils import PubSubItem, aiterable -async def test_close(): +async def test_close() -> None: async with PubSubItem[str]() as obj: assert obj -async def test_close_multiple_times(): +async def test_close_multiple_times() -> None: async with PubSubItem[str]() as obj: await obj.close() await obj.close() -@given(items=st.lists(st.text())) -async def test_get(items: Sequence[str]): +@given(...) +async def test_get(items: list[str]) -> None: async with PubSubItem[str]() as obj: with pytest.raises(LookupError): obj.latest() @@ -30,16 +30,16 @@ async def test_get(items: Sequence[str]): @given(items=st.lists(st.text()), n_subscriptions=st.integers(0, 5)) -async def test_subscribe(items: Sequence[str], n_subscriptions: int): +async def test_subscribe(items: Sequence[str], n_subscriptions: int) -> None: items = tuple(items) expected = [items] * n_subscriptions async with PubSubItem[str]() as obj: - async def receive(): + async def receive() -> tuple[str, ...]: return tuple([i async for i in obj.subscribe()]) - async def send(): + async def send() -> None: async for i in aiterable(items): await obj.publish(i) await obj.close() @@ -53,10 +53,10 @@ async def send(): @given(n_subscriptions=st.integers(0, 100)) -async def test_n_subscriptions(n_subscriptions: int): +async def test_n_subscriptions(n_subscriptions: int) -> None: async with PubSubItem[str]() as obj: - async def receive(): + async def receive() -> tuple[str, ...]: return tuple([i async for i in obj.subscribe()]) task = asyncio.gather(*(receive() for _ in range(n_subscriptions))) @@ -77,17 +77,17 @@ async def test_last( items: Sequence[int], last: bool, n_subscriptions: int, -): +) -> None: pre_items = tuple(pre_items) items = tuple(items) expected = [pre_items[-1:] + items if last else items] * n_subscriptions async with PubSubItem[int | str]() as obj: - async def receive(): + async def receive() -> tuple[int | str, ...]: return tuple([i async for i in obj.subscribe(last=last)]) - async def send(): + async def send() -> None: async for i in aiterable(items): await obj.publish(i) await obj.close() @@ -104,8 +104,8 @@ async def send(): assert results == expected -@given(items=st.lists(st.text()), last_item=st.text()) -async def test_put_after_close(items: Sequence[str], last_item: str): +@given(...) +async def test_put_after_close(items: list[str], last_item: str) -> None: async with PubSubItem[str]() as obj: for i in items: await obj.publish(i) @@ -118,15 +118,15 @@ async def test_put_after_close(items: Sequence[str], last_item: str): obj.latest() -@given(items=st.lists(st.text())) -async def test_subscribe_after_close(items: Sequence[str]): +@given(...) +async def test_subscribe_after_close(items: list[str]) -> None: async with PubSubItem[str]() as obj: for i in items: await obj.publish(i) await asyncio.sleep(0.001) - async def receive(): + async def receive() -> tuple[str, ...]: return tuple([i async for i in obj.subscribe()]) results = await receive() @@ -135,7 +135,7 @@ async def receive(): @given(st.data()) -async def test_break(data: st.DataObject): +async def test_break(data: st.DataObject) -> None: items = tuple(data.draw(st.lists(st.text(), min_size=1, unique=True))) idx = data.draw(st.integers(0, len(items) - 1)) at = items[idx] @@ -144,7 +144,7 @@ async def test_break(data: st.DataObject): async with PubSubItem[str]() as obj: - async def receive(): + async def receive() -> tuple[str, ...]: ret = [] assert obj.n_subscriptions == 0 async for i in obj.subscribe(): @@ -156,7 +156,7 @@ async def receive(): assert obj.n_subscriptions == 0 # the queue is closed return tuple(ret) - async def send(): + async def send() -> None: async for i in aiterable(items): await obj.publish(i) await obj.close() @@ -166,7 +166,7 @@ async def send(): @given(st.data()) -async def test_no_missing_or_duplicate(data: st.DataObject): +async def test_no_missing_or_duplicate(data: st.DataObject) -> None: '''Assert that the issue is resolved https://github.com/simonsobs/nextline/issues/2 @@ -184,11 +184,11 @@ async def test_no_missing_or_duplicate(data: st.DataObject): async with PubSubItem[str]() as obj: - async def receive(): + async def receive() -> tuple[str, ...]: await event.wait() return tuple([i async for i in obj.subscribe()]) - async def send(): + async def send() -> None: async for i in aiterable(pre_items): await obj.publish(i) event.set()