@@ -89,6 +89,22 @@ def tar4(tmp_path: pathlib.Path) -> pathlib.Path:
89
89
return tar
90
90
91
91
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
+
92
108
@pytest .fixture
93
109
def mock_sleep () -> typing .Generator [mock .MagicMock , None , None ]:
94
110
with mock .patch .object (time , "sleep" , autospec = True ) as mock_sleep :
@@ -234,3 +250,19 @@ def test_unpack_strip_n_root(
234
250
archive .unpack_strip_n (str (tar4 ), str (dest2 ), n = 0 )
235
251
# n=0 can be used to just strip the root component
236
252
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