File: test_2904.py

package info (click to toggle)
pymupdf 1.25.4%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 98,632 kB
  • sloc: python: 43,379; ansic: 75; makefile: 6
file content (40 lines) | stat: -rw-r--r-- 1,491 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import pymupdf

import os
import sys

def test_2904():
    print(f'test_2904(): {pymupdf.mupdf_version_tuple=}.')
    path = os.path.abspath(f'{__file__}/../../tests/resources/test_2904.pdf')
    pdf_docs = pymupdf.open(path)
    for page_id, page in enumerate(pdf_docs):
        page_imgs = page.get_images()
        for i, img in enumerate(page_imgs):
            if page_id == 5:
                #print(f'{page_id=} {i=} {type(img)=} {img=}')
                sys.stdout.flush()
            e = None
            try:
                recs = page.get_image_rects(img, transform=True)
            except Exception as ee:
                print(f'Exception: {page_id=} {i=} {img=}: {ee}')
                if 0 and hasattr(pymupdf, 'mupdf'):
                    print(f'pymupdf.exception_info:')
                    pymupdf.exception_info()
                    sys.stdout.flush()
                e = ee
            if page_id == 5:
                print(f'{pymupdf.mupdf_version_tuple=}: {page_id=} {i=} {e=} {img=}:')
            if page_id == 5 and i==3:
                assert e
                if hasattr(pymupdf, 'mupdf'):
                    # rebased.
                    assert str(e) == 'code=8: Failed to read JPX header'
                else:
                    # classic
                    assert str(e) == 'Failed to read JPX header'
            else:
                assert not e
    
    # Clear warnings, as we will have generated many.
    pymupdf.TOOLS.mupdf_warnings()