Skip to content
Snippets Groups Projects
Commit 14f8c429 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

tests/tarball: Use uncompress function instead of private ones

Do not leak internal swh.core.tarball implementation in tests.

Also fix swh.core.tarball.uncompress documentation and implementation,
the function should not return a value.
parent cbf07d95
No related branches found
No related tags found
No related merge requests found
......@@ -83,9 +83,6 @@ def uncompress(tarpath: str, dest: str):
tarpath: path to tarball to uncompress
dest: the destination folder where to uncompress the tarball
Returns:
The nature of the tarball, zip or tar.
Raises:
ValueError when a problem occurs during unpacking
......@@ -96,7 +93,7 @@ def uncompress(tarpath: str, dest: str):
raise ValueError(f"Problem during unpacking {tarpath}. Reason: {e}")
except NotImplementedError:
if tarpath.endswith(".zip"):
return _unpack_zip(tarpath, dest)
_unpack_zip(tarpath, dest)
else:
raise
......
......@@ -115,7 +115,7 @@ def test_compress_uncompress_tar_modes(tmp_path):
assert executable_path.stat().st_mode == 0o100755
def test__unpack_tar_failure(tmp_path, datadir):
def test_uncompress_tar_failure(tmp_path, datadir):
"""Unpack inexistent tarball should fail
"""
......@@ -123,13 +123,11 @@ def test__unpack_tar_failure(tmp_path, datadir):
assert not os.path.exists(tarpath)
with pytest.raises(
shutil.ReadError, match=f"Unable to uncompress {tarpath} to {tmp_path}"
):
tarball._unpack_tar(tarpath, tmp_path)
with pytest.raises(ValueError, match=f"Problem during unpacking {tarpath}"):
tarball.uncompress(tarpath, tmp_path)
def test__unpack_tar_failure2(tmp_path, datadir):
def test_uncompress_tar_failure2(tmp_path, datadir):
"""Unpack Existent tarball into an inexistent folder should fail
"""
......@@ -140,28 +138,11 @@ def test__unpack_tar_failure2(tmp_path, datadir):
extract_dir = os.path.join(tmp_path, "dir", "inexistent")
with pytest.raises(
shutil.ReadError, match=f"Unable to uncompress {tarpath} to {tmp_path}"
):
tarball._unpack_tar(tarpath, extract_dir)
with pytest.raises(ValueError, match=f"Problem during unpacking {tarpath}"):
tarball.uncompress(tarpath, extract_dir)
def test__unpack_tar_failure3(tmp_path, datadir):
"""Unpack unsupported tarball should fail
"""
filename = "hello.zip"
tarpath = os.path.join(datadir, "archives", filename)
assert os.path.exists(tarpath)
with pytest.raises(
shutil.ReadError, match=f"Unable to uncompress {tarpath} to {tmp_path}"
):
tarball._unpack_tar(tarpath, tmp_path)
def test__unpack_tar(tmp_path, datadir):
def test_uncompress_tar(tmp_path, datadir):
"""Unpack supported tarball into an existent folder should be ok
"""
......@@ -173,9 +154,8 @@ def test__unpack_tar(tmp_path, datadir):
extract_dir = os.path.join(tmp_path, filename)
os.makedirs(extract_dir, exist_ok=True)
output_directory = tarball._unpack_tar(tarpath, extract_dir)
tarball.uncompress(tarpath, extract_dir)
assert extract_dir == output_directory
assert len(os.listdir(extract_dir)) > 0
......@@ -256,7 +236,6 @@ def test_unpcompress_zip_imploded(tmp_path, datadir):
extract_dir = os.path.join(tmp_path, filename)
os.makedirs(extract_dir, exist_ok=True)
output_directory = tarball.uncompress(zippath, extract_dir)
tarball.uncompress(zippath, extract_dir)
assert extract_dir == output_directory
assert len(os.listdir(extract_dir)) > 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment