mirror of
https://github.com/hyugogirubato/cbz.git
synced 2026-09-26 13:31:00 +00:00
fixing typo
This commit is contained in:
+17
-11
@@ -1,26 +1,32 @@
|
|||||||
import pytest
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from cbz.comic import ComicInfo
|
from cbz.comic import ComicInfo
|
||||||
from cbz.page import PageInfo
|
from cbz.page import PageInfo
|
||||||
from cbz.constants import PageType
|
from cbz.constants import PageType
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def fixtures_dir():
|
def fixtures_dir() -> Path:
|
||||||
"""Fixture that provides the path to the test fixtures directory."""
|
"""Fixture that provides the path to the test fixtures directory."""
|
||||||
return Path(__file__).parent / "fixtures"
|
return Path(__file__).parent / 'fixtures'
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def images_dir(fixtures_dir):
|
def images_dir(fixtures_dir: Path) -> Path:
|
||||||
"""Fixture that provides the path to the test images directory."""
|
"""Fixture that provides the path to the test images directory."""
|
||||||
return fixtures_dir / "images"
|
return fixtures_dir / 'images'
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def sample_image_path(images_dir):
|
def sample_image_path(images_dir: Path) -> Path:
|
||||||
"""Fixture that provides a sample image path."""
|
"""Fixture that provides a sample image path."""
|
||||||
return images_dir / "page-000.jpg"
|
return images_dir / 'page-000.jpg'
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def sample_cbz_file(tmp_path, images_dir):
|
def sample_cbz_file(tmp_path: Path, images_dir: Path) -> Path:
|
||||||
"""Fixture that creates a sample CBZ file for testing."""
|
"""Fixture that creates a sample CBZ file for testing."""
|
||||||
# Load sample pages
|
# Load sample pages
|
||||||
image_paths = sorted(list(images_dir.iterdir()))[:3] # Use first 3 images
|
image_paths = sorted(list(images_dir.iterdir()))[:3] # Use first 3 images
|
||||||
@@ -34,15 +40,15 @@ def sample_cbz_file(tmp_path, images_dir):
|
|||||||
# Create comic from pages
|
# Create comic from pages
|
||||||
comic = ComicInfo.from_pages(
|
comic = ComicInfo.from_pages(
|
||||||
pages=pages,
|
pages=pages,
|
||||||
title="Test Comic",
|
title='Test Comic',
|
||||||
series="Test Series",
|
series='Test Series',
|
||||||
number=1,
|
number=1,
|
||||||
volume=1,
|
volume=1,
|
||||||
year=2024
|
year=2024
|
||||||
)
|
)
|
||||||
|
|
||||||
# Save to temporary file
|
# Save to temporary file
|
||||||
cbz_path = tmp_path / "test_comic.cbz"
|
cbz_path = tmp_path / 'test_comic.cbz'
|
||||||
cbz_content = comic.pack()
|
cbz_content = comic.pack()
|
||||||
cbz_path.write_bytes(cbz_content)
|
cbz_path.write_bytes(cbz_content)
|
||||||
|
|
||||||
|
|||||||
+50
-46
@@ -1,15 +1,19 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from cbz.comic import ComicInfo
|
from cbz.comic import ComicInfo
|
||||||
from cbz.page import PageInfo
|
from cbz.page import PageInfo
|
||||||
from cbz.constants import PageType, YesNo, Manga, AgeRating, Format
|
from cbz.constants import PageType, YesNo, Manga, AgeRating, Format
|
||||||
|
|
||||||
|
|
||||||
class TestComicInfo:
|
class TestComicInfo:
|
||||||
"""Test cases for ComicInfo class."""
|
"""Test cases for ComicInfo class."""
|
||||||
|
|
||||||
def test_from_pages_creation(self, images_dir):
|
def test_from_pages_creation(self, images_dir: Path) -> None:
|
||||||
"""Test creating ComicInfo from pages."""
|
"""Test creating ComicInfo from pages."""
|
||||||
# Load sample pages
|
# Load sample pages
|
||||||
image_paths = sorted(list(images_dir.iterdir()))[:3] # Use first 3 images
|
image_paths = sorted(list(images_dir.iterdir()))[:3] # Use first 3 images
|
||||||
pages = []
|
pages: List[PageInfo] = []
|
||||||
|
|
||||||
for i, path in enumerate(image_paths):
|
for i, path in enumerate(image_paths):
|
||||||
page_type = PageType.FRONT_COVER if i == 0 else PageType.STORY
|
page_type = PageType.FRONT_COVER if i == 0 else PageType.STORY
|
||||||
@@ -19,15 +23,15 @@ class TestComicInfo:
|
|||||||
# Create comic from pages
|
# Create comic from pages
|
||||||
comic = ComicInfo.from_pages(
|
comic = ComicInfo.from_pages(
|
||||||
pages=pages,
|
pages=pages,
|
||||||
title="Test Comic",
|
title='Test Comic',
|
||||||
series="Test Series",
|
series='Test Series',
|
||||||
number=1,
|
number=1,
|
||||||
volume=1,
|
volume=1,
|
||||||
year=2024
|
year=2024
|
||||||
)
|
)
|
||||||
|
|
||||||
assert comic.title == "Test Comic"
|
assert comic.title == 'Test Comic'
|
||||||
assert comic.series == "Test Series"
|
assert comic.series == 'Test Series'
|
||||||
assert comic.number == 1
|
assert comic.number == 1
|
||||||
assert comic.volume == 1
|
assert comic.volume == 1
|
||||||
assert comic.year == 2024
|
assert comic.year == 2024
|
||||||
@@ -35,7 +39,7 @@ class TestComicInfo:
|
|||||||
assert comic.pages[0].type == PageType.FRONT_COVER
|
assert comic.pages[0].type == PageType.FRONT_COVER
|
||||||
assert comic.pages[1].type == PageType.STORY
|
assert comic.pages[1].type == PageType.STORY
|
||||||
|
|
||||||
def test_from_cbz_file(self, sample_cbz_file):
|
def test_from_cbz_file(self, sample_cbz_file: Path) -> None:
|
||||||
"""Test loading ComicInfo from CBZ file."""
|
"""Test loading ComicInfo from CBZ file."""
|
||||||
comic = ComicInfo.from_cbz(sample_cbz_file)
|
comic = ComicInfo.from_cbz(sample_cbz_file)
|
||||||
|
|
||||||
@@ -44,7 +48,7 @@ class TestComicInfo:
|
|||||||
assert len(comic.pages) > 0
|
assert len(comic.pages) > 0
|
||||||
assert all(isinstance(page, PageInfo) for page in comic.pages)
|
assert all(isinstance(page, PageInfo) for page in comic.pages)
|
||||||
|
|
||||||
def test_pack_cbz(self, images_dir):
|
def test_pack_cbz(self, images_dir: Path) -> None:
|
||||||
"""Test packing comic into CBZ format."""
|
"""Test packing comic into CBZ format."""
|
||||||
# Create a simple comic
|
# Create a simple comic
|
||||||
image_paths = sorted(list(images_dir.iterdir()))[:2]
|
image_paths = sorted(list(images_dir.iterdir()))[:2]
|
||||||
@@ -52,8 +56,8 @@ class TestComicInfo:
|
|||||||
|
|
||||||
comic = ComicInfo.from_pages(
|
comic = ComicInfo.from_pages(
|
||||||
pages=pages,
|
pages=pages,
|
||||||
title="Pack Test",
|
title='Pack Test',
|
||||||
series="Test Series"
|
series='Test Series'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Pack to CBZ
|
# Pack to CBZ
|
||||||
@@ -62,14 +66,14 @@ class TestComicInfo:
|
|||||||
assert isinstance(cbz_content, bytes)
|
assert isinstance(cbz_content, bytes)
|
||||||
assert len(cbz_content) > 0
|
assert len(cbz_content) > 0
|
||||||
|
|
||||||
def test_pack_with_rename(self, images_dir):
|
def test_pack_with_rename(self, images_dir: Path) -> None:
|
||||||
"""Test packing comic with page renaming."""
|
"""Test packing comic with page renaming."""
|
||||||
image_paths = sorted(list(images_dir.iterdir()))[:2]
|
image_paths = sorted(list(images_dir.iterdir()))[:2]
|
||||||
pages = [PageInfo.load(path=path) for path in image_paths]
|
pages = [PageInfo.load(path=path) for path in image_paths]
|
||||||
|
|
||||||
comic = ComicInfo.from_pages(
|
comic = ComicInfo.from_pages(
|
||||||
pages=pages,
|
pages=pages,
|
||||||
title="Rename Test"
|
title='Rename Test'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Pack with rename option
|
# Pack with rename option
|
||||||
@@ -78,33 +82,33 @@ class TestComicInfo:
|
|||||||
assert isinstance(cbz_content, bytes)
|
assert isinstance(cbz_content, bytes)
|
||||||
assert len(cbz_content) > 0
|
assert len(cbz_content) > 0
|
||||||
|
|
||||||
def test_comic_metadata_properties(self, images_dir):
|
def test_comic_metadata_properties(self, images_dir: Path) -> None:
|
||||||
"""Test comic metadata properties."""
|
"""Test comic metadata properties."""
|
||||||
image_paths = sorted(list(images_dir.iterdir()))[:1]
|
image_paths = sorted(list(images_dir.iterdir()))[:1]
|
||||||
pages = [PageInfo.load(path=path) for path in image_paths]
|
pages = [PageInfo.load(path=path) for path in image_paths]
|
||||||
|
|
||||||
comic = ComicInfo.from_pages(
|
comic = ComicInfo.from_pages(
|
||||||
pages=pages,
|
pages=pages,
|
||||||
title="Metadata Test",
|
title='Metadata Test',
|
||||||
series="Test Series",
|
series='Test Series',
|
||||||
number=5,
|
number=5,
|
||||||
count=10,
|
count=10,
|
||||||
volume=2,
|
volume=2,
|
||||||
summary="Test summary",
|
summary='Test summary',
|
||||||
year=2023,
|
year=2023,
|
||||||
month=6,
|
month=6,
|
||||||
day=15,
|
day=15,
|
||||||
writer="Test Writer",
|
writer='Test Writer',
|
||||||
penciller="Test Penciller",
|
penciller='Test Penciller',
|
||||||
inker="Test Inker",
|
inker='Test Inker',
|
||||||
colorist="Test Colorist",
|
colorist='Test Colorist',
|
||||||
letterer="Test Letterer",
|
letterer='Test Letterer',
|
||||||
cover_artist="Test Cover Artist",
|
cover_artist='Test Cover Artist',
|
||||||
editor="Test Editor",
|
editor='Test Editor',
|
||||||
publisher="Test Publisher",
|
publisher='Test Publisher',
|
||||||
imprint="Test Imprint",
|
imprint='Test Imprint',
|
||||||
genre="Test Genre",
|
genre='Test Genre',
|
||||||
language_iso="en",
|
language_iso='en',
|
||||||
format=Format.SERIES,
|
format=Format.SERIES,
|
||||||
black_white=YesNo.NO,
|
black_white=YesNo.NO,
|
||||||
manga=Manga.RIGHT_LEFT,
|
manga=Manga.RIGHT_LEFT,
|
||||||
@@ -112,44 +116,44 @@ class TestComicInfo:
|
|||||||
community_rating=4
|
community_rating=4
|
||||||
)
|
)
|
||||||
|
|
||||||
assert comic.title == "Metadata Test"
|
assert comic.title == 'Metadata Test'
|
||||||
assert comic.series == "Test Series"
|
assert comic.series == 'Test Series'
|
||||||
assert comic.number == 5
|
assert comic.number == 5
|
||||||
assert comic.count == 10
|
assert comic.count == 10
|
||||||
assert comic.volume == 2
|
assert comic.volume == 2
|
||||||
assert comic.summary == "Test summary"
|
assert comic.summary == 'Test summary'
|
||||||
assert comic.year == 2023
|
assert comic.year == 2023
|
||||||
assert comic.month == 6
|
assert comic.month == 6
|
||||||
assert comic.day == 15
|
assert comic.day == 15
|
||||||
assert comic.writer == "Test Writer"
|
assert comic.writer == 'Test Writer'
|
||||||
assert comic.penciller == "Test Penciller"
|
assert comic.penciller == 'Test Penciller'
|
||||||
assert comic.inker == "Test Inker"
|
assert comic.inker == 'Test Inker'
|
||||||
assert comic.colorist == "Test Colorist"
|
assert comic.colorist == 'Test Colorist'
|
||||||
assert comic.letterer == "Test Letterer"
|
assert comic.letterer == 'Test Letterer'
|
||||||
assert comic.cover_artist == "Test Cover Artist"
|
assert comic.cover_artist == 'Test Cover Artist'
|
||||||
assert comic.editor == "Test Editor"
|
assert comic.editor == 'Test Editor'
|
||||||
assert comic.publisher == "Test Publisher"
|
assert comic.publisher == 'Test Publisher'
|
||||||
assert comic.imprint == "Test Imprint"
|
assert comic.imprint == 'Test Imprint'
|
||||||
assert comic.genre == "Test Genre"
|
assert comic.genre == 'Test Genre'
|
||||||
assert comic.language_iso == "en"
|
assert comic.language_iso == 'en'
|
||||||
assert comic.format == Format.SERIES
|
assert comic.format == Format.SERIES
|
||||||
assert comic.black_white == YesNo.NO
|
assert comic.black_white == YesNo.NO
|
||||||
assert comic.manga == Manga.RIGHT_LEFT
|
assert comic.manga == Manga.RIGHT_LEFT
|
||||||
assert comic.age_rating == AgeRating.TEEN
|
assert comic.age_rating == AgeRating.TEEN
|
||||||
assert comic.community_rating == 4
|
assert comic.community_rating == 4
|
||||||
|
|
||||||
def test_page_count_property(self, images_dir):
|
def test_page_count_property(self, images_dir: Path) -> None:
|
||||||
"""Test that page count returns correct count."""
|
"""Test that page count returns correct count."""
|
||||||
image_paths = sorted(list(images_dir.iterdir()))[:4]
|
image_paths = sorted(list(images_dir.iterdir()))[:4]
|
||||||
pages = [PageInfo.load(path=path) for path in image_paths]
|
pages = [PageInfo.load(path=path) for path in image_paths]
|
||||||
|
|
||||||
comic = ComicInfo.from_pages(pages=pages, title="Count Test")
|
comic = ComicInfo.from_pages(pages=pages, title='Count Test')
|
||||||
|
|
||||||
assert len(comic.pages) == 4
|
assert len(comic.pages) == 4
|
||||||
|
|
||||||
def test_empty_pages_list(self):
|
def test_empty_pages_list(self) -> None:
|
||||||
"""Test creating comic with empty pages list."""
|
"""Test creating comic with empty pages list."""
|
||||||
comic = ComicInfo.from_pages(pages=[], title="Empty Test")
|
comic = ComicInfo.from_pages(pages=[], title='Empty Test')
|
||||||
|
|
||||||
assert comic.title == "Empty Test"
|
assert comic.title == 'Empty Test'
|
||||||
assert len(comic.pages) == 0
|
assert len(comic.pages) == 0
|
||||||
+60
-64
@@ -1,10 +1,11 @@
|
|||||||
from cbz.models import BaseModel, ComicModel, PageModel
|
from cbz.models import BaseModel, ComicModel, PageModel
|
||||||
from cbz.constants import Format, YesNo, Manga, AgeRating, PageType
|
from cbz.constants import Format, YesNo, Manga, AgeRating, PageType
|
||||||
|
|
||||||
|
|
||||||
class TestBaseModel:
|
class TestBaseModel:
|
||||||
"""Test cases for BaseModel class."""
|
"""Test cases for BaseModel class."""
|
||||||
|
|
||||||
def test_base_model_creation(self):
|
def test_base_model_creation(self) -> None:
|
||||||
"""Test creating BaseModel with fields."""
|
"""Test creating BaseModel with fields."""
|
||||||
test_fields = {
|
test_fields = {
|
||||||
'test_str': ('Test String', str),
|
'test_str': ('Test String', str),
|
||||||
@@ -19,7 +20,7 @@ class TestBaseModel:
|
|||||||
assert hasattr(model, 'test_int')
|
assert hasattr(model, 'test_int')
|
||||||
assert hasattr(model, 'test_bool')
|
assert hasattr(model, 'test_bool')
|
||||||
|
|
||||||
def test_base_model_with_kwargs(self):
|
def test_base_model_with_kwargs(self) -> None:
|
||||||
"""Test creating BaseModel with keyword arguments."""
|
"""Test creating BaseModel with keyword arguments."""
|
||||||
test_fields = {
|
test_fields = {
|
||||||
'title': ('Title', str),
|
'title': ('Title', str),
|
||||||
@@ -29,16 +30,16 @@ class TestBaseModel:
|
|||||||
|
|
||||||
model = BaseModel(
|
model = BaseModel(
|
||||||
fields=test_fields,
|
fields=test_fields,
|
||||||
title="Test Title",
|
title='Test Title',
|
||||||
number=42,
|
number=42,
|
||||||
published=True
|
published=True
|
||||||
)
|
)
|
||||||
|
|
||||||
assert model.title == "Test Title"
|
assert model.title == 'Test Title'
|
||||||
assert model.number == 42
|
assert model.number == 42
|
||||||
assert model.published
|
assert model.published
|
||||||
|
|
||||||
def test_attribute_type_verification(self):
|
def test_attribute_type_verification(self) -> None:
|
||||||
"""Test that attribute types are verified on assignment."""
|
"""Test that attribute types are verified on assignment."""
|
||||||
test_fields = {
|
test_fields = {
|
||||||
'count': ('Count', int),
|
'count': ('Count', int),
|
||||||
@@ -49,28 +50,28 @@ class TestBaseModel:
|
|||||||
|
|
||||||
# Valid assignments
|
# Valid assignments
|
||||||
model.count = 10
|
model.count = 10
|
||||||
model.name = "Test"
|
model.name = 'Test'
|
||||||
|
|
||||||
assert model.count == 10
|
assert model.count == 10
|
||||||
assert model.name == "Test"
|
assert model.name == 'Test'
|
||||||
|
|
||||||
def test_repr_method(self):
|
def test_repr_method(self) -> None:
|
||||||
"""Test string representation of BaseModel."""
|
"""Test string representation of BaseModel."""
|
||||||
test_fields = {
|
test_fields = {
|
||||||
'title': ('Title', str)
|
'title': ('Title', str)
|
||||||
}
|
}
|
||||||
|
|
||||||
model = BaseModel(fields=test_fields, title="Test")
|
model = BaseModel(fields=test_fields, title='Test')
|
||||||
repr_str = repr(model)
|
repr_str = repr(model)
|
||||||
|
|
||||||
assert isinstance(repr_str, str)
|
assert isinstance(repr_str, str)
|
||||||
assert "BaseModel" in repr_str
|
assert 'BaseModel' in repr_str
|
||||||
|
|
||||||
|
|
||||||
class TestComicModel:
|
class TestComicModel:
|
||||||
"""Test cases for ComicModel class."""
|
"""Test cases for ComicModel class."""
|
||||||
|
|
||||||
def test_comic_model_creation(self):
|
def test_comic_model_creation(self) -> None:
|
||||||
"""Test creating ComicModel with default values."""
|
"""Test creating ComicModel with default values."""
|
||||||
model = ComicModel()
|
model = ComicModel()
|
||||||
|
|
||||||
@@ -83,41 +84,41 @@ class TestComicModel:
|
|||||||
assert hasattr(model, 'month')
|
assert hasattr(model, 'month')
|
||||||
assert hasattr(model, 'day')
|
assert hasattr(model, 'day')
|
||||||
|
|
||||||
def test_comic_model_with_values(self):
|
def test_comic_model_with_values(self) -> None:
|
||||||
"""Test creating ComicModel with specific values."""
|
"""Test creating ComicModel with specific values."""
|
||||||
model = ComicModel(
|
model = ComicModel(
|
||||||
title="Test Comic",
|
title='Test Comic',
|
||||||
series="Test Series",
|
series='Test Series',
|
||||||
number=1,
|
number=1,
|
||||||
volume=1,
|
volume=1,
|
||||||
year=2024,
|
year=2024,
|
||||||
month=6,
|
month=6,
|
||||||
day=15,
|
day=15,
|
||||||
writer="Test Writer",
|
writer='Test Writer',
|
||||||
publisher="Test Publisher",
|
publisher='Test Publisher',
|
||||||
language_iso="en",
|
language_iso='en',
|
||||||
format=Format.SERIES,
|
format=Format.SERIES,
|
||||||
black_white=YesNo.NO,
|
black_white=YesNo.NO,
|
||||||
manga=Manga.RIGHT_LEFT,
|
manga=Manga.RIGHT_LEFT,
|
||||||
age_rating=AgeRating.EVERYONE
|
age_rating=AgeRating.EVERYONE
|
||||||
)
|
)
|
||||||
|
|
||||||
assert model.title == "Test Comic"
|
assert model.title == 'Test Comic'
|
||||||
assert model.series == "Test Series"
|
assert model.series == 'Test Series'
|
||||||
assert model.number == 1
|
assert model.number == 1
|
||||||
assert model.volume == 1
|
assert model.volume == 1
|
||||||
assert model.year == 2024
|
assert model.year == 2024
|
||||||
assert model.month == 6
|
assert model.month == 6
|
||||||
assert model.day == 15
|
assert model.day == 15
|
||||||
assert model.writer == "Test Writer"
|
assert model.writer == 'Test Writer'
|
||||||
assert model.publisher == "Test Publisher"
|
assert model.publisher == 'Test Publisher'
|
||||||
assert model.language_iso == "en"
|
assert model.language_iso == 'en'
|
||||||
assert model.format == Format.SERIES
|
assert model.format == Format.SERIES
|
||||||
assert model.black_white == YesNo.NO
|
assert model.black_white == YesNo.NO
|
||||||
assert model.manga == Manga.RIGHT_LEFT
|
assert model.manga == Manga.RIGHT_LEFT
|
||||||
assert model.age_rating == AgeRating.EVERYONE
|
assert model.age_rating == AgeRating.EVERYONE
|
||||||
|
|
||||||
def test_comic_model_enum_properties(self):
|
def test_comic_model_enum_properties(self) -> None:
|
||||||
"""Test that enum properties work correctly."""
|
"""Test that enum properties work correctly."""
|
||||||
model = ComicModel()
|
model = ComicModel()
|
||||||
|
|
||||||
@@ -137,41 +138,41 @@ class TestComicModel:
|
|||||||
model.age_rating = AgeRating.TEEN
|
model.age_rating = AgeRating.TEEN
|
||||||
assert model.age_rating == AgeRating.TEEN
|
assert model.age_rating == AgeRating.TEEN
|
||||||
|
|
||||||
def test_comic_model_metadata_fields(self):
|
def test_comic_model_metadata_fields(self) -> None:
|
||||||
"""Test comic metadata fields."""
|
"""Test comic metadata fields."""
|
||||||
model = ComicModel(
|
model = ComicModel(
|
||||||
summary="Test summary",
|
summary='Test summary',
|
||||||
notes="Test notes",
|
notes='Test notes',
|
||||||
genre="Adventure",
|
genre='Adventure',
|
||||||
web="http://example.com",
|
web='http://example.com',
|
||||||
ean="1234567890123",
|
ean='1234567890123',
|
||||||
community_rating=5,
|
community_rating=5,
|
||||||
main_character_or_team="Hero",
|
main_character_or_team='Hero',
|
||||||
characters="Hero, Villain",
|
characters='Hero, Villain',
|
||||||
teams="Justice League",
|
teams='Justice League',
|
||||||
locations="Metropolis",
|
locations='Metropolis',
|
||||||
scan_information="Scanned by Test",
|
scan_information='Scanned by Test',
|
||||||
story_arc="Origin Story",
|
story_arc='Origin Story',
|
||||||
series_group="DC Comics",
|
series_group='DC Comics',
|
||||||
alternate_series="Alternate Universe",
|
alternate_series='Alternate Universe',
|
||||||
alternate_number=2,
|
alternate_number=2,
|
||||||
alternate_count=10
|
alternate_count=10
|
||||||
)
|
)
|
||||||
|
|
||||||
assert model.summary == "Test summary"
|
assert model.summary == 'Test summary'
|
||||||
assert model.notes == "Test notes"
|
assert model.notes == 'Test notes'
|
||||||
assert model.genre == "Adventure"
|
assert model.genre == 'Adventure'
|
||||||
assert model.web == "http://example.com"
|
assert model.web == 'http://example.com'
|
||||||
assert model.ean == "1234567890123"
|
assert model.ean == '1234567890123'
|
||||||
assert model.community_rating == 5
|
assert model.community_rating == 5
|
||||||
assert model.main_character_or_team == "Hero"
|
assert model.main_character_or_team == 'Hero'
|
||||||
assert model.characters == "Hero, Villain"
|
assert model.characters == 'Hero, Villain'
|
||||||
assert model.teams == "Justice League"
|
assert model.teams == 'Justice League'
|
||||||
assert model.locations == "Metropolis"
|
assert model.locations == 'Metropolis'
|
||||||
assert model.scan_information == "Scanned by Test"
|
assert model.scan_information == 'Scanned by Test'
|
||||||
assert model.story_arc == "Origin Story"
|
assert model.story_arc == 'Origin Story'
|
||||||
assert model.series_group == "DC Comics"
|
assert model.series_group == 'DC Comics'
|
||||||
assert model.alternate_series == "Alternate Universe"
|
assert model.alternate_series == 'Alternate Universe'
|
||||||
assert model.alternate_number == 2
|
assert model.alternate_number == 2
|
||||||
assert model.alternate_count == 10
|
assert model.alternate_count == 10
|
||||||
|
|
||||||
@@ -179,7 +180,7 @@ class TestComicModel:
|
|||||||
class TestPageModel:
|
class TestPageModel:
|
||||||
"""Test cases for PageModel class."""
|
"""Test cases for PageModel class."""
|
||||||
|
|
||||||
def test_page_model_creation(self):
|
def test_page_model_creation(self) -> None:
|
||||||
"""Test creating PageModel with default values."""
|
"""Test creating PageModel with default values."""
|
||||||
model = PageModel()
|
model = PageModel()
|
||||||
|
|
||||||
@@ -195,29 +196,27 @@ class TestPageModel:
|
|||||||
assert hasattr(model, 'image_size')
|
assert hasattr(model, 'image_size')
|
||||||
# Note: format is not a base field in PageModel
|
# Note: format is not a base field in PageModel
|
||||||
|
|
||||||
def test_page_model_with_values(self):
|
def test_page_model_with_values(self) -> None:
|
||||||
"""Test creating PageModel with specific values."""
|
"""Test creating PageModel with specific values."""
|
||||||
model = PageModel(
|
model = PageModel(
|
||||||
image=1,
|
|
||||||
type=PageType.FRONT_COVER,
|
type=PageType.FRONT_COVER,
|
||||||
double=True,
|
double=True,
|
||||||
image_size=1024000,
|
image_size=1024000,
|
||||||
key="cover",
|
key='cover',
|
||||||
bookmark="Chapter 1",
|
bookmark='Chapter 1',
|
||||||
image_width=800,
|
image_width=800,
|
||||||
image_height=1200,
|
image_height=1200,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert model.image == 1
|
|
||||||
assert model.type == PageType.FRONT_COVER
|
assert model.type == PageType.FRONT_COVER
|
||||||
assert model.double
|
assert model.double
|
||||||
assert model.image_size == 1024000
|
assert model.image_size == 1024000
|
||||||
assert model.key == "cover"
|
assert model.key == 'cover'
|
||||||
assert model.bookmark == "Chapter 1"
|
assert model.bookmark == 'Chapter 1'
|
||||||
assert model.image_width == 800
|
assert model.image_width == 800
|
||||||
assert model.image_height == 1200
|
assert model.image_height == 1200
|
||||||
|
|
||||||
def test_page_model_page_types(self):
|
def test_page_model_page_types(self) -> None:
|
||||||
"""Test different page types."""
|
"""Test different page types."""
|
||||||
page_types = [
|
page_types = [
|
||||||
PageType.FRONT_COVER,
|
PageType.FRONT_COVER,
|
||||||
@@ -237,7 +236,7 @@ class TestPageModel:
|
|||||||
model = PageModel(type=page_type)
|
model = PageModel(type=page_type)
|
||||||
assert model.type == page_type
|
assert model.type == page_type
|
||||||
|
|
||||||
def test_page_model_boolean_properties(self):
|
def test_page_model_boolean_properties(self) -> None:
|
||||||
"""Test boolean properties in PageModel."""
|
"""Test boolean properties in PageModel."""
|
||||||
model = PageModel()
|
model = PageModel()
|
||||||
|
|
||||||
@@ -248,22 +247,19 @@ class TestPageModel:
|
|||||||
model.double = False
|
model.double = False
|
||||||
assert not model.double
|
assert not model.double
|
||||||
|
|
||||||
def test_page_model_numeric_properties(self):
|
def test_page_model_numeric_properties(self) -> None:
|
||||||
"""Test numeric properties in PageModel."""
|
"""Test numeric properties in PageModel."""
|
||||||
model = PageModel(
|
model = PageModel(
|
||||||
image=5,
|
|
||||||
image_size=2048000,
|
image_size=2048000,
|
||||||
image_width=1920,
|
image_width=1920,
|
||||||
image_height=1080
|
image_height=1080
|
||||||
)
|
)
|
||||||
|
|
||||||
assert model.image == 5
|
|
||||||
assert model.image_size == 2048000
|
assert model.image_size == 2048000
|
||||||
assert model.image_width == 1920
|
assert model.image_width == 1920
|
||||||
assert model.image_height == 1080
|
assert model.image_height == 1080
|
||||||
|
|
||||||
# Test that they're integers
|
# Test that they're integers
|
||||||
assert isinstance(model.image, int)
|
|
||||||
assert isinstance(model.image_size, int)
|
assert isinstance(model.image_size, int)
|
||||||
assert isinstance(model.image_width, int)
|
assert isinstance(model.image_width, int)
|
||||||
assert isinstance(model.image_height, int)
|
assert isinstance(model.image_height, int)
|
||||||
+23
-19
@@ -1,11 +1,15 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from cbz.page import PageInfo
|
from cbz.page import PageInfo
|
||||||
from cbz.constants import PageType
|
from cbz.constants import PageType
|
||||||
|
|
||||||
|
|
||||||
class TestPageInfo:
|
class TestPageInfo:
|
||||||
"""Test cases for PageInfo class."""
|
"""Test cases for PageInfo class."""
|
||||||
|
|
||||||
def test_load_from_file(self, sample_image_path):
|
def test_load_from_file(self, sample_image_path: Path) -> None:
|
||||||
"""Test loading PageInfo from image file."""
|
"""Test loading PageInfo from image file."""
|
||||||
page = PageInfo.load(path=sample_image_path)
|
page = PageInfo.load(path=sample_image_path)
|
||||||
|
|
||||||
@@ -18,20 +22,20 @@ class TestPageInfo:
|
|||||||
assert page.image_size > 0
|
assert page.image_size > 0
|
||||||
assert page.suffix is not None
|
assert page.suffix is not None
|
||||||
|
|
||||||
def test_load_with_page_type(self, sample_image_path):
|
def test_load_with_page_type(self, sample_image_path: Path) -> None:
|
||||||
"""Test loading PageInfo with specific page type."""
|
"""Test loading PageInfo with specific page type."""
|
||||||
page = PageInfo.load(path=sample_image_path, type=PageType.FRONT_COVER)
|
page = PageInfo.load(path=sample_image_path, type=PageType.FRONT_COVER)
|
||||||
|
|
||||||
assert page.type == PageType.FRONT_COVER
|
assert page.type == PageType.FRONT_COVER
|
||||||
|
|
||||||
def test_load_with_custom_name(self, sample_image_path):
|
def test_load_with_custom_name(self, sample_image_path: Path) -> None:
|
||||||
"""Test loading PageInfo with custom name."""
|
"""Test loading PageInfo with custom name."""
|
||||||
custom_name = "custom_page.jpg"
|
custom_name = 'custom_page.jpg'
|
||||||
page = PageInfo.load(path=sample_image_path, name=custom_name)
|
page = PageInfo.load(path=sample_image_path, name=custom_name)
|
||||||
|
|
||||||
assert page.name == custom_name
|
assert page.name == custom_name
|
||||||
|
|
||||||
def test_page_content_property(self, sample_image_path):
|
def test_page_content_property(self, sample_image_path: Path) -> None:
|
||||||
"""Test page content property getter and setter."""
|
"""Test page content property getter and setter."""
|
||||||
page = PageInfo.load(path=sample_image_path)
|
page = PageInfo.load(path=sample_image_path)
|
||||||
original_content = page.content
|
original_content = page.content
|
||||||
@@ -45,7 +49,7 @@ class TestPageInfo:
|
|||||||
assert page.image_height > 0
|
assert page.image_height > 0
|
||||||
assert page.image_size > 0
|
assert page.image_size > 0
|
||||||
|
|
||||||
def test_image_metadata_extraction(self, sample_image_path):
|
def test_image_metadata_extraction(self, sample_image_path: Path) -> None:
|
||||||
"""Test that image metadata is correctly extracted."""
|
"""Test that image metadata is correctly extracted."""
|
||||||
page = PageInfo.load(path=sample_image_path)
|
page = PageInfo.load(path=sample_image_path)
|
||||||
|
|
||||||
@@ -60,12 +64,12 @@ class TestPageInfo:
|
|||||||
assert isinstance(page.image_height, int)
|
assert isinstance(page.image_height, int)
|
||||||
assert isinstance(page.image_size, int)
|
assert isinstance(page.image_size, int)
|
||||||
|
|
||||||
def test_multiple_image_formats(self, images_dir):
|
def test_multiple_image_formats(self, images_dir: Path) -> None:
|
||||||
"""Test loading different image formats."""
|
"""Test loading different image formats."""
|
||||||
image_files = list(images_dir.glob("*.jpg"))
|
image_files = list(images_dir.glob('*.jpg'))
|
||||||
|
|
||||||
if not image_files:
|
if not image_files:
|
||||||
pytest.skip("No image files found in example directory")
|
pytest.skip('No image files found in example directory')
|
||||||
|
|
||||||
for image_path in image_files[:3]: # Test first 3 images
|
for image_path in image_files[:3]: # Test first 3 images
|
||||||
page = PageInfo.load(path=image_path)
|
page = PageInfo.load(path=image_path)
|
||||||
@@ -77,7 +81,7 @@ class TestPageInfo:
|
|||||||
assert page.image_height > 0
|
assert page.image_height > 0
|
||||||
assert page.image_size > 0
|
assert page.image_size > 0
|
||||||
|
|
||||||
def test_page_type_assignment(self, sample_image_path):
|
def test_page_type_assignment(self, sample_image_path: Path) -> None:
|
||||||
"""Test different page type assignments."""
|
"""Test different page type assignments."""
|
||||||
page_types = [
|
page_types = [
|
||||||
PageType.FRONT_COVER,
|
PageType.FRONT_COVER,
|
||||||
@@ -97,40 +101,40 @@ class TestPageInfo:
|
|||||||
page = PageInfo.load(path=sample_image_path, type=page_type)
|
page = PageInfo.load(path=sample_image_path, type=page_type)
|
||||||
assert page.type == page_type
|
assert page.type == page_type
|
||||||
|
|
||||||
def test_page_creation_from_bytes(self, sample_image_path):
|
def test_page_creation_from_bytes(self, sample_image_path: Path) -> None:
|
||||||
"""Test creating PageInfo directly from bytes."""
|
"""Test creating PageInfo directly from bytes."""
|
||||||
# Read image file as bytes
|
# Read image file as bytes
|
||||||
with open(sample_image_path, 'rb') as f:
|
with open(sample_image_path, 'rb') as f:
|
||||||
image_bytes = f.read()
|
image_bytes = f.read()
|
||||||
|
|
||||||
# Create page from bytes
|
# Create page from bytes
|
||||||
page = PageInfo(content=image_bytes, name="test_page.jpg")
|
page = PageInfo(content=image_bytes, name='test_page.jpg')
|
||||||
|
|
||||||
assert page.content == image_bytes
|
assert page.content == image_bytes
|
||||||
assert page.name == "test_page.jpg"
|
assert page.name == 'test_page.jpg'
|
||||||
assert page.image_width > 0
|
assert page.image_width > 0
|
||||||
assert page.image_height > 0
|
assert page.image_height > 0
|
||||||
assert page.image_size > 0
|
assert page.image_size > 0
|
||||||
|
|
||||||
def test_repr_string(self, sample_image_path):
|
def test_repr_string(self, sample_image_path: Path) -> None:
|
||||||
"""Test string representation of PageInfo."""
|
"""Test string representation of PageInfo."""
|
||||||
page = PageInfo.load(path=sample_image_path, type=PageType.STORY)
|
page = PageInfo.load(path=sample_image_path, type=PageType.STORY)
|
||||||
|
|
||||||
repr_str = repr(page)
|
repr_str = repr(page)
|
||||||
assert "PageInfo" in repr_str
|
assert 'PageInfo' in repr_str
|
||||||
assert isinstance(repr_str, str)
|
assert isinstance(repr_str, str)
|
||||||
|
|
||||||
def test_page_bookmark_property(self, sample_image_path):
|
def test_page_bookmark_property(self, sample_image_path: Path) -> None:
|
||||||
"""Test page bookmark property."""
|
"""Test page bookmark property."""
|
||||||
# Test with bookmark
|
# Test with bookmark
|
||||||
page = PageInfo.load(path=sample_image_path, bookmark="Chapter 1")
|
page = PageInfo.load(path=sample_image_path, bookmark='Chapter 1')
|
||||||
assert page.bookmark == "Chapter 1"
|
assert page.bookmark == 'Chapter 1'
|
||||||
|
|
||||||
# Test without bookmark
|
# Test without bookmark
|
||||||
page_no_bookmark = PageInfo.load(path=sample_image_path)
|
page_no_bookmark = PageInfo.load(path=sample_image_path)
|
||||||
assert hasattr(page_no_bookmark, 'bookmark')
|
assert hasattr(page_no_bookmark, 'bookmark')
|
||||||
|
|
||||||
def test_page_double_page_property(self, sample_image_path):
|
def test_page_double_page_property(self, sample_image_path: Path) -> None:
|
||||||
"""Test page double_page property."""
|
"""Test page double_page property."""
|
||||||
page = PageInfo.load(path=sample_image_path, double=True)
|
page = PageInfo.load(path=sample_image_path, double=True)
|
||||||
assert page.double
|
assert page.double
|
||||||
|
|||||||
Reference in New Issue
Block a user