Skip to content

Commit 20cc3af

Browse files
committed
new test
1 parent b545545 commit 20cc3af

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/lib/test_archive.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ def tar4(tmp_path: pathlib.Path) -> pathlib.Path:
8989
return tar
9090

9191

92+
@pytest.fixture
93+
def tar5(tmp_path: pathlib.Path) -> pathlib.Path:
94+
a = tmp_path.joinpath("a")
95+
a.write_text("")
96+
b = tmp_path.joinpath("b")
97+
b.write_text("")
98+
99+
tar = tmp_path.joinpath("tar")
100+
101+
with tarfile.open(tar, "w:tar") as tarf:
102+
tarf.add(a, arcname="foo/v1/bar")
103+
tarf.add(b, arcname="foo/v2/baz")
104+
105+
return tar
106+
107+
92108
@pytest.fixture
93109
def mock_sleep() -> typing.Generator[mock.MagicMock, None, None]:
94110
with mock.patch.object(time, "sleep", autospec=True) as mock_sleep:
@@ -234,3 +250,19 @@ def test_unpack_strip_n_root(
234250
archive.unpack_strip_n(str(tar4), str(dest2), n=0)
235251
# n=0 can be used to just strip the root component
236252
assert os.path.exists(f"{tmp_path}/dest/foo/bar")
253+
254+
255+
def test_unpack_strip_n_unexpected_structure_inconsistent_components(
256+
tar5: pathlib.Path, tmp_path: pathlib.Path
257+
) -> None:
258+
dest = tmp_path.joinpath("dest")
259+
with pytest.raises(ValueError) as excinfo:
260+
archive.unpack_strip_n(str(tar5), str(dest), n=2)
261+
262+
assert (
263+
f"{excinfo.value}"
264+
== """unexpected archive structure:
265+
266+
foo/v2/baz doesn't have the prefix to be removed (foo/v1/)
267+
"""
268+
)

0 commit comments

Comments
 (0)