Skip to content

Commit

Permalink
added edge case test
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Neagu committed Dec 20, 2024
1 parent 21c7f0a commit a58849f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

_logger = logging.getLogger(__name__)

_TOTAL_BYTES_RE: Final[str] = r" (\d+)\s*bytes "
_TOTAL_BYTES_RE: Final[str] = r" (\d+)\s*bytes"
_FILE_COUNT_RE: Final[str] = r" (\d+)\s*files"
_PROGRESS_PERCENT_RE: Final[str] = r" (?:100|\d?\d)% "
_ALL_DONE_RE: Final[str] = r"Everything is Ok"
Expand Down Expand Up @@ -301,7 +301,7 @@ async def unarchive_dir(

tqdm_progress = exit_stack.enter_context(
tqdm.tqdm(
desc=f"decompressing {archive_to_extract} -> {destination_folder} [{file_count} file{'s' if file_count > 1 else ''}"
desc=f"decompressing {archive_to_extract} -> {destination_folder} [{file_count} file{'' if file_count == 1 else 's'}"
f"/{human_readable_size(archive_to_extract.stat().st_size)}]\n",
total=total_bytes,
**TQDM_MULTI_FILES_OPTIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ def _escape_undecodable_str(s: str) -> str:
return s.encode(errors="replace").decode("utf-8")


def _escape_undecodable_path(path: Path) -> Path:
return Path(_escape_undecodable_str(str(path)))


async def assert_same_directory_content(
dir_to_compress: Path,
output_dir: Path,
Expand Down Expand Up @@ -430,3 +426,21 @@ async def test_regression_archive_hash_does_not_change(
_, first_hash = _compute_hash(first_archive)
_, second_hash = _compute_hash(second_archive)
assert first_hash == second_hash


@pytest.mark.parametrize("compress", [True, False])
async def test_archive_empty_folder(tmp_path: Path, compress: bool):
archive_path = tmp_path / "zip_archive"
assert not archive_path.exists()

empty_folder_path = tmp_path / "empty"
empty_folder_path.mkdir(parents=True, exist_ok=True)
extract_to_path = tmp_path / "extracted_to"
extract_to_path.mkdir(parents=True, exist_ok=True)

await archive_dir(empty_folder_path, archive_path, compress=compress)

detected_files = await unarchive_dir(archive_path, extract_to_path)
assert detected_files == set()

await assert_same_directory_content(empty_folder_path, extract_to_path)

0 comments on commit a58849f

Please sign in to comment.