Skip to content

Commit

Permalink
new test
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuarli committed Oct 3, 2024
1 parent b545545 commit 20cc3af
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/lib/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ def tar4(tmp_path: pathlib.Path) -> pathlib.Path:
return tar


@pytest.fixture
def tar5(tmp_path: pathlib.Path) -> pathlib.Path:
a = tmp_path.joinpath("a")
a.write_text("")
b = tmp_path.joinpath("b")
b.write_text("")

tar = tmp_path.joinpath("tar")

with tarfile.open(tar, "w:tar") as tarf:
tarf.add(a, arcname="foo/v1/bar")
tarf.add(b, arcname="foo/v2/baz")

return tar


@pytest.fixture
def mock_sleep() -> typing.Generator[mock.MagicMock, None, None]:
with mock.patch.object(time, "sleep", autospec=True) as mock_sleep:
Expand Down Expand Up @@ -234,3 +250,19 @@ def test_unpack_strip_n_root(
archive.unpack_strip_n(str(tar4), str(dest2), n=0)
# n=0 can be used to just strip the root component
assert os.path.exists(f"{tmp_path}/dest/foo/bar")


def test_unpack_strip_n_unexpected_structure_inconsistent_components(
tar5: pathlib.Path, tmp_path: pathlib.Path
) -> None:
dest = tmp_path.joinpath("dest")
with pytest.raises(ValueError) as excinfo:
archive.unpack_strip_n(str(tar5), str(dest), n=2)

assert (
f"{excinfo.value}"
== """unexpected archive structure:
foo/v2/baz doesn't have the prefix to be removed (foo/v1/)
"""
)

0 comments on commit 20cc3af

Please sign in to comment.