pyWebLayout/pyWebLayout/examples/simple_epub_test.py
Duncan Tourolle c0c366e9f4
Some checks failed
Python CI / test (push) Failing after 1m35s
Additional changes.
2025-06-06 20:54:33 +02:00

87 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""
Simple EPUB test script to isolate the issue.
"""
import sys
from pathlib import Path
# Add the parent directory to the path to import pyWebLayout
sys.path.append(str(Path(__file__).parent.parent.parent))
def test_epub_basic():
"""Test basic EPUB functionality without full HTML parsing."""
print("Testing basic EPUB components...")
try:
# Test basic document classes
from pyWebLayout.abstract.document import Document, Book, Chapter, MetadataType
print("✓ Document classes imported")
# Test creating a simple book
book = Book("Test Book", "Test Author")
chapter = book.create_chapter("Test Chapter")
print("✓ Book and chapter created")
return True
except Exception as e:
print(f"✗ Basic test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_epub_file():
"""Test opening the EPUB file without full parsing."""
print("Testing EPUB file access...")
try:
import zipfile
import os
epub_path = "pg174-images-3.epub"
if not os.path.exists(epub_path):
print(f"✗ EPUB file not found: {epub_path}")
return False
with zipfile.ZipFile(epub_path, 'r') as zip_ref:
file_list = zip_ref.namelist()
print(f"✓ EPUB file opened, contains {len(file_list)} files")
# Look for key files
has_container = any('container.xml' in f for f in file_list)
has_opf = any('.opf' in f for f in file_list)
print(f"✓ Container file: {'found' if has_container else 'not found'}")
print(f"✓ Package file: {'found' if has_opf else 'not found'}")
return True
except Exception as e:
print(f"✗ EPUB file test failed: {e}")
import traceback
traceback.print_exc()
return False
def main():
print("Simple EPUB Test")
print("=" * 50)
# Test basic functionality
if not test_epub_basic():
return False
print()
# Test EPUB file access
if not test_epub_file():
return False
print()
print("All basic tests passed!")
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)