Skip to content

Commit bc5a593

Browse files
remove duplicated code
1 parent ad66715 commit bc5a593

File tree

1 file changed

+2
-121
lines changed

1 file changed

+2
-121
lines changed

core/testcontainers/core/wait_strategies.py

Lines changed: 2 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@
3131
import time
3232
from datetime import timedelta
3333
from pathlib import Path
34-
from typing import TYPE_CHECKING, Any, Callable, Optional, Union
34+
from typing import Any, Callable, Optional, TYPE_CHECKING, Union
3535
from urllib.error import HTTPError, URLError
3636
from urllib.request import Request, urlopen
3737

38+
from testcontainers.compose import DockerCompose
3839
from testcontainers.core.utils import setup_logger
39-
from . import testcontainers_config
4040
# Import base classes from waiting_utils to make them available for tests
4141
from testcontainers.core.waiting_utils import WaitStrategy, WaitStrategyTarget
42-
from testcontainers.compose import DockerCompose
4342

4443
if TYPE_CHECKING:
4544
from testcontainers.core.container import DockerContainer
@@ -81,22 +80,6 @@ def __init__(
8180
self._times = times
8281
self._predicate_streams_and = predicate_streams_and
8382

84-
def with_startup_timeout(self, timeout: Union[int, timedelta]) -> "LogMessageWaitStrategy":
85-
"""Set the maximum time to wait for the container to be ready."""
86-
if isinstance(timeout, timedelta):
87-
self._startup_timeout = int(timeout.total_seconds())
88-
else:
89-
self._startup_timeout = timeout
90-
return self
91-
92-
def with_poll_interval(self, interval: Union[float, timedelta]) -> "LogMessageWaitStrategy":
93-
"""Set how frequently to check if the container is ready."""
94-
if isinstance(interval, timedelta):
95-
self._poll_interval = interval.total_seconds()
96-
else:
97-
self._poll_interval = interval
98-
return self
99-
10083
def wait_until_ready(self, container: "WaitStrategyTarget") -> None:
10184
"""
10285
Wait until the specified message appears in the container logs.
@@ -202,22 +185,6 @@ def __init__(self, port: int, path: Optional[str] = "/") -> None:
202185
self._body: Optional[str] = None
203186
self._insecure_tls = False
204187

205-
def with_startup_timeout(self, timeout: Union[int, timedelta]) -> "HttpWaitStrategy":
206-
"""Set the maximum time to wait for the container to be ready."""
207-
if isinstance(timeout, timedelta):
208-
self._startup_timeout = int(timeout.total_seconds())
209-
else:
210-
self._startup_timeout = timeout
211-
return self
212-
213-
def with_poll_interval(self, interval: Union[float, timedelta]) -> "HttpWaitStrategy":
214-
"""Set how frequently to check if the container is ready."""
215-
if isinstance(interval, timedelta):
216-
self._poll_interval = interval.total_seconds()
217-
else:
218-
self._poll_interval = interval
219-
return self
220-
221188
@classmethod
222189
def from_url(cls, url: str) -> "HttpWaitStrategy":
223190
"""
@@ -487,22 +454,6 @@ class HealthcheckWaitStrategy(WaitStrategy):
487454
def __init__(self) -> None:
488455
super().__init__()
489456

490-
def with_startup_timeout(self, timeout: Union[int, timedelta]) -> "HealthcheckWaitStrategy":
491-
"""Set the maximum time to wait for the container to be ready."""
492-
if isinstance(timeout, timedelta):
493-
self._startup_timeout = int(timeout.total_seconds())
494-
else:
495-
self._startup_timeout = timeout
496-
return self
497-
498-
def with_poll_interval(self, interval: Union[float, timedelta]) -> "HealthcheckWaitStrategy":
499-
"""Set how frequently to check if the container is ready."""
500-
if isinstance(interval, timedelta):
501-
self._poll_interval = interval.total_seconds()
502-
else:
503-
self._poll_interval = interval
504-
return self
505-
506457
def wait_until_ready(self, container: WaitStrategyTarget) -> None:
507458
"""
508459
Wait until the container's health check reports as healthy.
@@ -585,22 +536,6 @@ def __init__(self, port: int) -> None:
585536
super().__init__()
586537
self._port = port
587538

588-
def with_startup_timeout(self, timeout: Union[int, timedelta]) -> "PortWaitStrategy":
589-
"""Set the maximum time to wait for the container to be ready."""
590-
if isinstance(timeout, timedelta):
591-
self._startup_timeout = int(timeout.total_seconds())
592-
else:
593-
self._startup_timeout = timeout
594-
return self
595-
596-
def with_poll_interval(self, interval: Union[float, timedelta]) -> "PortWaitStrategy":
597-
"""Set how frequently to check if the container is ready."""
598-
if isinstance(interval, timedelta):
599-
self._poll_interval = interval.total_seconds()
600-
else:
601-
self._poll_interval = interval
602-
return self
603-
604539
def wait_until_ready(self, container: WaitStrategyTarget) -> None:
605540
"""
606541
Wait until the specified port is available for connection.
@@ -658,22 +593,6 @@ def __init__(self, file_path: Union[str, Path]) -> None:
658593
super().__init__()
659594
self._file_path = Path(file_path)
660595

661-
def with_startup_timeout(self, timeout: Union[int, timedelta]) -> "FileExistsWaitStrategy":
662-
"""Set the maximum time to wait for the container to be ready."""
663-
if isinstance(timeout, timedelta):
664-
self._startup_timeout = int(timeout.total_seconds())
665-
else:
666-
self._startup_timeout = timeout
667-
return self
668-
669-
def with_poll_interval(self, interval: Union[float, timedelta]) -> "FileExistsWaitStrategy":
670-
"""Set how frequently to check if the container is ready."""
671-
if isinstance(interval, timedelta):
672-
self._poll_interval = interval.total_seconds()
673-
else:
674-
self._poll_interval = interval
675-
return self
676-
677596
def wait_until_ready(self, container: WaitStrategyTarget) -> None:
678597
"""
679598
Wait until the specified file exists on the host filesystem.
@@ -806,44 +725,6 @@ def __init__(self, *strategies: WaitStrategy) -> None:
806725
super().__init__()
807726
self._strategies = list(strategies)
808727

809-
def with_startup_timeout(self, timeout: Union[int, timedelta]) -> "CompositeWaitStrategy":
810-
"""
811-
Set the startup timeout for all contained strategies.
812-
813-
Args:
814-
timeout: Maximum time to wait in seconds
815-
816-
Returns:
817-
self for method chaining
818-
"""
819-
if isinstance(timeout, timedelta):
820-
self._startup_timeout = int(timeout.total_seconds())
821-
else:
822-
self._startup_timeout = timeout
823-
824-
for strategy in self._strategies:
825-
strategy.with_startup_timeout(timeout)
826-
return self
827-
828-
def with_poll_interval(self, interval: Union[float, timedelta]) -> "CompositeWaitStrategy":
829-
"""
830-
Set the poll interval for all contained strategies.
831-
832-
Args:
833-
interval: How frequently to check in seconds
834-
835-
Returns:
836-
self for method chaining
837-
"""
838-
if isinstance(interval, timedelta):
839-
self._poll_interval = interval.total_seconds()
840-
else:
841-
self._poll_interval = interval
842-
843-
for strategy in self._strategies:
844-
strategy.with_poll_interval(interval)
845-
return self
846-
847728
def wait_until_ready(self, container: WaitStrategyTarget) -> None:
848729
"""
849730
Wait until all contained strategies are ready.

0 commit comments

Comments
 (0)