Skip to content

Commit

Permalink
Refactoring (#52)
Browse files Browse the repository at this point in the history
* Cleaner tox runs

* Simplified folder & files structure

* Added WORKER_DOCKERFILE_ROOTDIR to defaults

* Cleanup

* Fixed bug where celery_setup_name fixture wasn't used correctly

* Changed docker tag for default worker container from pytest-celery/components/worker:base to pytest-celery/components/worker:default

* Removed unused fixtures
- default_rabbitmq_broker_celeryconfig
- default_redis_broker_celeryconfig
- default_redis_backend_celeryconfig

* Renamed DEFAULT_NETWORK -> default_pytest_celery_network

* poetry.lock

* Refactored tests folder & files structure
  • Loading branch information
Nusnus authored Oct 10, 2023
1 parent f13c10d commit ce0863c
Show file tree
Hide file tree
Showing 86 changed files with 540 additions and 781 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Run tox for "${{ matrix.python-version }}-unit"
timeout-minutes: 5
run: |
tox --verbose --verbose -e "${{ matrix.python-version }}-unit" -- -n auto --reruns 3 --rerun-except AssertionError
tox --verbose --verbose -e "${{ matrix.python-version }}-unit" -- -n auto --reruns 5 --rerun-except AssertionError
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
Expand Down Expand Up @@ -119,7 +119,7 @@ jobs:
- name: Run tox for "${{ matrix.python-version }}-integration"
timeout-minutes: 15
run: |
tox --verbose --verbose -e "${{ matrix.python-version }}-integration" -- -n auto --reruns 3 --rerun-except AssertionError
tox --verbose --verbose -e "${{ matrix.python-version }}-integration" -- -n auto --reruns 5 --rerun-except AssertionError
Smoke:
needs:
Expand Down Expand Up @@ -167,4 +167,4 @@ jobs:
- name: Run tox for "${{ matrix.python-version }}-smoke"
timeout-minutes: 50
run: |
tox --verbose --verbose -e "${{ matrix.python-version }}-smoke" -- -n auto --reruns 3 --rerun-except AssertionError
tox --verbose --verbose -e "${{ matrix.python-version }}-smoke" -- -n auto --reruns 5 --rerun-except AssertionError
485 changes: 244 additions & 241 deletions poetry.lock

Large diffs are not rendered by default.

89 changes: 21 additions & 68 deletions src/pytest_celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,27 @@

# flake8: noqa

from pytest_celery.defaults import *

__version__ = "1.0.0a1"


from pytest_celery.api import CeleryBackendCluster
from pytest_celery.api import CeleryBrokerCluster
from pytest_celery.api import CeleryTestBackend
from pytest_celery.api import CeleryTestBroker
from pytest_celery.api import CeleryTestCluster
from pytest_celery.api import CeleryTestContainer
from pytest_celery.api import CeleryTestNode
from pytest_celery.api import CeleryTestSetup
from pytest_celery.api import CeleryTestWorker
from pytest_celery.api import CeleryWorkerCluster
from pytest_celery.components import RabbitMQTestBroker
from pytest_celery.components import RedisTestBackend
from pytest_celery.components import RedisTestBroker
from pytest_celery.components import celery_base_worker_image
from pytest_celery.components import celery_rabbitmq_broker
from pytest_celery.components import celery_redis_backend
from pytest_celery.components import celery_redis_broker
from pytest_celery.components import celery_setup_worker
from pytest_celery.components import default_rabbitmq_broker
from pytest_celery.components import default_rabbitmq_broker_celeryconfig
from pytest_celery.components import default_rabbitmq_broker_cls
from pytest_celery.components import default_rabbitmq_broker_env
from pytest_celery.components import default_rabbitmq_broker_image
from pytest_celery.components import default_rabbitmq_broker_ports
from pytest_celery.components import default_redis_backend
from pytest_celery.components import default_redis_backend_celeryconfig
from pytest_celery.components import default_redis_backend_cls
from pytest_celery.components import default_redis_backend_env
from pytest_celery.components import default_redis_backend_image
from pytest_celery.components import default_redis_backend_ports
from pytest_celery.components import default_redis_broker
from pytest_celery.components import default_redis_broker_celeryconfig
from pytest_celery.components import default_redis_broker_cls
from pytest_celery.components import default_redis_broker_env
from pytest_celery.components import default_redis_broker_image
from pytest_celery.components import default_redis_broker_ports
from pytest_celery.components import default_worker_celerky_worker_queue
from pytest_celery.components import default_worker_celery_log_level
from pytest_celery.components import default_worker_celery_version
from pytest_celery.components import default_worker_celery_worker_name
from pytest_celery.components import default_worker_cls
from pytest_celery.components import default_worker_container
from pytest_celery.components import default_worker_container_cls
from pytest_celery.components import default_worker_container_session_cls
from pytest_celery.components import default_worker_env
from pytest_celery.components import default_worker_initial_content
from pytest_celery.components import default_worker_signals
from pytest_celery.components import default_worker_tasks
from pytest_celery.components import default_worker_volume
from pytest_celery.containers import CeleryWorkerContainer
from pytest_celery.containers import RabbitMQContainer
from pytest_celery.containers import RedisContainer
from pytest_celery.fixtures import celery_backend
from pytest_celery.fixtures import celery_backend_cluster
from pytest_celery.fixtures import celery_backend_cluster_config
from pytest_celery.fixtures import celery_broker
from pytest_celery.fixtures import celery_broker_cluster
from pytest_celery.fixtures import celery_broker_cluster_config
from pytest_celery.fixtures import celery_setup
from pytest_celery.fixtures import celery_setup_app
from pytest_celery.fixtures import celery_setup_cls
from pytest_celery.fixtures import celery_setup_config
from pytest_celery.fixtures import celery_setup_name
from pytest_celery.fixtures import celery_worker
from pytest_celery.fixtures import celery_worker_cluster
from pytest_celery.fixtures import celery_worker_cluster_config
from pytest_celery.api.backend import *
from pytest_celery.api.base import *
from pytest_celery.api.broker import *
from pytest_celery.api.container import *
from pytest_celery.api.setup import *
from pytest_celery.api.worker import *
from pytest_celery.defaults import *
from pytest_celery.fixtures.backend import *
from pytest_celery.fixtures.broker import *
from pytest_celery.fixtures.setup import *
from pytest_celery.fixtures.worker import *
from pytest_celery.vendors.rabbitmq.api import *
from pytest_celery.vendors.rabbitmq.container import *
from pytest_celery.vendors.rabbitmq.fixtures import *
from pytest_celery.vendors.redis.backend.api import *
from pytest_celery.vendors.redis.backend.fixtures import *
from pytest_celery.vendors.redis.broker.api import *
from pytest_celery.vendors.redis.broker.fixtures import *
from pytest_celery.vendors.redis.container import *
from pytest_celery.vendors.worker.container import *
from pytest_celery.vendors.worker.fixtures import *
12 changes: 0 additions & 12 deletions src/pytest_celery/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
# 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.container import CeleryTestContainer
from pytest_celery.api.setup import CeleryTestSetup
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
from pytest_celery.api.container import CeleryTestContainer


class CeleryTestBackend(CeleryTestNode):
@classmethod
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):
self._container = container

