From b17536b1f23cdf329a002a363fdcd5bd7caee302 Mon Sep 17 00:00:00 2001 From: Favyen Bastani Date: Fri, 18 Oct 2024 15:20:21 -0700 Subject: [PATCH] add test for new make_archive function --- tests/unit/test_launcher_lib.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/unit/test_launcher_lib.py diff --git a/tests/unit/test_launcher_lib.py b/tests/unit/test_launcher_lib.py new file mode 100644 index 00000000..9dec5bee --- /dev/null +++ b/tests/unit/test_launcher_lib.py @@ -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