Skip to content

Commit

Permalink
Fix imports from updates in mode-streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
wbarnha committed Mar 29, 2024
1 parent 11505bc commit eb81248
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 36 deletions.
10 changes: 5 additions & 5 deletions docs/userguide/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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://'
Expand Down
3 changes: 1 addition & 2 deletions faust/agents/manager.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions faust/app/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,6 +30,7 @@
Mapping,
MutableMapping,
MutableSequence,
NoReturn,
Optional,
Pattern,
Set,
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions faust/assignor/copartitioned_assignor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion faust/cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
List,
Mapping,
MutableSequence,
NoReturn,
Optional,
Sequence,
Tuple,
Expand All @@ -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
Expand Down
18 changes: 14 additions & 4 deletions faust/livecheck/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions faust/livecheck/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion faust/models/record.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Record - Dictionary Model."""

from collections import OrderedDict
from datetime import datetime
from decimal import Decimal
from itertools import chain
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion faust/models/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Any,
Callable,
ClassVar,
Counter,
Dict,
Iterator,
List,
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion faust/sensors/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from typing import (
Any,
Callable,
Counter,
Deque,
Dict,
Mapping,
MutableMapping,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion faust/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
AsyncIterable,
AsyncIterator,
Callable,
Deque,
Dict,
Iterable,
Iterator,
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion faust/tables/recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from time import monotonic
from typing import (
Any,
Counter,
Deque,
Iterator,
List,
Mapping,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion faust/tables/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ItemsView,
Iterator,
KeysView,
NoReturn,
Optional,
Tuple,
Type,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion faust/transport/drivers/aiokafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Awaitable,
Callable,
ClassVar,
Deque,
Iterable,
List,
Mapping,
Expand Down Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions faust/transport/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Transport utils - scheduling."""

from collections import OrderedDict
from typing import (
Any,
Dict,
Expand All @@ -12,8 +13,6 @@
Tuple,
)

from mode.utils.compat import OrderedDict

from faust.types import TP
from faust.types.transports import SchedulingStrategyT

Expand Down
2 changes: 1 addition & 1 deletion faust/types/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Iterable,
Mapping,
MutableSequence,
NoReturn,
Optional,
Pattern,
Set,
Expand All @@ -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
Expand Down
13 changes: 10 additions & 3 deletions faust/types/events.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions faust/web/cache/backends/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_streams.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit eb81248

Please sign in to comment.