Skip to content

Commit 7b69f50

Browse files
committed
CR fixes
1 parent e9e8c2f commit 7b69f50

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

core/testcontainers/core/docker_client.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -180,25 +180,25 @@ def bridge_ip(self, container_id: str) -> str:
180180
"""
181181
container = self.get_container(container_id)
182182
network_name = self.network_name(container_id)
183-
return cast(str, container["NetworkSettings"]["Networks"][network_name]["IPAddress"])
183+
return str(container["NetworkSettings"]["Networks"][network_name]["IPAddress"])
184184

185185
def network_name(self, container_id: str) -> str:
186186
"""
187187
Get the name of the network this container runs on
188188
"""
189189
container = self.get_container(container_id)
190-
name = container["HostConfig"]["NetworkMode"]
190+
name = str(container["HostConfig"]["NetworkMode"])
191191
if name == "default":
192192
return "bridge"
193-
return cast(str, name)
193+
return name
194194

195195
def gateway_ip(self, container_id: str) -> str:
196196
"""
197197
Get the gateway ip address for a container.
198198
"""
199199
container = self.get_container(container_id)
200200
network_name = self.network_name(container_id)
201-
return cast(str, container["NetworkSettings"]["Networks"][network_name]["Gateway"])
201+
return str(container["NetworkSettings"]["Networks"][network_name]["Gateway"])
202202

203203
def get_connection_mode(self) -> ConnectionMode:
204204
"""
@@ -235,7 +235,8 @@ def host(self) -> str:
235235
return "localhost"
236236
if "http" in url.scheme or "tcp" in url.scheme and url.hostname:
237237
# see https://github.com/testcontainers/testcontainers-python/issues/415
238-
if url.hostname == "localnpipe" and utils.is_windows():
238+
hostname = url.hostname
239+
if not hostname or (hostname == "localnpipe" and utils.is_windows()):
239240
return "localhost"
240241
return cast(str, url.hostname)
241242
if utils.inside_container() and ("unix" in url.scheme or "npipe" in url.scheme):

0 commit comments

Comments
 (0)