|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | from abc import abstractmethod |
4 | | -from typing import Any |
5 | 4 | from typing import Iterator |
6 | 5 |
|
7 | 6 | import pytest_docker_tools |
|
14 | 13 |
|
15 | 14 |
|
16 | 15 | class CeleryTestNode: |
17 | | - """CeleryTestNode is the logical representation of a container instance. It |
18 | | - is used to provide a common interface for interacting with the container |
19 | | - regardless of the underlying implementation. |
| 16 | + """This is the logical representation of a container instance. It is used |
| 17 | + to provide a common interface for interacting with the container regardless |
| 18 | + of the underlying implementation. |
20 | 19 |
|
21 | 20 | Responsibility Scope: |
22 | 21 | The node's responsibility is to wrap the container and provide |
@@ -44,6 +43,8 @@ def app(self) -> Celery: |
44 | 43 | return self._app |
45 | 44 |
|
46 | 45 | def __eq__(self, other: object) -> bool: |
| 46 | + """Two nodes are equal if they have the same container and Celery |
| 47 | + app.""" |
47 | 48 | if isinstance(other, CeleryTestNode): |
48 | 49 | return all( |
49 | 50 | ( |
@@ -152,8 +153,8 @@ def assert_log_does_not_exist(self, log: str, message: str = "", timeout: int = |
152 | 153 |
|
153 | 154 |
|
154 | 155 | class CeleryTestCluster: |
155 | | - """CeleryTestCluster is a collection of CeleryTestNodes. It is used to |
156 | | - collect the test nodes into a single object for easier management. |
| 156 | + """This is a collection of CeleryTestNodes. It is used to collect the test |
| 157 | + nodes into a single object for easier management. |
157 | 158 |
|
158 | 159 | Responsibility Scope: |
159 | 160 | The cluster's responsibility is to define which nodes will be used for |
@@ -194,19 +195,24 @@ def nodes(self, nodes: tuple[CeleryTestNode | CeleryTestContainer]) -> None: |
194 | 195 | self._nodes = self._set_nodes(*nodes) # type: ignore |
195 | 196 |
|
196 | 197 | def __iter__(self) -> Iterator[CeleryTestNode]: |
| 198 | + """Iterate over the nodes of the cluster.""" |
197 | 199 | return iter(self.nodes) |
198 | 200 |
|
199 | | - def __getitem__(self, index: Any) -> CeleryTestNode: |
| 201 | + def __getitem__(self, index: int) -> CeleryTestNode: |
| 202 | + """Get a node from the cluster by index.""" |
200 | 203 | return self.nodes[index] |
201 | 204 |
|
202 | 205 | def __len__(self) -> int: |
| 206 | + """Get the number of nodes in the cluster.""" |
203 | 207 | return len(self.nodes) |
204 | 208 |
|
205 | 209 | def __eq__(self, other: object) -> bool: |
| 210 | + """Two clusters are equal if they have the same nodes.""" |
206 | 211 | if isinstance(other, CeleryTestCluster): |
207 | | - for node in self: |
208 | | - if node not in other: |
209 | | - return False |
| 212 | + if len(self) == len(other): |
| 213 | + for node in self: |
| 214 | + if node not in other: |
| 215 | + return False |
210 | 216 | return False |
211 | 217 |
|
212 | 218 | @classmethod |
|
0 commit comments