Changeset View
Changeset View
Standalone View
Standalone View
swh/core/tests/test_tarball.py
Show First 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | def test_register_new_archive_formats(prepare_shutil_state): | ||||
tarball.register_new_archive_formats() | tarball.register_new_archive_formats() | ||||
# then | # then | ||||
unpack_formats_v2 = [f[0] for f in shutil.get_unpack_formats()] | unpack_formats_v2 = [f[0] for f in shutil.get_unpack_formats()] | ||||
for format_id in tarball.ADDITIONAL_ARCHIVE_FORMATS: | for format_id in tarball.ADDITIONAL_ARCHIVE_FORMATS: | ||||
assert format_id[0] in unpack_formats_v2 | assert format_id[0] in unpack_formats_v2 | ||||
def test_uncompress_tarpaths(tmp_path, datadir, prepare_shutil_state): | def test_uncompress_archives(tmp_path, datadir, prepare_shutil_state): | ||||
"""High level call uncompression on un/supported tarballs | """High level call uncompression on un/supported archives | ||||
""" | """ | ||||
archive_dir = os.path.join(datadir, "archives") | archive_dir = os.path.join(datadir, "archives") | ||||
tarfiles = os.listdir(archive_dir) | archive_files = os.listdir(archive_dir) | ||||
tarpaths = [os.path.join(archive_dir, tarfile) for tarfile in tarfiles] | |||||
unsupported_tarpaths = [] | |||||
for t in tarpaths: | |||||
if t.endswith(".Z") or t.endswith(".x") or t.endswith(".lz"): | |||||
unsupported_tarpaths.append(t) | |||||
# not supported yet | # not supported yet | ||||
for tarpath in unsupported_tarpaths: | unsupported_archives = [] | ||||
with pytest.raises(ValueError, match=f"Problem during unpacking {tarpath}."): | for archive_file in archive_files: | ||||
tarball.uncompress(tarpath, dest=tmp_path) | if any([archive_file.endswith(ext) for ext in (".Z", ".x", ".lz", ".egg")]): | ||||
unsupported_archives.append(os.path.join(archive_dir, archive_file)) | |||||
for archive_path in unsupported_archives: | |||||
with pytest.raises( | |||||
ValueError, match=f"Problem during unpacking {archive_path}." | |||||
): | |||||
tarball.uncompress(archive_path, dest=tmp_path) | |||||
# register those unsupported formats | # register those unsupported formats | ||||
tarball.register_new_archive_formats() | tarball.register_new_archive_formats() | ||||
# unsupported formats are now supported | # unsupported formats are now supported | ||||
for n, tarpath in enumerate(tarpaths, start=1): | for archive_file in archive_files: | ||||
tarball.uncompress(tarpath, dest=tmp_path) | archive_path = os.path.join(archive_dir, archive_file) | ||||
extract_dir = os.path.join(tmp_path, archive_file) | |||||
assert n == len(tarpaths) | tarball.uncompress(archive_path, dest=extract_dir) | ||||
assert len(os.listdir(extract_dir)) > 0 | |||||
def test_normalize_permissions(tmp_path): | def test_normalize_permissions(tmp_path): | ||||
for perms in range(0o1000): | for perms in range(0o1000): | ||||
filename = str(perms) | filename = str(perms) | ||||
file_path = tmp_path / filename | file_path = tmp_path / filename | ||||
file_path.touch() | file_path.touch() | ||||
file_path.chmod(perms) | file_path.chmod(perms) | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |