mirror of
https://github.com/hyugogirubato/cbz.git
synced 2026-09-26 13:31:00 +00:00
Merge pull request #22 from tssujt/single
Fix ComicInfo XML parsing for single page comic
This commit is contained in:
+1
-1
@@ -161,7 +161,7 @@ class ComicInfo(ComicModel):
|
||||
|
||||
if XML_NAME in names:
|
||||
with archive_file.open(XML_NAME, 'r') as f:
|
||||
comic_info = xmltodict.parse(f.read()).get('ComicInfo', {})
|
||||
comic_info = xmltodict.parse(f.read(), force_list=('Page',)).get('ComicInfo', {})
|
||||
names.remove(XML_NAME)
|
||||
|
||||
comic = ComicInfo.__extract_info(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
@@ -157,3 +158,22 @@ class TestComicInfo:
|
||||
|
||||
assert comic.title == 'Empty Test'
|
||||
assert len(comic.pages) == 0
|
||||
|
||||
def test_single_page_comic_load(self, images_dir):
|
||||
"""Test loading comic with a single page."""
|
||||
image_paths = sorted(list(images_dir.iterdir()))[:1]
|
||||
pages = [PageInfo.load(path=path) for path in image_paths]
|
||||
|
||||
comic = ComicInfo.from_pages(pages=pages, title="Single Page Test")
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
temp_path = Path(temp_dir) / "single_page.cbz"
|
||||
data = comic.pack()
|
||||
with open(temp_path, "wb") as f:
|
||||
f.write(data)
|
||||
|
||||
assert temp_path.exists()
|
||||
|
||||
comic_loaded = ComicInfo.from_cbz(temp_path)
|
||||
assert comic_loaded.title == "Single Page Test"
|
||||
assert len(comic_loaded.pages) == 1
|
||||
|
||||
Reference in New Issue
Block a user