diff tests/test_nonpdf.py @ 1:1d09e1dec1d9 upstream

ADD: PyMuPDF v1.26.4: the original sdist. It does not yet contain MuPDF. This normally will be downloaded when building PyMuPDF.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:37:51 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_nonpdf.py	Mon Sep 15 11:37:51 2025 +0200
@@ -0,0 +1,35 @@
+"""
+* Check EPUB document is no PDF
+* Check page access using (chapter, page) notation
+* Re-layout EPUB ensuring a previous location is memorized
+"""
+import os
+
+import pymupdf
+
+scriptdir = os.path.abspath(os.path.dirname(__file__))
+filename = os.path.join(scriptdir, "resources", "Bezier.epub")
+doc = pymupdf.open(filename)
+
+
+def test_isnopdf():
+    assert not doc.is_pdf
+
+
+def test_pageids():
+    assert doc.chapter_count == 7
+    assert doc.last_location == (6, 1)
+    assert doc.prev_location((6, 0)) == (5, 11)
+    assert doc.next_location((5, 11)) == (6, 0)
+    # Check page numbers have no gaps:
+    i = 0
+    for chapter in range(doc.chapter_count):
+        for cpno in range(doc.chapter_page_count(chapter)):
+            assert doc.page_number_from_location((chapter, cpno)) == i
+            i += 1
+
+def test_layout():
+    """Memorize a page location, re-layout with ISO-A4, assert pre-determined location."""
+    loc = doc.make_bookmark((5, 11))
+    doc.layout(pymupdf.Rect(pymupdf.paper_rect("a4")))
+    assert doc.find_bookmark(loc) == (5, 6)