Skip to content

Commit 1162271

Browse files
committed
more fixes
1 parent 4c10229 commit 1162271

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

core/testcontainers/compose/compose.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def get_config(
293293
config_cmd.append("--no-interpolate")
294294

295295
cmd_output = self._run_command(cmd=config_cmd).stdout
296-
return cast(dict[str, Any], loads(cmd_output))
296+
return cast(dict[str, Any], loads(cmd_output)) # noqa: TC006
297297

298298
def get_containers(self, include_all=False) -> list[ComposeContainer]:
299299
"""

core/testcontainers/core/config.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ class ConnectionMode(Enum):
1717
@property
1818
def use_mapped_port(self) -> bool:
1919
"""
20-
Return true if we need to use mapped port for this connection
20+
Return True if mapped ports should be used for this connection mode.
2121
22-
This is true for everything but bridge mode.
22+
Mapped ports are used for all connection modes except 'bridge_ip'.
2323
"""
24-
if self == self.bridge_ip: # type: ignore[comparison-overlap]
25-
return False
26-
return True
24+
return self != ConnectionMode.bridge_ip
2725

2826

2927
def get_docker_socket() -> str:
@@ -137,15 +135,15 @@ def timeout(self) -> int:
137135
testcontainers_config = TestcontainersConfiguration()
138136

139137
__all__ = [
140-
# the public API of this module
141-
"testcontainers_config",
142-
# and all the legacy things that are deprecated:
138+
# Legacy things that are deprecated:
143139
"MAX_TRIES",
144-
"SLEEP_TIME",
145-
"TIMEOUT",
146-
"RYUK_IMAGE",
147-
"RYUK_PRIVILEGED",
148140
"RYUK_DISABLED",
149141
"RYUK_DOCKER_SOCKET",
142+
"RYUK_IMAGE",
143+
"RYUK_PRIVILEGED",
150144
"RYUK_RECONNECTION_TIMEOUT",
145+
"SLEEP_TIME",
146+
"TIMEOUT",
147+
# Public API of this module:
148+
"testcontainers_config",
151149
]

core/testcontainers/core/docker_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def port(self, container_id: str, port: int) -> str:
162162
"""
163163
port_mappings = self.client.api.port(container_id, port)
164164
if not port_mappings:
165-
raise ConnectionError(f"Port mapping for container {container_id} and port {port} is " "not available")
165+
raise ConnectionError(f"Port mapping for container {container_id} and port {port} is not available")
166166
return cast(str, port_mappings[0]["HostPort"])
167167

168168
def get_container(self, container_id: str) -> dict[str, Any]:
@@ -233,7 +233,10 @@ def host(self) -> str:
233233
url = urllib.parse.urlparse(self.client.api.base_url)
234234
except ValueError:
235235
return "localhost"
236-
if "http" in url.scheme or "tcp" in url.scheme and url.hostname:
236+
237+
is_http_scheme = "http" in url.scheme
238+
is_tcp_scheme_with_hostname = "tcp" in url.scheme and url.hostname
239+
if is_http_scheme or is_tcp_scheme_with_hostname:
237240
# see https://github.com/testcontainers/testcontainers-python/issues/415
238241
hostname = url.hostname
239242
if not hostname or (hostname == "localnpipe" and utils.is_windows()):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# flake8: noqa
1+
# flake8: noqa: F401
22
from testcontainers.socat.socat import SocatContainer

modules/mqtt/testcontainers/mqtt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(
5050
super().__init__(image, **kwargs)
5151
# self.password = password
5252
# reusable client context:
53-
self.client: Optional["Client"] = None
53+
self.client: Optional["Client"] = None # noqa: UP037
5454

5555
@wait_container_is_ready()
5656
def get_client(self) -> "Client":

modules/opensearch/testcontainers/opensearch/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from testcontainers.core.utils import raise_for_deprecated_parameter
99
from testcontainers.core.waiting_utils import wait_container_is_ready
1010

11+
MIN_REQUIRED_INITIAL_ADMIN_PASSWORD = [2, 12, 0]
12+
1113

1214
class OpenSearchContainer(DockerContainer):
1315
"""
@@ -65,7 +67,7 @@ def __init__(
6567

6668
def _supports_initial_admin_password(self, image: str) -> bool:
6769
with suppress(Exception):
68-
return [int(n) for n in image.split(":")[-1].split(".")] >= [int(n) for n in "2.12.0".split(".")]
70+
return [int(n) for n in image.split(":")[-1].split(".")] >= MIN_REQUIRED_INITIAL_ADMIN_PASSWORD
6971
return False
7072

7173
def get_config(self) -> dict:

0 commit comments

Comments
 (0)