bump version

This commit is contained in:
hyugogirubato
2026-04-06 15:01:01 +02:00
parent 0ecf0f843b
commit 95472d4ac4
20 changed files with 2198 additions and 1461 deletions
+133 -194
View File
@@ -1,265 +1,204 @@
from cbz.models import BaseModel, ComicModel, PageModel
from cbz.constants import Format, YesNo, Manga, AgeRating, PageType
"""Tests for data models."""
from dataclasses import fields
class TestBaseModel:
"""Test cases for BaseModel class."""
import pytest
def test_base_model_creation(self) -> None:
"""Test creating BaseModel with fields."""
test_fields = {
'test_str': ('Test String', str),
'test_int': ('Test Integer', int),
'test_bool': ('Test Boolean', bool)
}
model = BaseModel(fields=test_fields)
# Check default values are set
assert hasattr(model, 'test_str')
assert hasattr(model, 'test_int')
assert hasattr(model, 'test_bool')
def test_base_model_with_kwargs(self) -> None:
"""Test creating BaseModel with keyword arguments."""
test_fields = {
'title': ('Title', str),
'number': ('Number', int),
'published': ('Published', bool)
}
model = BaseModel(
fields=test_fields,
title='Test Title',
number=42,
published=True
)
assert model.title == 'Test Title'
assert model.number == 42
assert model.published
def test_attribute_type_verification(self) -> None:
"""Test that attribute types are verified on assignment."""
test_fields = {
'count': ('Count', int),
'name': ('Name', str)
}
model = BaseModel(fields=test_fields)
# Valid assignments
model.count = 10
model.name = 'Test'
assert model.count == 10
assert model.name == 'Test'
def test_repr_method(self) -> None:
"""Test string representation of BaseModel."""
test_fields = {
'title': ('Title', str)
}
model = BaseModel(fields=test_fields, title='Test')
repr_str = repr(model)
assert isinstance(repr_str, str)
assert 'BaseModel' in repr_str
from cbz.constants import (
AgeRating,
Format,
LanguageISO,
Manga,
PageType,
Rating,
YesNo,
)
from cbz.models import ComicModel, PageModel, _get_xml_mapping
class TestComicModel:
"""Test cases for ComicModel class."""
"""Tests for the ComicModel dataclass."""
def test_comic_model_creation(self) -> None:
"""Test creating ComicModel with default values."""
def test_default_values(self) -> None:
"""Correct default values."""
model = ComicModel()
# Check that comic-specific attributes exist
assert hasattr(model, 'title')
assert hasattr(model, 'series')
assert hasattr(model, 'number')
assert hasattr(model, 'volume')
assert hasattr(model, 'year')
assert hasattr(model, 'month')
assert hasattr(model, 'day')
assert model.title == ""
assert model.series == ""
assert model.number is None
assert model.count is None
assert model.volume is None
assert model.year is None
assert model.format == Format.UNKNOWN
assert model.black_white == YesNo.UNKNOWN
assert model.manga == Manga.UNKNOWN
assert model.age_rating == AgeRating.UNKNOWN
assert model.community_rating is None
def test_comic_model_with_values(self) -> None:
"""Test creating ComicModel with specific values."""
def test_with_values(self) -> None:
"""Creation with specific values."""
model = ComicModel(
title='Test Comic',
series='Test Series',
title="Test Comic",
series="Test Series",
number=1,
volume=1,
year=2024,
month=6,
day=15,
writer='Test Writer',
publisher='Test Publisher',
language_iso='en',
writer="Test Writer",
publisher="Test Publisher",
language_iso=LanguageISO("en"),
format=Format.SERIES,
black_white=YesNo.NO,
manga=Manga.RIGHT_LEFT,
age_rating=AgeRating.EVERYONE
manga=Manga.YES_AND_RIGHT_TO_LEFT,
age_rating=AgeRating.EVERYONE,
)
assert model.title == 'Test Comic'
assert model.series == 'Test Series'
assert model.title == "Test Comic"
assert model.series == "Test Series"
assert model.number == 1
assert model.volume == 1
assert model.year == 2024
assert model.month == 6
assert model.day == 15
assert model.writer == 'Test Writer'
assert model.publisher == 'Test Publisher'
assert model.language_iso == 'en'
assert model.format == Format.SERIES
assert model.black_white == YesNo.NO
assert model.manga == Manga.RIGHT_LEFT
assert model.age_rating == AgeRating.EVERYONE
assert model.manga == Manga.YES_AND_RIGHT_TO_LEFT
def test_comic_model_enum_properties(self) -> None:
"""Test that enum properties work correctly."""
def test_enum_assignment(self) -> None:
"""Enum assignment."""
model = ComicModel()
# Test format enum
model.format = Format.PREVIEW
assert model.format == Format.PREVIEW
# Test yes/no enum
model.black_white = YesNo.YES
assert model.black_white == YesNo.YES
# Test manga enum
model.manga = Manga.RIGHT_LEFT
assert model.manga == Manga.RIGHT_LEFT
model.manga = Manga.YES_AND_RIGHT_TO_LEFT
assert model.manga == Manga.YES_AND_RIGHT_TO_LEFT
# Test age rating enum
model.age_rating = AgeRating.TEEN
assert model.age_rating == AgeRating.TEEN
def test_comic_model_metadata_fields(self) -> None:
"""Test comic metadata fields."""
def test_metadata_fields(self) -> None:
"""Verify metadata fields."""
model = ComicModel(
summary='Test summary',
notes='Test notes',
genre='Adventure',
web='http://example.com',
ean='1234567890123',
community_rating=5,
main_character_or_team='Hero',
characters='Hero, Villain',
teams='Justice League',
locations='Metropolis',
scan_information='Scanned by Test',
story_arc='Origin Story',
series_group='DC Comics',
alternate_series='Alternate Universe',
summary="Test summary",
notes="Test notes",
genre="Adventure",
web="http://example.com",
ean="1234567890123",
community_rating=Rating(5),
main_character_or_team="Hero",
characters="Hero, Villain",
teams="Justice League",
locations="Metropolis",
scan_information="Scanned by Test",
story_arc="Origin Story",
series_group="DC Comics",
alternate_series="Alternate Universe",
alternate_number=2,
alternate_count=10
alternate_count=10,
)
assert model.summary == 'Test summary'
assert model.notes == 'Test notes'
assert model.genre == 'Adventure'
assert model.web == 'http://example.com'
assert model.ean == '1234567890123'
assert model.summary == "Test summary"
assert model.genre == "Adventure"
assert model.community_rating == 5
assert model.main_character_or_team == 'Hero'
assert model.characters == 'Hero, Villain'
assert model.teams == 'Justice League'
assert model.locations == 'Metropolis'
assert model.scan_information == 'Scanned by Test'
assert model.story_arc == 'Origin Story'
assert model.series_group == 'DC Comics'
assert model.alternate_series == 'Alternate Universe'
assert model.characters == "Hero, Villain"
assert model.alternate_number == 2
assert model.alternate_count == 10
def test_xml_mapping(self) -> None:
"""Verify XML mapping."""
mapping = _get_xml_mapping(ComicModel)
assert "title" in mapping
assert mapping["title"][0] == "Title"
def test_all_fields_have_xml_mapping(self) -> None:
"""All annotated fields have an XML mapping."""
mapping = _get_xml_mapping(ComicModel)
for f in fields(ComicModel):
if "xml_name" in f.metadata:
assert f.name in mapping
class TestPageModel:
"""Test cases for PageModel class."""
"""Tests for the PageModel dataclass."""
def test_page_model_creation(self) -> None:
"""Test creating PageModel with default values."""
def test_default_values(self) -> None:
"""Correct default values."""
model = PageModel()
# Check that page-specific attributes exist
assert hasattr(model, 'image')
assert hasattr(model, 'type')
assert hasattr(model, 'double')
assert hasattr(model, 'image_size')
assert hasattr(model, 'key')
assert hasattr(model, 'bookmark')
assert hasattr(model, 'image_width')
assert hasattr(model, 'image_height')
assert hasattr(model, 'image_size')
# Note: format is not a base field in PageModel
assert model.type == PageType.STORY
assert model.double is False
assert model.image_size == 0
assert model.key == ""
assert model.bookmark == ""
assert model.image_width == 0
assert model.image_height == 0
def test_page_model_with_values(self) -> None:
"""Test creating PageModel with specific values."""
def test_with_values(self) -> None:
"""Creation with specific values."""
model = PageModel(
type=PageType.FRONT_COVER,
double=True,
image_size=1024000,
key='cover',
bookmark='Chapter 1',
key="cover",
bookmark="Chapter 1",
image_width=800,
image_height=1200,
)
assert model.type == PageType.FRONT_COVER
assert model.double
assert model.double is True
assert model.image_size == 1024000
assert model.key == 'cover'
assert model.bookmark == 'Chapter 1'
assert model.key == "cover"
assert model.bookmark == "Chapter 1"
assert model.image_width == 800
assert model.image_height == 1200
def test_page_model_page_types(self) -> None:
"""Test different page types."""
page_types = [
PageType.FRONT_COVER,
PageType.INNER_COVER,
PageType.ROUNDUP,
PageType.STORY,
PageType.ADVERTISEMENT,
PageType.EDITORIAL,
PageType.LETTERS,
PageType.PREVIEW,
PageType.BACK_COVER,
PageType.OTHER,
PageType.DELETED
]
for page_type in page_types:
def test_all_page_types(self) -> None:
"""All page types are valid."""
for page_type in PageType:
model = PageModel(type=page_type)
assert model.type == page_type
def test_page_model_boolean_properties(self) -> None:
"""Test boolean properties in PageModel."""
def test_boolean_properties(self) -> None:
"""Boolean double property."""
model = PageModel()
# Test double property
model.double = True
assert model.double
assert model.double is True
model.double = False
assert not model.double
assert model.double is False
def test_page_model_numeric_properties(self) -> None:
"""Test numeric properties in PageModel."""
model = PageModel(
image_size=2048000,
image_width=1920,
image_height=1080
)
assert model.image_size == 2048000
assert model.image_width == 1920
assert model.image_height == 1080
class TestRating:
"""Tests for the Rating type."""
# Test that they're integers
assert isinstance(model.image_size, int)
assert isinstance(model.image_width, int)
assert isinstance(model.image_height, int)
def test_valid_rating(self) -> None:
"""Valid ratings (0-5)."""
assert Rating(0) == 0.0
assert Rating(2.5) == 2.5
assert Rating(5) == 5.0
def test_invalid_rating(self) -> None:
"""Invalid ratings raise ValueError."""
with pytest.raises(ValueError):
Rating(-1)
with pytest.raises(ValueError):
Rating(6)
class TestLanguageISO:
"""Tests for the LanguageISO type."""
def test_valid_language(self) -> None:
"""Valid language codes."""
assert LanguageISO("en") == "en"
assert LanguageISO("fr") == "fr"
assert LanguageISO("ja") == "ja"
def test_empty_language(self) -> None:
"""Empty language code is allowed."""
assert LanguageISO("") == ""
def test_invalid_language(self) -> None:
"""Invalid language code raises ValueError."""
with pytest.raises(ValueError):
LanguageISO("zzzzzzz")