Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Nusnus committed Oct 9, 2023
1 parent b8586af commit 4526e45
Show file tree
Hide file tree
Showing 33 changed files with 122 additions and 159 deletions.
16 changes: 8 additions & 8 deletions src/pytest_celery/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# flake8: noqa

from pytest_celery.api.components import CeleryBackendCluster
from pytest_celery.api.components import CeleryBrokerCluster
from pytest_celery.api.components import CeleryTestBackend
from pytest_celery.api.components import CeleryTestBroker
from pytest_celery.api.components import CeleryTestCluster
from pytest_celery.api.components import CeleryTestNode
from pytest_celery.api.components import CeleryTestWorker
from pytest_celery.api.components import CeleryWorkerCluster
from pytest_celery.api.backend import CeleryBackendCluster
from pytest_celery.api.backend import CeleryTestBackend
from pytest_celery.api.base import CeleryTestCluster
from pytest_celery.api.base import CeleryTestNode
from pytest_celery.api.broker import CeleryBrokerCluster
from pytest_celery.api.broker import CeleryTestBroker

Check warning on line 8 in src/pytest_celery/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/__init__.py#L3-L8

Added lines #L3 - L8 were not covered by tests
from pytest_celery.api.container import CeleryTestContainer
from pytest_celery.api.setup import CeleryTestSetup
from pytest_celery.api.worker import CeleryTestWorker
from pytest_celery.api.worker import CeleryWorkerCluster

Check warning on line 12 in src/pytest_celery/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/__init__.py#L11-L12

Added lines #L11 - L12 were not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
from typing import Union

from pytest_celery import defaults
from pytest_celery.api.components.backend.node import CeleryTestBackend
from pytest_celery.api.components.cluster.base import CeleryTestCluster
from pytest_celery.api.components.cluster.node import CeleryTestNode
from pytest_celery.api.base import CeleryTestCluster
from pytest_celery.api.base import CeleryTestNode

Check warning on line 7 in src/pytest_celery/api/backend.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/backend.py#L6-L7

Added lines #L6 - L7 were not covered by tests
from pytest_celery.api.container import CeleryTestContainer


class CeleryTestBackend(CeleryTestNode):
@classmethod

Check warning on line 12 in src/pytest_celery/api/backend.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/backend.py#L11-L12

Added lines #L11 - L12 were not covered by tests
def default_config(cls) -> dict:
return {
"url": defaults.WORKER_ENV["CELERY_RESULT_BACKEND"],
"local_url": defaults.WORKER_ENV["CELERY_RESULT_BACKEND"],
}


class CeleryBackendCluster(CeleryTestCluster):
def __init__(self, *backends: Tuple[Union[CeleryTestBackend, CeleryTestContainer]]) -> None:
super().__init__(*backends)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,45 @@
from typing import Type
from typing import Union

from pytest_celery.api.components.cluster.node import CeleryTestNode
from pytest_celery.api.container import CeleryTestContainer


class CeleryTestNode:
def __init__(self, container: CeleryTestContainer):

Check warning on line 12 in src/pytest_celery/api/base.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/base.py#L11-L12

Added lines #L11 - L12 were not covered by tests
self._container = container

@property

Check warning on line 15 in src/pytest_celery/api/base.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/base.py#L15

Added line #L15 was not covered by tests
def container(self) -> CeleryTestContainer:
return self._container

def ready(self) -> bool:

Check warning on line 19 in src/pytest_celery/api/base.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/base.py#L19

Added line #L19 was not covered by tests
return self.container.ready()

def config(self, *args: tuple, **kwargs: dict) -> dict:
return self.container.celeryconfig

Check warning on line 23 in src/pytest_celery/api/base.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/base.py#L22-L23

Added lines #L22 - L23 were not covered by tests

@classmethod

Check warning on line 25 in src/pytest_celery/api/base.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/base.py#L25

Added line #L25 was not covered by tests
def default_config(cls) -> dict:
return {}

