diff --git a/src/__init__.py b/src/__init__.py index df5f03c39..2bda40ff7 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -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 @@ -30,7 +31,6 @@ import zipfile from . import extra -import importlib.util # Set up g_out_log and g_out_message from environment variables. # @@ -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', '<>') @@ -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): @@ -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.""" @@ -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): diff --git a/tests/resources/test_4928.pdf b/tests/resources/test_4928.pdf new file mode 100644 index 000000000..d40b8c7a0 Binary files /dev/null and b/tests/resources/test_4928.pdf differ diff --git a/tests/test_general.py b/tests/test_general.py index 96d070f1b..b96e68eda 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -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}') + diff --git a/tests/test_memory.py b/tests/test_memory.py index 8da6de934..4d70d58fc 100644 --- a/tests/test_memory.py +++ b/tests/test_memory.py @@ -1,4 +1,5 @@ import pymupdf +import util import gc import os @@ -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 diff --git a/tests/test_pixmap.py b/tests/test_pixmap.py index bfbf3c565..921e7bcfe 100644 --- a/tests/test_pixmap.py +++ b/tests/test_pixmap.py @@ -18,6 +18,7 @@ import pytest import textwrap import time +import util scriptdir = os.path.abspath(os.path.dirname(__file__)) @@ -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) @@ -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: diff --git a/tests/test_typing.py b/tests/test_typing.py index 88f7dceee..d734ac8a0 100644 --- a/tests/test_typing.py +++ b/tests/test_typing.py @@ -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() diff --git a/tests/util.py b/tests/util.py index dbb246581..32785f673 100644 --- a/tests/util.py +++ b/tests/util.py @@ -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