@property
def container(self) -> CeleryTestContainer:
return self._container

def ready(self) -> bool:
return self.container.ready()

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

@classmethod
def default_config(cls) -> dict:
return {}

def __eq__(self, __value: object) -> bool:
if isinstance(__value, CeleryTestNode):
return self.container == __value.container
return False

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

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

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

def teardown(self) -> None:
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
from pytest_celery.api.container import CeleryTestContainer


class CeleryTestBroker(CeleryTestNode):
@classmethod
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.

3 changes: 3 additions & 0 deletions src/pytest_celery/api/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def celeryconfig(self) -> dict:

@classmethod
def command(cls) -> list:
# To be used with pytest_docker_tools.container
# using the command kwarg with the class method as value
# e.g. command=MyContainer.command()
raise NotImplementedError("CeleryTestContainer.command")

def teardown(self) -> None:
Expand Down
11 changes: 5 additions & 6 deletions src/pytest_celery/api/setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
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
from pytest_celery.vendors.worker.tasks import ping


class CeleryTestSetup:
Expand All @@ -20,8 +21,6 @@ def __init__(
self._backend_cluster = backend_cluster
self._app = app

from pytest_celery.components.worker.tasks import ping

self.ping = ping

def __len__(self) -> int:
Expand Down
Loading

0 comments on commit ce0863c

Please sign in to comment.