Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import atexit
import binascii
import collections
import glob
import importlib.util
import inspect
import io
import math
import os
import pathlib
import glob
import re
import string
import sys
Expand All @@ -30,7 +31,6 @@
import zipfile

from . import extra
import importlib.util

# Set up g_out_log and g_out_message from environment variables.
#
Expand Down Expand Up @@ -586,6 +586,9 @@ class Annot:
def __init__(self, annot):
assert isinstance( annot, mupdf.PdfAnnot)
self.this = annot

def __bool__(self):
return bool(self.this)

def __repr__(self):
parent = getattr(self, 'parent', '<>')
Expand Down Expand Up @@ -10184,7 +10187,7 @@ def _load_annot(self, name, xref):
annot = JM_get_annot_by_name(page, name)
else:
annot = JM_get_annot_by_xref(page, xref)
if annot.m_internal:
if annot:
return Annot(annot)

def _makePixmap(self, doc, ctm, cs, alpha=0, annots=1, clip=None):
Expand Down Expand Up @@ -11383,6 +11386,9 @@ def extend_textpage(self, tpage, flags=0, matrix=None):
mupdf.fz_run_page( page, dev, ctm, mupdf.FzCookie())
mupdf.fz_close_device( dev)

def find_tables(self, **kwargs):
return table.find_tables(self, **kwargs)

@property
def first_annot(self):
"""First annotation."""
Expand Down Expand Up @@ -25571,8 +25577,7 @@ def _mupdf_devel(make_links=True):
recover_quad = utils.recover_quad
recover_span_quad = utils.recover_span_quad

from .table import find_tables
Page.find_tables = find_tables
from . import table


class FitzDeprecation(DeprecationWarning):
Expand Down
Binary file added tests/resources/test_4928.pdf
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -2212,3 +2212,12 @@ def test_4907():
print(f'{i=}')
display_list = page.get_displaylist(annots=False)
text_page = display_list.get_textpage()

def test_4928():
path = os.path.normpath(f'{__file__}/../../tests/resources/test_4928.pdf')
with pymupdf.open(path) as document:
try:
document.scrub()
except Exception as e:
print(f'Ignoring expected exception: {e}')

3 changes: 3 additions & 0 deletions tests/test_memory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pymupdf
import util

import gc
import os
Expand All @@ -17,6 +18,8 @@ def test_2791():
'''
Check for memory leaks.
'''
if util.skip_slow_tests('test_2791'):
return
if os.environ.get('PYODIDE_ROOT'):
print('test_2791(): not running on Pyodide - No module named \'psutil\'.')
return
Expand Down
6 changes: 6 additions & 0 deletions tests/test_pixmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import pytest
import textwrap
import time
import util


scriptdir = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -371,6 +372,8 @@ def do(gi):


def test_3848():
if util.skip_slow_tests('test_3848'):
return
if os.environ.get('PYMUPDF_RUNNING_ON_VALGRIND') == '1':
# Takes 40m on Github.
print(f'test_3848(): not running on valgrind because very slow.', flush=1)
Expand Down Expand Up @@ -509,6 +512,9 @@ def test_4336():


def test_4435():
# This is slow, e.g. 224s.
if util.skip_slow_tests('test_4435'):
return
print(f'{pymupdf.version=}')
path = os.path.normpath(f'{__file__}/../../tests/resources/test_4435.pdf')
with pymupdf.open(path) as document:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ def test_py_typed():

def _test_4903(page: pymupdf.Page) -> float: # In 1.27.1, error: Variable "pymupdf.Page" is not valid as a type
return page.rect.width # In 1.27.1, error: pymupdf.Page? has no attribute "rect"

def _test_4932(page: pymupdf.Page):
page.find_tables()
6 changes: 6 additions & 0 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ def download(url, name, size=None):
with open(path, 'wb') as f:
f.write(r.content)
return path

def skip_slow_tests(test_name):
PYMUPDF_TEST_QUICK = os.environ.get('PYMUPDF_TEST_QUICK')
if PYMUPDF_TEST_QUICK == '1':
print(f'{test_name}(): skipping test because {PYMUPDF_TEST_QUICK=}.')
return True
Loading