-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mehdi BEN ABDALLAH
committed
May 26, 2024
1 parent
cae372b
commit 67f5220
Showing
7 changed files
with
44 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
|
||
from pathlib import Path | ||
from os import path | ||
import tarfile | ||
import tempfile | ||
from contextlib import contextmanager | ||
from os import path | ||
from pathlib import Path | ||
|
||
from docker.models.containers import Container | ||
|
||
|
||
@contextmanager | ||
def file(container: Container, target: str): | ||
target_path = Path(target) | ||
assert target_path.is_absolute(), "target must be an absolute path" | ||
|
||
with tempfile.TemporaryDirectory() as tmp: | ||
archive = Path(tmp) / 'grabbed.tar' | ||
target_path = Path(target) | ||
assert target_path.is_absolute(), "target must be an absolute path" | ||
|
||
# download from container as tar archive | ||
with open(archive, 'wb') as f: | ||
tar_bits, _ = container.get_archive(target) | ||
for chunk in tar_bits: | ||
f.write(chunk) | ||
with tempfile.TemporaryDirectory() as tmp: | ||
archive = Path(tmp) / "grabbed.tar" | ||
|
||
# extract target file from tar archive | ||
with tarfile.TarFile(archive) as tar: | ||
yield tar.extractfile(path.basename(target)) | ||
# download from container as tar archive | ||
with open(archive, "wb") as f: | ||
tar_bits, _ = container.get_archive(target) | ||
for chunk in tar_bits: | ||
f.write(chunk) | ||
|
||
# extract target file from tar archive | ||
with tarfile.TarFile(archive) as tar: | ||
yield tar.extractfile(path.basename(target)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import pytest | ||
from testcontainers.cosmosdb import CosmosDBNoSQLEndpointContainer | ||
|
||
|
||
def test_runs(): | ||
with CosmosDBNoSQLEndpointContainer(partition_count=1, bind_ports=False) as emulator: | ||
assert emulator.get_exposed_port(8081) is not None, "The NoSQL endpoint's port should be exposed" |