-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for new make_archive function
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pathlib | ||
import zipfile | ||
|
||
from rslp.launcher_lib import make_archive | ||
|
||
|
||
def test_make_archive(tmp_path: pathlib.Path): | ||
# Make sure make_archive correctly ignores the passed prefixes. | ||
# We make sure it works with exactly matching file as well as a subdirectory. | ||
exclude_prefixes = [ | ||
"ignored_file", | ||
"dir/ignored_subdir", | ||
] | ||
root_dir = tmp_path / "root" | ||
(root_dir / "dir" / "ignored_subdir").mkdir(parents=True, exist_ok=True) | ||
(root_dir / "dir" / "okay_subdir").mkdir(parents=True, exist_ok=True) | ||
(root_dir / "okay_file1").touch() | ||
(root_dir / "ignored_file").touch() | ||
(root_dir / "dir" / "okay_file2").touch() | ||
(root_dir / "dir" / "ignored_subdir" / "also_ignored").touch() | ||
(root_dir / "dir" / "okay_subdir" / "okay_file3").touch() | ||
|
||
zip_fname = str(tmp_path / "archive.zip") | ||
|
||
make_archive(zip_fname, str(root_dir), exclude_prefixes=exclude_prefixes) | ||
with zipfile.ZipFile(zip_fname) as zipf: | ||
members = zipf.namelist() | ||
|
||
assert "okay_file1" in members | ||
assert "dir/okay_file2" in members | ||
assert "dir/okay_subdir/okay_file3" in members | ||
assert len(members) == 3 |