Mercurial > hgrepos > Python2 > PyMuPDF
comparison tests/test_2548.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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 1:1d09e1dec1d9 |
|---|---|
| 1 import os | |
| 2 | |
| 3 import pymupdf | |
| 4 | |
| 5 root = os.path.abspath(f'{__file__}/../..') | |
| 6 | |
| 7 def test_2548(): | |
| 8 """Text extraction should fail because of PDF structure cycle. | |
| 9 | |
| 10 Old MuPDF version did not detect the loop. | |
| 11 """ | |
| 12 print(f'test_2548(): {pymupdf.mupdf_version_tuple=}') | |
| 13 pymupdf.TOOLS.mupdf_warnings(reset=True) | |
| 14 doc = pymupdf.open(f'{root}/tests/resources/test_2548.pdf') | |
| 15 e = False | |
| 16 for page in doc: | |
| 17 try: | |
| 18 _ = page.get_text() | |
| 19 except Exception as ee: | |
| 20 print(f'test_2548: {ee=}') | |
| 21 if hasattr(pymupdf, 'mupdf'): | |
| 22 # Rebased. | |
| 23 expected = "RuntimeError('code=2: cycle in structure tree')" | |
| 24 else: | |
| 25 # Classic. | |
| 26 expected = "RuntimeError('cycle in structure tree')" | |
| 27 assert repr(ee) == expected, f'Expected {expected=} but got {repr(ee)=}.' | |
| 28 e = True | |
| 29 wt = pymupdf.TOOLS.mupdf_warnings() | |
| 30 print(f'test_2548(): {wt=}') | |
| 31 | |
| 32 # This checks that PyMuPDF 1.23.7 fixes this bug, and also that earlier | |
| 33 # versions with updated MuPDF also fix the bug. | |
| 34 rebased = hasattr(pymupdf, 'mupdf') | |
| 35 if pymupdf.mupdf_version_tuple >= (1, 27): | |
| 36 expected = 'format error: No common ancestor in structure tree\nstructure tree broken, assume tree is missing' | |
| 37 expected = '\n'.join([expected] * 5) | |
| 38 else: | |
| 39 expected = 'format error: cycle in structure tree\nstructure tree broken, assume tree is missing' | |
| 40 if rebased: | |
| 41 assert wt == expected, f'expected:\n {expected!r}\nwt:\n {wt!r}\n' | |
| 42 assert not e |
