Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions submitit/core/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import shutil
import sys
import tarfile
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -72,6 +73,21 @@ def test_archive_dev_folders(tmp_path: Path) -> None:
assert (tmp_path / "core").exists()


@pytest.mark.parametrize("default_outfile", [False, True])
def test_archive_dev_folders_is_gzip(tmp_path: Path, monkeypatch, default_outfile: bool) -> None:
monkeypatch.chdir(tmp_path)
folder = tmp_path / "project"
folder.mkdir()
(folder / "data.txt").write_text("archived content")
outfile = None if default_outfile else tmp_path / "custom.tar.gz"
archive = utils.archive_dev_folders([folder], outfile=outfile)

with tarfile.open(archive, mode="r:gz") as reader:
content = reader.extractfile("project/data.txt")
assert content is not None
assert content.read() == b"archived content"


def test_command_function() -> None:
# This will call `submitit.core.test_core.do_nothing`
command = [sys.executable, "-m", "submitit.core.test_core"]
Expand Down
2 changes: 1 addition & 1 deletion submitit/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def archive_dev_folders(
outfile = "_dev_folders_.tar.gz"
outfile = Path(outfile)
assert str(outfile).endswith(".tar.gz"), "Archive file must have extension .tar.gz"
with tarfile.TarFile(outfile, mode="w") as tf:
with tarfile.open(outfile, mode="w:gz") as tf:
for folder in folders:
tf.add(str(folder), arcname=Path(folder).name)
return outfile
Expand Down