Skip to content

Commit 8ddf5c6

Browse files
committed
fixes
1 parent 631740e commit 8ddf5c6

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

core/testcontainers/core/container.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(
7474
volumes: Optional[list[tuple[str, str, str]]] = None,
7575
network: Optional[Network] = None,
7676
network_aliases: Optional[list[str]] = None,
77-
transferrables: Optional[list[Transferable]] = None,
77+
transferables: Optional[list[Transferable]] = None,
7878
**kwargs: Any,
7979
) -> None:
8080
self.env = env or {}
@@ -102,7 +102,7 @@ def __init__(
102102
self.with_network_aliases(*network_aliases)
103103

104104
self._kwargs = kwargs
105-
self._transferables: list[Transferable] = transferrables or []
105+
self._transferables: list[Transferable] = transferables or []
106106

107107
def with_env(self, key: str, value: str) -> Self:
108108
self.env[key] = value
@@ -285,15 +285,19 @@ def _configure(self) -> None:
285285
pass
286286

287287
def with_copy_into_container(
288-
self, file_content: bytes | PathLike, destination_in_container: str, mode: int = 0o644
289-
):
288+
self, file_content: Union[bytes, PathLike], destination_in_container: str, mode: int = 0o644
289+
) -> Self:
290290
self._transferables.append(Transferable(file_content, destination_in_container, mode))
291291
return self
292292

293-
def copy_into_container(self, file_content: bytes | PathLike, destination_in_container: str, mode: int = 0o644):
293+
def copy_into_container(
294+
self, file_content: Union[bytes, PathLike], destination_in_container: str, mode: int = 0o644
295+
) -> None:
294296
return self._transfer_into_container(file_content, destination_in_container, mode)
295297

296-
def _transfer_into_container(self, source: bytes | PathLike, destination_in_container: str, mode: int):
298+
def _transfer_into_container(
299+
self, source: Union[bytes, PathLike], destination_in_container: str, mode: int
300+
) -> None:
297301
if isinstance(source, bytes):
298302
file_content = source
299303
elif isinstance(source, PathLike):
@@ -309,10 +313,12 @@ def _transfer_into_container(self, source: bytes | PathLike, destination_in_cont
309313
tarinfo.mode = mode
310314
tar.addfile(tarinfo, io.BytesIO(file_content))
311315
fileobj.seek(0)
316+
assert self._container is not None
312317
rv = self._container.put_archive(path="/", data=fileobj.getvalue())
313318
assert rv is True
314319

315-
def copy_from_container(self, source_in_container: str, destination_on_host: PathLike):
320+
def copy_from_container(self, source_in_container: str, destination_on_host: PathLike) -> None:
321+
assert self._container is not None
316322
tar_stream, _ = self._container.get_archive(source_in_container)
317323

318324
for chunk in tar_stream:
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import dataclasses
2-
import os
2+
import pathlib
33
from typing import Union
44

55

66
@dataclasses.dataclass
77
class Transferable:
8-
source: Union[bytes, os.PathLike]
8+
"""
9+
Wrapper class enabling copying files into a container
10+
"""
11+
12+
source: Union[bytes, pathlib.Path]
913
destination_in_container: str
1014
mode: int = 0o644

core/tests/test_core.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ def test_copy_file_into_container_via_initializer(tmp_path: Path):
8888
my_file = tmp_path / "my_file"
8989
my_file.write_text("hello world")
9090
destination_in_container = "/tmp/my_file"
91+
transferables = [Transferable(my_file, destination_in_container)]
9192

92-
with DockerContainer(
93-
"bash", command="sleep infinity", transferrables=(Transferable(my_file, destination_in_container),)
94-
) as container:
93+
with DockerContainer("bash", command="sleep infinity", transferables=transferables) as container:
9594
# When
9695
result = container.exec(f"cat {destination_in_container}")
9796

@@ -137,10 +136,9 @@ def test_copy_bytes_to_container_via_initializer():
137136
# Given
138137
file_content = b"hello world"
139138
destination_in_container = "/tmp/my_file"
139+
transferables = [Transferable(file_content, destination_in_container)]
140140

141-
with DockerContainer(
142-
"bash", command="sleep infinity", transferrables=(Transferable(file_content, destination_in_container),)
143-
) as container:
141+
with DockerContainer("bash", command="sleep infinity", transferables=transferables) as container:
144142
# When
145143
result = container.exec(f"cat {destination_in_container}")
146144

0 commit comments

Comments
 (0)