diff --git a/src/archivefile/_adapters/_base.py b/src/archivefile/_adapters/_base.py index f37c9c6..7398119 100644 --- a/src/archivefile/_adapters/_base.py +++ b/src/archivefile/_adapters/_base.py @@ -26,6 +26,7 @@ class BaseArchiveAdapter(Protocol): A base protocol that can be inherited from to implement more adapters. Refer to `src/archivefile/_core.py` for documentation of every method and property. """ + # fmt: off @overload def __init__(self, file: StrPath, mode: OpenArchiveMode = "r", *, password: str | None = None, compression_type: CompressionType | None = None, compression_level: CompressionLevel | None = None, **kwargs: Any) -> None: ... diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index c1bd09b..b81eb1e 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -50,6 +50,9 @@ Path("tests/test_data/source_STORE.zip"), ) +# Alias the pre-configured parametrize function for reusability +parametrize_files = pytest.mark.parametrize("file", files, ids=lambda x: x.name) + def test_write_rar() -> None: with pytest.raises(NotImplementedError): @@ -91,35 +94,35 @@ def test_existing_unsupported_archive(tmp_path: Path) -> None: archive.write_text("abc1234", arcname="a.txt") -@pytest.mark.parametrize("file", files) +@parametrize_files def test_missing_member(file: Path) -> None: with pytest.raises(KeyError): with ArchiveFile(file) as archive: archive.get_member("non-existent.member") -@pytest.mark.parametrize("file", files) +@parametrize_files def test_missing_member_in_read_bytes(file: Path) -> None: with pytest.raises(KeyError): with ArchiveFile(file) as archive: archive.read_bytes("non-existent.member") -@pytest.mark.parametrize("file", files) +@parametrize_files def test_missing_member_in_read_text(file: Path) -> None: with pytest.raises(KeyError): with ArchiveFile(file) as archive: archive.read_text("non-existent.member") -@pytest.mark.parametrize("file", files) +@parametrize_files def test_missing_member_in_extract(file: Path) -> None: with pytest.raises(KeyError): with ArchiveFile(file) as archive: archive.extract("non-existent.member") -@pytest.mark.parametrize("file", files) +@parametrize_files def test_missing_member_in_extractall(file: Path, tmp_path: Path) -> None: with pytest.raises(KeyError): with ArchiveFile(file) as archive: diff --git a/tests/test_extract.py b/tests/test_extract.py index 6e95911..97de94b 100644 --- a/tests/test_extract.py +++ b/tests/test_extract.py @@ -35,15 +35,18 @@ Path("tests/test_data/source_STORE.zip"), ) +# Alias the pre-configured parametrize function for reusability +parametrize_files = pytest.mark.parametrize("file", files, ids=lambda x: x.name) -@pytest.mark.parametrize("file", files) + +@parametrize_files def test_extract(file: Path, tmp_path: Path) -> None: with ArchiveFile(file) as archive: member = archive.extract("pyanilist-main/README.md", destination=tmp_path) assert member.is_file() -@pytest.mark.parametrize("file", files) +@parametrize_files def test_extract_without_context_manager(file: Path, tmp_path: Path) -> None: archive = ArchiveFile(file) extracted_file = archive.extract("pyanilist-main/README.md", destination=tmp_path) @@ -51,7 +54,7 @@ def test_extract_without_context_manager(file: Path, tmp_path: Path) -> None: assert extracted_file.is_file() -@pytest.mark.parametrize("file", files) +@parametrize_files def test_extract_by_member(file: Path, tmp_path: Path) -> None: with ArchiveFile(file) as archive: member = [member for member in archive.get_members() if member.is_file][0] @@ -59,7 +62,7 @@ def test_extract_by_member(file: Path, tmp_path: Path) -> None: assert outfile.is_file() -@pytest.mark.parametrize("file", files) +@parametrize_files def test_extractall(file: Path, tmp_path: Path) -> None: with ZipFile("tests/test_data/source_STORE.zip") as archive: dest = tmp_path / uuid4().hex @@ -73,7 +76,7 @@ def test_extractall(file: Path, tmp_path: Path) -> None: assert control == members -@pytest.mark.parametrize("file", files) +@parametrize_files def test_extractall_by_members(file: Path, tmp_path: Path) -> None: expected = [ "pyanilist-main/.gitignore", diff --git a/tests/test_member.py b/tests/test_member.py index 605f699..077d46c 100644 --- a/tests/test_member.py +++ b/tests/test_member.py @@ -33,14 +33,17 @@ Path("tests/test_data/source_STORE.zip"), ) +# Alias the pre-configured parametrize function for reusability +parametrize_files = pytest.mark.parametrize("file", files, ids=lambda x: x.name) -@pytest.mark.parametrize("file", files) + +@parametrize_files def test_get_members(file: Path) -> None: with ArchiveFile(file) as archive: assert len(tuple(archive.get_members())) == 53 -@pytest.mark.parametrize("file", files) +@parametrize_files def test_get_members_without_context_manager(file: Path) -> None: archive = ArchiveFile(file) total_members = len(tuple(archive.get_members())) @@ -48,13 +51,13 @@ def test_get_members_without_context_manager(file: Path) -> None: assert total_members == 53 -@pytest.mark.parametrize("file", files) +@parametrize_files def test_get_names(file: Path) -> None: with ArchiveFile(file) as archive: assert len(archive.get_names()) == 53 -@pytest.mark.parametrize("file", files) +@parametrize_files def test_get_names_without_context_manager(file: Path) -> None: archive = ArchiveFile(file) total_members = len(archive.get_names()) @@ -62,14 +65,14 @@ def test_get_names_without_context_manager(file: Path) -> None: assert total_members == 53 -@pytest.mark.parametrize("file", files) +@parametrize_files def test_member_and_names(file: Path) -> None: with ArchiveFile(file) as archive: names = tuple([member.name for member in archive.get_members()]) assert archive.get_names() == names -@pytest.mark.parametrize("file", files) +@parametrize_files def test_members_and_names_without_context_manager(file: Path) -> None: archive = ArchiveFile(file) names = tuple([member.name for member in archive.get_members()]) diff --git a/tests/test_property.py b/tests/test_property.py index 1ee0297..cc9eb18 100644 --- a/tests/test_property.py +++ b/tests/test_property.py @@ -18,6 +18,7 @@ (Path("tests/test_data/source_STORE.rar"), None, None, "RarFileAdapter"), (Path("tests/test_data/source_STORE.zip"), CompressionType.STORED, None, "ZipFileAdapter"), ], + ids=lambda x: x.name if isinstance(x, Path) else x, # https://github.com/pytest-dev/pytest/issues/8283 ) def test_core_properties( file: Path, compression_type: CompressionType | None, compression_level: int | None, adapter: str diff --git a/tests/test_read.py b/tests/test_read.py index 131bfc1..5827a65 100644 --- a/tests/test_read.py +++ b/tests/test_read.py @@ -58,29 +58,32 @@ For more information, please refer to """ +# Alias the pre-configured parametrize function for reusability +parametrize_files = pytest.mark.parametrize("file", files, ids=lambda x: x.name) -@pytest.mark.parametrize("file", files) + +@parametrize_files def test_read_text_file(file: Path) -> None: with ArchiveFile(file) as archive: member = archive.read_text("pyanilist-main/UNLICENSE") assert member.strip() == unlicense.strip() -@pytest.mark.parametrize("file", files) +@parametrize_files def test_read_bytes_file(file: Path) -> None: with ArchiveFile(file) as archive: member = archive.read_bytes("pyanilist-main/UNLICENSE") assert member.decode().strip() == unlicense.strip() -@pytest.mark.parametrize("file", files) +@parametrize_files def test_read_text_folder(file: Path) -> None: with ArchiveFile(file) as archive: member = archive.read_text("pyanilist-main/src/") assert member == "" -@pytest.mark.parametrize("file", files) +@parametrize_files def test_read_bytes_folder(file: Path) -> None: with ArchiveFile(file) as archive: member = archive.read_bytes("pyanilist-main/src/")