def __eq__(self, __value: object) -> bool:

Check warning on line 29 in src/pytest_celery/api/base.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/base.py#L29

Added line #L29 was not covered by tests
if isinstance(__value, CeleryTestNode):
return self.container == __value.container
return False

Check warning on line 32 in src/pytest_celery/api/base.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/base.py#L32

Added line #L32 was not covered by tests

def logs(self) -> str:
return self.container.logs()

Check warning on line 35 in src/pytest_celery/api/base.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/base.py#L34-L35

Added lines #L34 - L35 were not covered by tests

def name(self) -> str:
return self.container.name

Check warning on line 38 in src/pytest_celery/api/base.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/base.py#L37-L38

Added lines #L37 - L38 were not covered by tests

def kill(self) -> None:
self.container.kill()

Check warning on line 41 in src/pytest_celery/api/base.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/base.py#L40-L41

Added lines #L40 - L41 were not covered by tests

def teardown(self) -> None:

Check warning on line 43 in src/pytest_celery/api/base.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/base.py#L43

Added line #L43 was not covered by tests
self.container.teardown()


class CeleryTestCluster:
def __init__(self, *nodes: Tuple[Union[CeleryTestNode, CeleryTestContainer]]) -> None:
if not nodes:
Expand Down Expand Up @@ -38,11 +73,11 @@ def __eq__(self, __value: object) -> bool:

@property
def nodes(self) -> Tuple[CeleryTestNode]:
return self._nodes
return self.s

@nodes.setter
def nodes(self, nodes: Tuple[Union[CeleryTestNode, CeleryTestContainer]]) -> None:
self._nodes = self._set_nodes(*nodes) # type: ignore
self.s = self._set_nodes(*nodes) # type: ignore

@abstractmethod
def _set_nodes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
from typing import Union

from pytest_celery import defaults
from pytest_celery.api.components.broker.node import CeleryTestBroker
from pytest_celery.api.components.cluster.base import CeleryTestCluster
from pytest_celery.api.components.cluster.node import CeleryTestNode
from pytest_celery.api.base import CeleryTestCluster
from pytest_celery.api.base import CeleryTestNode

Check warning on line 7 in src/pytest_celery/api/broker.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/broker.py#L6-L7

Added lines #L6 - L7 were not covered by tests
from pytest_celery.api.container import CeleryTestContainer


class CeleryTestBroker(CeleryTestNode):
@classmethod

Check warning on line 12 in src/pytest_celery/api/broker.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/broker.py#L11-L12

Added lines #L11 - L12 were not covered by tests
def default_config(cls) -> dict:
return {
"url": defaults.WORKER_ENV["CELERY_BROKER_URL"],
"local_url": defaults.WORKER_ENV["CELERY_BROKER_URL"],
}


class CeleryBrokerCluster(CeleryTestCluster):
def __init__(self, *brokers: Tuple[Union[CeleryTestBroker, CeleryTestContainer]]) -> None:
super().__init__(*brokers)
Expand Down
10 changes: 0 additions & 10 deletions src/pytest_celery/api/components/__init__.py

This file was deleted.

4 changes: 0 additions & 4 deletions src/pytest_celery/api/components/backend/__init__.py

This file was deleted.

11 changes: 0 additions & 11 deletions src/pytest_celery/api/components/backend/node.py

This file was deleted.

4 changes: 0 additions & 4 deletions src/pytest_celery/api/components/broker/__init__.py

This file was deleted.

11 changes: 0 additions & 11 deletions src/pytest_celery/api/components/broker/node.py

This file was deleted.

4 changes: 0 additions & 4 deletions src/pytest_celery/api/components/cluster/__init__.py

This file was deleted.

37 changes: 0 additions & 37 deletions src/pytest_celery/api/components/cluster/node.py

This file was deleted.

4 changes: 0 additions & 4 deletions src/pytest_celery/api/components/worker/__init__.py

