This commit is contained in:
parent
a0a26ef345
commit
9baafe85bf
@ -1,112 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""
|
|
||||||
Test the enhanced Page class with HTML loading capabilities
|
|
||||||
"""
|
|
||||||
|
|
||||||
from pyWebLayout.concrete.page import Page
|
|
||||||
from pyWebLayout.style.fonts import Font
|
|
||||||
from PIL import Image
|
|
||||||
import tempfile
|
|
||||||
import os
|
|
||||||
|
|
||||||
def test_page_html_loading():
|
|
||||||
"""Test basic Page creation and rendering without HTML loading"""
|
|
||||||
|
|
||||||
# Create a page - the current Page API doesn't support HTML loading
|
|
||||||
# This test verifies basic page functionality
|
|
||||||
page = Page(size=(800, 600))
|
|
||||||
|
|
||||||
# The Page class doesn't have HTML loading methods currently
|
|
||||||
# Instead, test basic page creation and rendering
|
|
||||||
try:
|
|
||||||
image = page.render()
|
|
||||||
print(f"✓ Successfully created and rendered empty page: {image.size}")
|
|
||||||
|
|
||||||
# Save the rendered image for inspection
|
|
||||||
output_path = "test_page_output.png"
|
|
||||||
image.save(output_path)
|
|
||||||
print(f"✓ Saved rendered page to: {output_path}")
|
|
||||||
|
|
||||||
assert image.size == (800, 600), f"Expected size (800, 600), got {image.size}"
|
|
||||||
return True
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"✗ Error rendering page: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def test_page_html_file_loading():
|
|
||||||
"""Test Page with manual content creation"""
|
|
||||||
|
|
||||||
# Since Page doesn't support HTML loading, test manual content creation
|
|
||||||
try:
|
|
||||||
# Create a page with different background color
|
|
||||||
page = Page(size=(400, 300), background_color=(240, 240, 240))
|
|
||||||
|
|
||||||
# Test that we can render a page with different parameters
|
|
||||||
image = page.render()
|
|
||||||
print(f"✓ Successfully created page with custom size and background: {image.size}")
|
|
||||||
|
|
||||||
# Save the rendered image
|
|
||||||
output_path = "test_custom_page_output.png"
|
|
||||||
image.save(output_path)
|
|
||||||
print(f"✓ Saved custom page to: {output_path}")
|
|
||||||
|
|
||||||
assert image.size == (400, 300), f"Expected size (400, 300), got {image.size}"
|
|
||||||
return True
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"✗ Error creating custom page: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def test_epub_reader_imports():
|
|
||||||
"""Test that the EPUB reader can be imported without errors"""
|
|
||||||
try:
|
|
||||||
from epub_reader_tk import EPUBReaderApp
|
|
||||||
print("✓ Successfully imported EPUBReaderApp")
|
|
||||||
|
|
||||||
# Test creating the app (but don't show it)
|
|
||||||
app = EPUBReaderApp()
|
|
||||||
print("✓ Successfully created EPUBReaderApp instance")
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"✗ Error importing/creating EPUB reader: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def main():
|
|
||||||
"""Run all tests"""
|
|
||||||
print("Testing enhanced Page class and EPUB reader...")
|
|
||||||
print("=" * 50)
|
|
||||||
|
|
||||||
tests = [
|
|
||||||
("HTML String Loading", test_page_html_loading),
|
|
||||||
("HTML File Loading", test_page_html_file_loading),
|
|
||||||
("EPUB Reader Imports", test_epub_reader_imports),
|
|
||||||
]
|
|
||||||
|
|
||||||
results = []
|
|
||||||
for test_name, test_func in tests:
|
|
||||||
print(f"\nTesting: {test_name}")
|
|
||||||
print("-" * 30)
|
|
||||||
success = test_func()
|
|
||||||
results.append((test_name, success))
|
|
||||||
|
|
||||||
# Summary
|
|
||||||
print("\n" + "=" * 50)
|
|
||||||
print("Test Summary:")
|
|
||||||
for test_name, success in results:
|
|
||||||
status = "PASS" if success else "FAIL"
|
|
||||||
print(f" {test_name}: {status}")
|
|
||||||
|
|
||||||
total_tests = len(results)
|
|
||||||
passed_tests = sum(1 for _, success in results if success)
|
|
||||||
print(f"\nPassed: {passed_tests}/{total_tests}")
|
|
||||||
|
|
||||||
if passed_tests == total_tests:
|
|
||||||
print("🎉 All tests passed!")
|
|
||||||
else:
|
|
||||||
print(f"⚠️ {total_tests - passed_tests} test(s) failed")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
Loading…
x
Reference in New Issue
Block a user