Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ test = [
"moto[server]>=5.0,<6",
"openai-responses>=0.11.4,<1",
"optuna>=3.0,<5",
"pytest>=8.3,<9.1.0",
"pytest-asyncio>=1.0,<1.4.0",
"pytest>=8.3,<10",
"pytest-asyncio>=1.0,<2",
"pytest-benchmark>=5.1.0",
"pytest-cases>=3.8,<4",
"pytest-env>=1.1,<2",
"pytest-lazy-fixtures>=1.4,<2",
"pytest-rerunfailures>=15.0,<17",
"ray[default,tune]>=2.40.0,<3",
"redis>=7.1,<9",
Expand Down
8 changes: 3 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import pytest
import pytest_asyncio
import pytest_cases
from that_depends import ContextScopes, container_context
import uvloop

Expand Down Expand Up @@ -67,16 +66,15 @@ async def DI_teardown() -> _t.AsyncGenerator[None, None]:
await DI.tear_down()


@pytest_cases.fixture
@pytest_cases.parametrize(zmq_pubsub_proxy=[False, True])
def zmq_connector_cls(zmq_pubsub_proxy: bool) -> _t.Iterator[_t.Type[ZMQConnector]]:
@pytest.fixture(params=[False, True], ids=["zmq_pubsub_proxy=False", "zmq_pubsub_proxy=True"])
def zmq_connector_cls(request: pytest.FixtureRequest) -> _t.Iterator[_t.Type[ZMQConnector]]:
"""Returns the ZMQConnector class with the specified proxy setting.

Patches the env var `PLUGBOARD_FLAGS_ZMQ_PUBSUB_PROXY` to control the proxy setting.
"""
with patch.dict(
os.environ,
{"PLUGBOARD_FLAGS_ZMQ_PUBSUB_PROXY": str(zmq_pubsub_proxy)},
{"PLUGBOARD_FLAGS_ZMQ_PUBSUB_PROXY": str(request.param)},
):
testing_settings = Settings()
DI.settings.override_sync(testing_settings)
Expand Down
27 changes: 11 additions & 16 deletions tests/integration/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from plugboard_schemas.connector import ConnectorMode, ConnectorSpec
import pytest
import pytest_cases
from pytest_lazy_fixtures import lf

from plugboard.connector import (
Connector,
Expand All @@ -23,40 +23,35 @@
)


@pytest_cases.fixture
@pytest_cases.parametrize(zmq_pubsub_proxy=[True])
def zmq_connector_cls(zmq_pubsub_proxy: bool) -> _t.Iterator[_t.Type[ZMQConnector]]:
@pytest.fixture(params=[True], ids=["zmq_pubsub_proxy=True"])
def zmq_connector_cls(request: pytest.FixtureRequest) -> _t.Iterator[_t.Type[ZMQConnector]]:
"""Returns the ZMQConnector class with the specified proxy setting.

Patches the env var `PLUGBOARD_FLAGS_ZMQ_PUBSUB_PROXY` to control the proxy setting.
"""
with patch.dict(
os.environ,
{"PLUGBOARD_FLAGS_ZMQ_PUBSUB_PROXY": str(zmq_pubsub_proxy)},
{"PLUGBOARD_FLAGS_ZMQ_PUBSUB_PROXY": str(request.param)},
):
testing_settings = Settings()
DI.settings.override_sync(testing_settings)
yield ZMQConnector
DI.settings.reset_override_sync()


@pytest_cases.fixture
@pytest_cases.parametrize("_connector_cls", [RabbitMQConnector, zmq_connector_cls, RedisConnector])
def connector_cls(_connector_cls: type[Connector]) -> type[Connector]:
@pytest.fixture(params=[RabbitMQConnector, lf("zmq_connector_cls"), RedisConnector])
def connector_cls(request: pytest.FixtureRequest) -> type[Connector]:
"""Fixture for `Connector` of various types."""
return _connector_cls
return request.param


@pytest_cases.fixture
@pytest_cases.parametrize(
"_connector_cls_mp", [RabbitMQConnector, zmq_connector_cls, RedisConnector]
)
def connector_cls_mp(_connector_cls_mp: type[Connector]) -> type[Connector]:
@pytest.fixture(params=[RabbitMQConnector, lf("zmq_connector_cls"), RedisConnector])
def connector_cls_mp(request: pytest.FixtureRequest) -> type[Connector]:
"""Fixture for `Connector` of various types for use in multiprocess context."""
return _connector_cls_mp
return request.param


@pytest_cases.parametrize("connector_cls", [RabbitMQConnector, RedisConnector])
@pytest.mark.parametrize("connector_cls", [RabbitMQConnector, RedisConnector])
async def test_channel_broker_url_unset(connector_cls: type[Connector], job_id_ctx: str) -> None:
"""Test that attempting to connect a channel without the broker URL set raises an error."""
spec = ConnectorSpec(mode=ConnectorMode.PIPELINE, source="test.send", target="test.recv")
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/test_component_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import typing as _t

import pytest
import pytest_cases

from plugboard.component import IOController as IO
from plugboard.component.utils import component
Expand Down Expand Up @@ -83,7 +82,7 @@ async def step(self) -> None:


@pytest.mark.asyncio
@pytest_cases.parametrize(
@pytest.mark.parametrize(
"process_cls, connector_cls",
[
(LocalProcess, AsyncioConnector),
Expand Down Expand Up @@ -127,7 +126,7 @@ async def test_process_with_decorated_components(


@pytest.mark.asyncio
@pytest_cases.parametrize(
@pytest.mark.parametrize(
"process_cls, connector_cls",
[
(LocalProcess, AsyncioConnector),
Expand Down
10 changes: 4 additions & 6 deletions tests/integration/test_component_event_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
from pydantic import BaseModel
import pytest
import pytest_asyncio
import pytest_cases
from pytest_lazy_fixtures import lf

from plugboard.component import Component, IOController
from plugboard.connector import AsyncioConnector, Connector, ConnectorBuilder
from plugboard.events import Event
from plugboard.events.event import StopEvent
from plugboard.schemas import ConnectorSpec
from tests.conftest import zmq_connector_cls


class EventTypeAData(BaseModel):
Expand Down Expand Up @@ -77,11 +76,10 @@ async def event_B_handler(self, evt: EventTypeB) -> None:
self._event_B_count += evt.data.y


@pytest_cases.fixture(scope="function")
@pytest_cases.parametrize("_connector_cls", [AsyncioConnector, zmq_connector_cls])
def connector_cls(_connector_cls: _t.Type[Connector]) -> _t.Type[Connector]:
@pytest.fixture(scope="function", params=[AsyncioConnector, lf("zmq_connector_cls")])
def connector_cls(request: pytest.FixtureRequest) -> _t.Type[Connector]:
"""Returns a `Connector` class."""
return _connector_cls
return request.param


@pytest.fixture
Expand Down
40 changes: 19 additions & 21 deletions tests/integration/test_connector_pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from unittest.mock import patch

import pytest
import pytest_cases
from pytest_lazy_fixtures import lf

from plugboard.connector import (
Connector,
Expand All @@ -24,36 +24,34 @@
)


@pytest_cases.fixture
@pytest_cases.parametrize(zmq_pubsub_proxy=[True])
def zmq_connector_cls(zmq_pubsub_proxy: bool) -> _t.Iterator[_t.Type[ZMQConnector]]:
@pytest.fixture(params=[True], ids=["zmq_pubsub_proxy=True"])
def zmq_connector_cls(request: pytest.FixtureRequest) -> _t.Iterator[_t.Type[ZMQConnector]]:
"""Returns the ZMQConnector class with the specified proxy setting.

Patches the env var `PLUGBOARD_FLAGS_ZMQ_PUBSUB_PROXY` to control the proxy setting.
"""
with patch.dict(
os.environ,
{"PLUGBOARD_FLAGS_ZMQ_PUBSUB_PROXY": str(zmq_pubsub_proxy)},
{"PLUGBOARD_FLAGS_ZMQ_PUBSUB_PROXY": str(request.param)},
):
testing_settings = Settings()
DI.settings.override_sync(testing_settings)
yield ZMQConnector
DI.settings.reset_override_sync()


@pytest_cases.fixture
@pytest_cases.parametrize(_connector_cls=[RabbitMQConnector, zmq_connector_cls, RedisConnector])
def connector_cls(_connector_cls: type[Connector]) -> type[Connector]:
@pytest.fixture(params=[RabbitMQConnector, lf("zmq_connector_cls"), RedisConnector])
def connector_cls(request: pytest.FixtureRequest) -> type[Connector]:
"""Fixture for `Connector` of various types."""
return _connector_cls
return request.param


@pytest.mark.asyncio
@pytest_cases.parametrize(
"connector_cls, num_subscribers, num_messages",
@pytest.mark.parametrize(
"num_subscribers, num_messages",
[
(connector_cls, 1, 100),
(connector_cls, 10, 100),
(1, 100),
(10, 100),
],
)
async def test_pubsub_channel_single_publisher(
Expand All @@ -68,11 +66,11 @@ async def test_pubsub_channel_single_publisher(


@pytest.mark.asyncio
@pytest_cases.parametrize(
"connector_cls, num_publishers, num_subscribers, num_messages",
@pytest.mark.parametrize(
"num_publishers, num_subscribers, num_messages",
[
(connector_cls, 10, 1, 100),
(connector_cls, 10, 10, 100),
(10, 1, 100),
(10, 10, 100),
],
)
async def test_pubsub_channel_multiple_publishers(
Expand All @@ -93,11 +91,11 @@ async def test_pubsub_channel_multiple_publishers(


@pytest.mark.asyncio
@pytest_cases.parametrize(
"connector_cls, num_topics, num_publishers, num_subscribers, num_messages",
@pytest.mark.parametrize(
"num_topics, num_publishers, num_subscribers, num_messages",
[
(connector_cls, 3, 10, 1, 100),
(connector_cls, 3, 10, 10, 100),
(3, 10, 1, 100),
(3, 10, 10, 100),
],
)
async def test_pubsub_channel_multiple_topics_and_publishers(
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_process_stop_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import typing as _t

import pytest
import pytest_cases
from pytest_lazy_fixtures import lf

from plugboard.component import Component, IOController as IO
from plugboard.connector import (
Expand All @@ -20,7 +20,7 @@
from plugboard.events import StopEvent
from plugboard.process import LocalProcess, Process, RayProcess
from plugboard.schemas import ConnectorSpec, Status
from tests.conftest import ComponentTestHelper, zmq_connector_cls
from tests.conftest import ComponentTestHelper


STOP_TOLERANCE = 3
Expand Down Expand Up @@ -57,14 +57,14 @@ async def step(self) -> None:


@pytest.mark.asyncio
@pytest_cases.parametrize(
@pytest.mark.parametrize(
"process_cls, connector_cls",
[
(LocalProcess, AsyncioConnector),
(LocalProcess, zmq_connector_cls),
(LocalProcess, lf("zmq_connector_cls")),
(LocalProcess, RabbitMQConnector),
# (RayProcess, RayConnector), # TODO : Pubsub/StopEvent unsupported. See https://github.com/plugboard-dev/plugboard/issues/101.
(RayProcess, zmq_connector_cls),
(RayProcess, lf("zmq_connector_cls")),
(RayProcess, RabbitMQConnector),
],
)
Expand Down Expand Up @@ -137,7 +137,7 @@ async def stop_after() -> None:


@pytest.mark.asyncio
@pytest_cases.parametrize(
@pytest.mark.parametrize(
"process_cls, connector_cls",
[
(LocalProcess, AsyncioConnector),
Expand Down
18 changes: 9 additions & 9 deletions tests/integration/test_process_with_components_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from aiofile import async_open
from pydantic import BaseModel
import pytest
import pytest_cases
from pytest_lazy_fixtures import lf

from plugboard.component import IOController as IO
from plugboard.component.component import IO_READ_TIMEOUT_SECONDS
Expand All @@ -26,7 +26,7 @@
from plugboard.library import FileWriter
from plugboard.process import LocalProcess, Process, RayProcess
from plugboard.schemas import ConnectorSpec, Status
from tests.conftest import ComponentTestHelper, zmq_connector_cls
from tests.conftest import ComponentTestHelper


class A(ComponentTestHelper):
Expand Down Expand Up @@ -84,14 +84,14 @@ def tempfile_path() -> _t.Generator[Path, None, None]:


@pytest.mark.asyncio
@pytest_cases.parametrize(
@pytest.mark.parametrize(
"process_cls, connector_cls",
[
(LocalProcess, AsyncioConnector),
(LocalProcess, zmq_connector_cls),
(LocalProcess, lf("zmq_connector_cls")),
(LocalProcess, RabbitMQConnector),
(RayProcess, RayConnector),
(RayProcess, zmq_connector_cls),
(RayProcess, lf("zmq_connector_cls")),
(RayProcess, RabbitMQConnector),
],
)
Expand Down Expand Up @@ -200,7 +200,7 @@ async def _status_check(self) -> None:


@pytest.mark.asyncio
@pytest_cases.parametrize(
@pytest.mark.parametrize(
"process_cls, connector_cls",
[
(LocalProcess, AsyncioConnector),
Expand Down Expand Up @@ -259,7 +259,7 @@ async def step(self) -> None:


@pytest.mark.asyncio
@pytest_cases.parametrize(
@pytest.mark.parametrize(
"process_cls, connector_cls",
[
(LocalProcess, AsyncioConnector),
Expand Down Expand Up @@ -420,7 +420,7 @@ async def handle_action(self, evt: ActionEvent) -> None:


@pytest.mark.asyncio
@pytest_cases.parametrize(
@pytest.mark.parametrize(
"process_cls, connector_cls",
[
(LocalProcess, AsyncioConnector),
Expand Down Expand Up @@ -659,7 +659,7 @@ async def handle_message(self, event: MessageEvent) -> None:


@pytest.mark.asyncio
@pytest_cases.parametrize(
@pytest.mark.parametrize(
"process_cls, connector_cls",
[
(LocalProcess, AsyncioConnector),
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_state_backend_multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest
import pytest_asyncio
import pytest_cases
from ray.util.multiprocessing import Pool
import uvloop

Expand Down Expand Up @@ -185,7 +184,7 @@ async def _inner() -> None:
assert state_data_conn["times_upserted"] == 2


@pytest_cases.parametrize("setup_backend", [setup_SqliteStateBackend, setup_PostgresStateBackend])
@pytest.mark.parametrize("setup_backend", [setup_SqliteStateBackend, setup_PostgresStateBackend])
@pytest.mark.asyncio
async def test_no_process_found_errors(
setup_backend: _t.Callable[[], _t.ContextManager[StateBackend]],
Expand Down
Loading
Loading