From 14db5c63b4d3a315d22fda7cc4cc235dfc3b1a27 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Tue, 18 Aug 2026 12:17:55 +0100 Subject: [PATCH] tests/: added test_5082(), test for hang in get_pixmap(). Also added and args to util.py:download(). --- tests/test_font.py | 2 +- tests/test_pixmap.py | 32 ++++++++++++++++++++++++++++++++ tests/util.py | 4 ++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/tests/test_font.py b/tests/test_font.py index 0e9f4665e..667e97a75 100644 --- a/tests/test_font.py +++ b/tests/test_font.py @@ -247,7 +247,7 @@ def test_4457(): ('https://github.com/user-attachments/files/20862922/test_4457_b.pdf', 'test_4457_b.pdf', None, 9), ) for url, name, size, rms_old_after_max in files: - path = util.download(url, name, size) + path = util.download(url, name, size=size) with pymupdf.open(path) as document: page = document[0] diff --git a/tests/test_pixmap.py b/tests/test_pixmap.py index dfab01a8e..11f2ef761 100644 --- a/tests/test_pixmap.py +++ b/tests/test_pixmap.py @@ -759,6 +759,7 @@ def test_natural(): pix=pymupdf.Pixmap(pm) print(f"{pix=}") + def text_pixmap_transpositions(): """Test that flip_rotate() is consistent with repeated applications.""" path = os.path.normpath(f'{__file__}/../../tests/resources/test_natural.pdf') @@ -777,3 +778,34 @@ def text_pixmap_transpositions(): for _ in range(repeat): new = new.flip_rotate(mode) assert new.samples == samples0, "Failed for mode %s" % mode + + +def test_5082(): + print() + path = util.download( + 'https://www.city.toyota.aichi.jp/_res/projects/default_project/_page_/001/057/466/01.pdf', + 'test_5082.pdf', + headers={'user-agent': 'pymupdf-test'}, # Avoids html 403 failure. + ) + print(f'test_5082(): {pymupdf.mupdf_version=}.') + print(f'test_5082(): calling page.get_pixmap() in child process.') + timeout = False + try: + cp = subprocess.run( + [ + sys.executable, + '-c', + f'import pymupdf; document=pymupdf.open({path!r}); page = document[0]; page.get_pixmap()', + ], + check=1, + timeout=10, + ) + except subprocess.TimeoutExpired: + timeout = True + print(f'test_5082(): {timeout=}') + # As of 2026-08-18 we expect timeout with 1.28.x (currently 1.28.3) and + # earlier. + if pymupdf.mupdf_version_tuple <= (1, 28, 3): + assert timeout, f'Expected timeout from {pymupdf.mupdf_version=}.' + else: + assert not timeout, f'Unexpected timeout from {pymupdf.mupdf_version=}.' diff --git a/tests/util.py b/tests/util.py index 32785f673..2a1e28f9a 100644 --- a/tests/util.py +++ b/tests/util.py @@ -2,7 +2,7 @@ import subprocess -def download(url, name, size=None): +def download(url, name, *, timeout=10, size=None, headers=None): ''' Downloads from to a local file and returns its path. @@ -18,7 +18,7 @@ def download(url, name, size=None): print(f'Downloading from {url=}.') subprocess.run(f'pip install -U requests', check=1, shell=1) import requests - r = requests.get(url, path, timeout=10) + r = requests.get(url, path, timeout=10, headers=headers) r.raise_for_status() if size is not None: assert len(r.content) == size