This file was deleted.

25 changes: 0 additions & 25 deletions src/pytest_celery/api/components/worker/cluster.py

This file was deleted.

8 changes: 4 additions & 4 deletions src/pytest_celery/api/setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from celery import Celery

from pytest_celery import defaults
from pytest_celery.api.components.backend.cluster import CeleryBackendCluster
from pytest_celery.api.components.broker.cluster import CeleryBrokerCluster
from pytest_celery.api.components.worker.cluster import CeleryWorkerCluster
from pytest_celery.api.components.worker.node import CeleryTestWorker
from pytest_celery.api.backend import CeleryBackendCluster
from pytest_celery.api.broker import CeleryBrokerCluster
from pytest_celery.api.worker import CeleryTestWorker
from pytest_celery.api.worker import CeleryWorkerCluster

Check warning on line 7 in src/pytest_celery/api/setup.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/setup.py#L4-L7

Added lines #L4 - L7 were not covered by tests


class CeleryTestSetup:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from typing import Set
from typing import Tuple
from typing import Type
from typing import Union

Check warning on line 4 in src/pytest_celery/api/worker.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/worker.py#L1-L4

Added lines #L1 - L4 were not covered by tests

from celery import Celery

from pytest_celery.api.components.cluster.node import CeleryTestNode
from pytest_celery.api.base import CeleryTestCluster
from pytest_celery.api.base import CeleryTestNode

Check warning on line 9 in src/pytest_celery/api/worker.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/worker.py#L8-L9

Added lines #L8 - L9 were not covered by tests
from pytest_celery.api.container import CeleryTestContainer
from pytest_celery.containers.worker import CeleryWorkerContainer

Expand Down Expand Up @@ -33,3 +39,19 @@ def worker_name(self) -> str:
@property
def worker_queue(self) -> str:
return self.container.worker_queue()


class CeleryWorkerCluster(CeleryTestCluster):
def __init__(self, *workers: Tuple[Union[CeleryTestWorker, CeleryTestContainer]]) -> None:

Check warning on line 45 in src/pytest_celery/api/worker.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/worker.py#L44-L45

Added lines #L44 - L45 were not covered by tests
super().__init__(*workers)

def _set_nodes(

Check warning on line 48 in src/pytest_celery/api/worker.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/worker.py#L48

Added line #L48 was not covered by tests
self,
*nodes: Tuple[Union[CeleryTestNode, CeleryTestContainer]],
node_cls: Type[CeleryTestNode] = CeleryTestWorker,
) -> Tuple[CeleryTestNode]:
return super()._set_nodes(*nodes, node_cls=node_cls)

@property

Check warning on line 55 in src/pytest_celery/api/worker.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/worker.py#L55

Added line #L55 was not covered by tests
def versions(self) -> Set[str]:
return {worker.version for worker in self} # type: ignore
2 changes: 1 addition & 1 deletion src/pytest_celery/components/worker/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pytest_docker_tools import volume

from pytest_celery import defaults
from pytest_celery.api.components.worker.node import CeleryTestWorker
from pytest_celery.api.worker import CeleryTestWorker

Check warning on line 13 in src/pytest_celery/components/worker/fixtures.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/components/worker/fixtures.py#L13

Added line #L13 was not covered by tests
from pytest_celery.containers.worker import CeleryWorkerContainer


Expand Down
2 changes: 1 addition & 1 deletion src/pytest_celery/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

# Default container settings for all worker container fixtures
WORKER_CELERY_APP_NAME = "celery_test_app"
WORKER_CELERY_VERSION = "5.3.0b2"
WORKER_CELERY_VERSION = "5.3"

Check warning on line 95 in src/pytest_celery/defaults.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/defaults.py#L95

Added line #L95 was not covered by tests
WORKER_LOG_LEVEL = "INFO"
WORKER_NAME = CELERY_SETUP_WORKER
WORKER_QUEUE = "celery"
Expand Down
4 changes: 2 additions & 2 deletions src/pytest_celery/fixtures/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pytest

