mirror of
https://github.com/ajurna/cbwebreader.git
synced 2026-11-02 10:36:55 +00:00
**Replace Flake8 with Ruff, refactor type hints, and enhance archive processing logic**
- Removed `flake8` and `flake8-annotations` from dependencies, replaced by `ruff` for linting. - Introduced cleaner type hinting and modern Python annotations (PEP 604 style) across multiple modules. - Moved archive processing to a dedicated helper (`comic.archives`) for improved maintainability. - Updated and simplified logic for archive file retrieval, directory cleaning, and user access validation. - Improved error handling and added support for user classification restrictions in API responses.
This commit is contained in:
1 parent
1148f4072b
commit
a7e9bd0743
16 files changed
+553
-4
No files matched your search
@@ -0,0 +1,42 @@
|
||||
"""Tests for the shared archive page listing in comic.archives."""
|
||||
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
from comic.archives import get_archive_files
|
||||
from comic.tests.factories import make_cbz
|
||||
|
||||
|
||||
def names(archive: zipfile.ZipFile) -> list[str]:
|
||||
return [entry.file_name for entry in get_archive_files(archive)]
|
||||
|
||||
|
||||
def test_metadata_entries_are_not_pages(tmp_path: Path) -> None:
|
||||
path = make_cbz(tmp_path / 'issue.cbz', pages=2, metadata=True)
|
||||
with zipfile.ZipFile(path) as archive:
|
||||
assert names(archive) == ['page00.png', 'page01.png']
|
||||
|
||||
|
||||
def test_entries_are_returned_in_page_order(tmp_path: Path) -> None:
|
||||
path = tmp_path / 'issue.cbz'
|
||||
with zipfile.ZipFile(path, 'w') as archive:
|
||||
archive.writestr('page10.png', b'x')
|
||||
archive.writestr('page02.png', b'x')
|
||||
archive.writestr('page01.png', b'x')
|
||||
with zipfile.ZipFile(path) as archive:
|
||||
assert names(archive) == ['page01.png', 'page02.png', 'page10.png']
|
||||
|
||||
|
||||
def test_directory_entries_are_ignored(tmp_path: Path) -> None:
|
||||
path = tmp_path / 'issue.cbz'
|
||||
with zipfile.ZipFile(path, 'w') as archive:
|
||||
archive.writestr('cover.png', b'x')
|
||||
archive.writestr('images/', b'')
|
||||
with zipfile.ZipFile(path) as archive:
|
||||
assert names(archive) == ['cover.png']
|
||||
|
||||
|
||||
def test_mime_type_is_guessed_from_the_file_name(tmp_path: Path) -> None:
|
||||
path = make_cbz(tmp_path / 'issue.cbz', pages=1, metadata=False)
|
||||
with zipfile.ZipFile(path) as archive:
|
||||
assert get_archive_files(archive)[0].mime_type == 'image/png'
|
||||
Reference in new issue
Block a user