diff --git a/docs/userguide/testing.rst b/docs/userguide/testing.rst index 05bb27c9f..ea0ed4baa 100644 --- a/docs/userguide/testing.rst +++ b/docs/userguide/testing.rst @@ -129,7 +129,7 @@ first test ``foo`` with ``bar`` mocked, then in a different test do ``bar``: @pytest.mark.asyncio() async def test_foo(test_app): with patch(__name__ + '.bar') as mocked_bar: - mocked_bar.send = mock_coro() + mocked_bar.send = mock_coro() async with foo.test_context() as agent: await agent.put('hey') mocked_bar.send.assert_called_with('hey') @@ -145,8 +145,8 @@ first test ``foo`` with ``bar`` mocked, then in a different test do ``bar``: async with bar.test_context() as agent: event = await agent.put('hey') assert agent.results[event.message.offset] == 'heyYOLO' - - + + You can put the `test_app` fixture into a [`conftest.py` file](https://docs.pytest.org/en/6.2.x/fixture.html#scope-sharing-fixtures-across-classes-modules-packages-or-session). If the fixture is not in the same file as the app's definition (which should be the case) you must import the app the fixture definition: .. sourcecode:: python @@ -155,9 +155,9 @@ You can put the `test_app` fixture into a [`conftest.py` file](https://docs.pyte @pytest.fixture(scope="function") def test_app(event_loop): """passing in event_loop helps avoid 'attached to a different loop' error""" - + from example import app - + app.loop = event_loop app.finalize() app.conf.store = 'memory://' diff --git a/faust/agents/manager.py b/faust/agents/manager.py index b1e164383..1336be522 100644 --- a/faust/agents/manager.py +++ b/faust/agents/manager.py @@ -1,13 +1,12 @@ """Agent manager.""" import asyncio -from collections import defaultdict +from collections import OrderedDict, defaultdict from typing import Any, Dict, List, Mapping, MutableMapping, MutableSet, Set from weakref import WeakSet from mode import Service from mode.utils.collections import ManagedUserDict -from mode.utils.compat import OrderedDict from mode.utils.locks import Event from faust.types import AgentManagerT, AgentT, AppT diff --git a/faust/app/base.py b/faust/app/base.py index 5205e3968..9bb15a18d 100644 --- a/faust/app/base.py +++ b/faust/app/base.py @@ -12,6 +12,7 @@ import sys import typing import warnings +from contextlib import nullcontext from datetime import tzinfo from functools import wraps from itertools import chain @@ -29,6 +30,7 @@ Mapping, MutableMapping, MutableSequence, + NoReturn, Optional, Pattern, Set, @@ -44,14 +46,12 @@ from mode import Seconds, Service, ServiceT, SupervisorStrategyT, want_seconds from mode.utils.aiter import aiter from mode.utils.collections import force_mapping -from mode.utils.contexts import nullcontext from mode.utils.futures import stampede from mode.utils.imports import import_from_cwd, smart_import from mode.utils.logging import flight_recorder, get_logger from mode.utils.objects import cached_property, qualname, shortlabel from mode.utils.queues import FlowControlEvent, ThrowableQueue from mode.utils.types.trees import NodeT -from mode.utils.typing import NoReturn from faust import transport from faust.agents import AgentFun, AgentManager, AgentT, ReplyConsumer, SinkT diff --git a/faust/assignor/copartitioned_assignor.py b/faust/assignor/copartitioned_assignor.py index 093781afd..ada471793 100644 --- a/faust/assignor/copartitioned_assignor.py +++ b/faust/assignor/copartitioned_assignor.py @@ -2,9 +2,7 @@ from itertools import cycle from math import ceil, floor -from typing import Iterable, Iterator, MutableMapping, Optional, Sequence, Set - -from mode.utils.typing import Counter +from typing import Counter, Iterable, Iterator, MutableMapping, Optional, Sequence, Set from .client_assignment import CopartitionedAssignment diff --git a/faust/cli/base.py b/faust/cli/base.py index 5715176e8..8e57b6485 100644 --- a/faust/cli/base.py +++ b/faust/cli/base.py @@ -21,6 +21,7 @@ List, Mapping, MutableSequence, + NoReturn, Optional, Sequence, Tuple, @@ -36,7 +37,6 @@ from mode.utils import text from mode.utils.compat import want_bytes from mode.utils.imports import import_from_cwd, symbol_by_name -from mode.utils.typing import NoReturn from mode.worker import exiting from faust.types import AppT, CodecArg, ModelT diff --git a/faust/livecheck/case.py b/faust/livecheck/case.py index 5c8cc4d68..771d89050 100644 --- a/faust/livecheck/case.py +++ b/faust/livecheck/case.py @@ -3,19 +3,29 @@ import traceback import typing from collections import deque -from contextlib import ExitStack +from contextlib import ExitStack, asynccontextmanager from datetime import datetime, timedelta, timezone from itertools import count from random import uniform from statistics import median from time import monotonic -from typing import Any, ClassVar, Dict, Iterable, Optional, Type, Union, cast +from typing import ( + Any, + AsyncGenerator, + ClassVar, + Counter, + Deque, + Dict, + Iterable, + Optional, + Type, + Union, + cast, +) from aiohttp import ClientError, ClientTimeout from mode import Seconds, Service, want_seconds -from mode.utils.contexts import asynccontextmanager from mode.utils.times import humanize_seconds -from mode.utils.typing import AsyncGenerator, Counter, Deque from yarl import URL from faust.utils import uuid diff --git a/faust/livecheck/runners.py b/faust/livecheck/runners.py index a1d26fb1d..2e6594e1a 100644 --- a/faust/livecheck/runners.py +++ b/faust/livecheck/runners.py @@ -5,11 +5,10 @@ import traceback import typing from time import monotonic -from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple +from typing import Any, Dict, Iterable, List, Mapping, NoReturn, Optional, Tuple from mode.utils.logging import CompositeLogger from mode.utils.times import humanize_seconds -from mode.utils.typing import NoReturn from faust.models import maybe_model diff --git a/faust/models/record.py b/faust/models/record.py index dbfd65a5e..032abd607 100644 --- a/faust/models/record.py +++ b/faust/models/record.py @@ -1,5 +1,6 @@ """Record - Dictionary Model.""" +from collections import OrderedDict from datetime import datetime from decimal import Decimal from itertools import chain @@ -18,7 +19,6 @@ cast, ) -from mode.utils.compat import OrderedDict from mode.utils.objects import annotations, is_optional, remove_optional from mode.utils.text import pluralize diff --git a/faust/models/typing.py b/faust/models/typing.py index dc9ff0d88..030d5ecb1 100644 --- a/faust/models/typing.py +++ b/faust/models/typing.py @@ -23,6 +23,7 @@ Any, Callable, ClassVar, + Counter, Dict, Iterator, List, @@ -45,7 +46,6 @@ is_union, qualname, ) -from mode.utils.typing import Counter from faust.types.models import CoercionHandler, CoercionMapping, IsInstanceArgT, ModelT from faust.utils import codegen diff --git a/faust/sensors/monitor.py b/faust/sensors/monitor.py index 44d7da1e1..b37a0f8a4 100644 --- a/faust/sensors/monitor.py +++ b/faust/sensors/monitor.py @@ -10,6 +10,8 @@ from typing import ( Any, Callable, + Counter, + Deque, Dict, Mapping, MutableMapping, @@ -21,7 +23,6 @@ from mode import Service, label from mode.utils.objects import KeywordReduce -from mode.utils.typing import Counter, Deque from faust import web from faust.types import AppT, CollectionT, EventT, StreamT diff --git a/faust/streams.py b/faust/streams.py index d2faf482a..9f4286a3f 100644 --- a/faust/streams.py +++ b/faust/streams.py @@ -12,6 +12,7 @@ AsyncIterable, AsyncIterator, Callable, + Deque, Dict, Iterable, Iterator, @@ -32,7 +33,6 @@ from mode.utils.futures import current_task, maybe_async, notify from mode.utils.queues import ThrowableQueue from mode.utils.types.trees import NodeT -from mode.utils.typing import Deque from . import joins from .exceptions import ImproperlyConfigured, Skip diff --git a/faust/tables/recovery.py b/faust/tables/recovery.py index 41bb20c18..11737aef0 100644 --- a/faust/tables/recovery.py +++ b/faust/tables/recovery.py @@ -8,6 +8,8 @@ from time import monotonic from typing import ( Any, + Counter, + Deque, Iterator, List, Mapping, @@ -23,7 +25,6 @@ from mode import Service, get_logger from mode.services import WaitArgT from mode.utils.times import humanize_seconds, humanize_seconds_ago -from mode.utils.typing import Counter, Deque from yarl import URL from faust.exceptions import ConsistencyError diff --git a/faust/tables/wrappers.py b/faust/tables/wrappers.py index 0650c59e6..bab3d72a0 100644 --- a/faust/tables/wrappers.py +++ b/faust/tables/wrappers.py @@ -10,6 +10,7 @@ ItemsView, Iterator, KeysView, + NoReturn, Optional, Tuple, Type, @@ -18,7 +19,6 @@ ) from mode import Seconds -from mode.utils.typing import NoReturn from faust.exceptions import ImproperlyConfigured from faust.streams import current_event diff --git a/faust/transport/drivers/aiokafka.py b/faust/transport/drivers/aiokafka.py index f69c532db..fe189d9d3 100644 --- a/faust/transport/drivers/aiokafka.py +++ b/faust/transport/drivers/aiokafka.py @@ -11,6 +11,7 @@ Awaitable, Callable, ClassVar, + Deque, Iterable, List, Mapping, @@ -49,7 +50,6 @@ from mode.utils.futures import StampedeWrapper from mode.utils.objects import cached_property from mode.utils.times import Seconds, humanize_seconds_ago, want_seconds -from mode.utils.typing import Deque from opentracing.ext import tags from yarl import URL diff --git a/faust/transport/utils.py b/faust/transport/utils.py index 0b0c7b213..dc0b8d7d0 100644 --- a/faust/transport/utils.py +++ b/faust/transport/utils.py @@ -1,5 +1,6 @@ """Transport utils - scheduling.""" +from collections import OrderedDict from typing import ( Any, Dict, @@ -12,8 +13,6 @@ Tuple, ) -from mode.utils.compat import OrderedDict - from faust.types import TP from faust.types.transports import SchedulingStrategyT diff --git a/faust/types/app.py b/faust/types/app.py index c62858dcb..adb336035 100644 --- a/faust/types/app.py +++ b/faust/types/app.py @@ -12,6 +12,7 @@ Iterable, Mapping, MutableSequence, + NoReturn, Optional, Pattern, Set, @@ -28,7 +29,6 @@ from mode.utils.objects import cached_property from mode.utils.queues import FlowControlEvent, ThrowableQueue from mode.utils.types.trees import NodeT -from mode.utils.typing import NoReturn from .agents import AgentFun, AgentManagerT, AgentT, SinkT from .assignor import PartitionAssignorT diff --git a/faust/types/events.py b/faust/types/events.py index 11061e07b..9b1498609 100644 --- a/faust/types/events.py +++ b/faust/types/events.py @@ -1,8 +1,15 @@ import abc import typing -from typing import Any, Awaitable, Generic, Mapping, Optional, TypeVar, Union - -from mode.utils.typing import AsyncContextManager +from typing import ( + Any, + AsyncContextManager, + Awaitable, + Generic, + Mapping, + Optional, + TypeVar, + Union, +) from .codecs import CodecArg from .core import HeadersArg, K, V diff --git a/faust/web/cache/backends/base.py b/faust/web/cache/backends/base.py index 06b87ec8e..a0cbf2ddf 100644 --- a/faust/web/cache/backends/base.py +++ b/faust/web/cache/backends/base.py @@ -1,12 +1,11 @@ """Cache backend - base implementation.""" import abc -from typing import Any, ClassVar, Optional, Tuple, Type, Union +from contextlib import asynccontextmanager +from typing import Any, AsyncGenerator, ClassVar, Optional, Tuple, Type, Union from mode import Service -from mode.utils.contexts import asynccontextmanager from mode.utils.logging import get_logger -from mode.utils.typing import AsyncGenerator from yarl import URL from faust.types import AppT diff --git a/requirements/requirements.txt b/requirements/requirements.txt index cdd50fedd..5b7f71c9b 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -2,7 +2,7 @@ aiohttp>=3.8.0,<4.0 aiohttp_cors>=0.7,<2.0 aiokafka>=0.9.0 click>=6.7,<8.2 -mode-streaming>=0.3.0 +mode-streaming>=0.4.0 opentracing>=1.3.0,<=2.4.0 terminaltables>=3.1,<4.0 yarl>=1.0,<2.0 diff --git a/tests/unit/test_streams.py b/tests/unit/test_streams.py index 1a9c03035..4b7af428d 100644 --- a/tests/unit/test_streams.py +++ b/tests/unit/test_streams.py @@ -1,9 +1,9 @@ import asyncio from collections import defaultdict +from contextlib import ExitStack from unittest.mock import Mock, patch import pytest -from mode.utils.contexts import ExitStack import faust from faust import joins