from pytest_celery import defaults
from pytest_celery.api.components.backend import CeleryBackendCluster
from pytest_celery.api.components.backend import CeleryTestBackend
from pytest_celery.api.backend import CeleryBackendCluster
from pytest_celery.api.backend import CeleryTestBackend

Check warning on line 7 in src/pytest_celery/fixtures/backend.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/fixtures/backend.py#L6-L7

Added lines #L6 - L7 were not covered by tests


@pytest.fixture(params=defaults.ALL_CELERY_BACKENDS)
Expand Down
4 changes: 2 additions & 2 deletions src/pytest_celery/fixtures/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pytest

from pytest_celery import defaults
from pytest_celery.api.components.broker import CeleryBrokerCluster
from pytest_celery.api.components.broker import CeleryTestBroker
from pytest_celery.api.broker import CeleryBrokerCluster
from pytest_celery.api.broker import CeleryTestBroker

Check warning on line 7 in src/pytest_celery/fixtures/broker.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/fixtures/broker.py#L6-L7

Added lines #L6 - L7 were not covered by tests


@pytest.fixture(params=defaults.ALL_CELERY_BROKERS)
Expand Down
6 changes: 3 additions & 3 deletions src/pytest_celery/fixtures/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import pytest
from celery import Celery

from pytest_celery.api.components.backend.cluster import CeleryBackendCluster
from pytest_celery.api.components.broker.cluster import CeleryBrokerCluster
from pytest_celery.api.components.worker.cluster import CeleryWorkerCluster
from pytest_celery.api.backend import CeleryBackendCluster
from pytest_celery.api.broker import CeleryBrokerCluster

Check warning on line 7 in src/pytest_celery/fixtures/setup.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/fixtures/setup.py#L6-L7

Added lines #L6 - L7 were not covered by tests
from pytest_celery.api.setup import CeleryTestSetup
from pytest_celery.api.worker import CeleryWorkerCluster

Check warning on line 9 in src/pytest_celery/fixtures/setup.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/fixtures/setup.py#L9

Added line #L9 was not covered by tests


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions src/pytest_celery/fixtures/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pytest

from pytest_celery import defaults
from pytest_celery.api.components.worker import CeleryTestWorker
from pytest_celery.api.components.worker import CeleryWorkerCluster
from pytest_celery.api.worker import CeleryTestWorker
from pytest_celery.api.worker import CeleryWorkerCluster

Check warning on line 7 in src/pytest_celery/fixtures/worker.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/fixtures/worker.py#L6-L7

Added lines #L6 - L7 were not covered by tests


@pytest.fixture(params=defaults.ALL_CELERY_WORKERS)
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pytest_docker_tools import fxtr

from pytest_celery import defaults
from pytest_celery.api.components.worker.node import CeleryTestWorker
from pytest_celery.api.worker import CeleryTestWorker
from pytest_celery.containers.worker import CeleryWorkerContainer


Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pytest_lazyfixture import lazy_fixture

from pytest_celery import defaults
from pytest_celery.api.components.worker.node import CeleryTestWorker
from pytest_celery.api.worker import CeleryTestWorker


@pytest.mark.parametrize("node", [lazy_fixture(defaults.CELERY_SETUP_WORKER)])
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/setup/custom/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from pytest_docker_tools import fxtr

from pytest_celery import defaults
from pytest_celery.api.components.worker.cluster import CeleryWorkerCluster
from pytest_celery.api.components.worker.node import CeleryTestWorker
from pytest_celery.api.worker import CeleryTestWorker
from pytest_celery.api.worker import CeleryWorkerCluster
from pytest_celery.containers.worker import CeleryWorkerContainer
from tests.conftest import Celery5WorkerContainer

Expand Down
Loading

0 comments on commit 4526e45

Please sign in to comment.