Skip to content

Commit 3af046f

Browse files
committed
Adapt tests to fewer bogus font ascent/descent value warnings.
Since MuPDF commit 3d89b00ae59c6ed1f042d77e049a5668b32ca4ca "Only warn about non-zero bad ascender/descender font values" MuPDF no longer warns "bogus font ascent/descent values (0 / 0)". This commit will be part of the upcoming MuPDF 1.27.0, so this commit updates a few pymupdf tests to this new behaviour.
1 parent a31bac3 commit 3af046f

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

tests/test_clip_page.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def test_clip():
1818
page = doc[0]
1919
page.clip_to_rect(rect) # clip the page to the rectangle
2020
# capture font warning message of MuPDF
21-
assert pymupdf.TOOLS.mupdf_warnings() == "bogus font ascent/descent values (0 / 0)"
21+
if pymupdf.mupdf_version_tuple < (1, 27):
22+
assert pymupdf.TOOLS.mupdf_warnings() == "bogus font ascent/descent values (0 / 0)"
2223
# extract all text characters and assert that each one
2324
# has a non-empty intersection with the rectangle.
2425
chars = [

tests/test_font.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,5 @@ def test_4457():
337337
# Avoid test failure caused by mupdf warnings.
338338
wt = pymupdf.TOOLS.mupdf_warnings()
339339
print(f'{wt=}')
340-
assert wt == 'bogus font ascent/descent values (0 / 0)\n... repeated 5 times...'
340+
if pymupdf.mupdf_version_tuple < (1, 27):
341+
assert wt == 'bogus font ascent/descent values (0 / 0)\n... repeated 5 times...'

tests/test_general.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@ def test_iswrapped():
6262
doc = pymupdf.open(filename)
6363
page = doc[0]
6464
assert page.is_wrapped
65-
wt = pymupdf.TOOLS.mupdf_warnings()
66-
if pymupdf.mupdf_version_tuple >= (1, 26, 0):
67-
assert wt == 'bogus font ascent/descent values (0 / 0)'
68-
else:
69-
assert not wt
65+
if (1, 26, 0) <= pymupdf.mupdf_version_tuple < (1, 27):
66+
assert pymupdf.TOOLS.mupdf_warnings() == 'bogus font ascent/descent values (0 / 0)'
7067

7168

7269
def test_wrapcontents():
@@ -82,7 +79,7 @@ def test_wrapcontents():
8279
rebased = hasattr(pymupdf, 'mupdf')
8380
if rebased:
8481
wt = pymupdf.TOOLS.mupdf_warnings()
85-
if pymupdf.mupdf_version_tuple >= (1, 26, 0):
82+
if (1, 26, 0) <= pymupdf.mupdf_version_tuple < (1, 27):
8683
assert wt == 'bogus font ascent/descent values (0 / 0)\nPDF stream Length incorrect'
8784
else:
8885
assert wt == 'PDF stream Length incorrect'
@@ -246,11 +243,8 @@ def test_get_text_dict():
246243
blocks=page.get_text("dict")["blocks"]
247244
# Check no opaque types in `blocks`.
248245
json.dumps( blocks, indent=4)
249-
wt = pymupdf.TOOLS.mupdf_warnings()
250-
if pymupdf.mupdf_version_tuple >= (1, 26, 0):
251-
assert wt == 'bogus font ascent/descent values (0 / 0)'
252-
else:
253-
assert not wt
246+
if (1, 26, 0) <= pymupdf.mupdf_version_tuple < (1, 27):
247+
assert pymupdf.TOOLS.mupdf_warnings() == 'bogus font ascent/descent values (0 / 0)'
254248

255249
def test_font():
256250
font = pymupdf.Font()

tests/test_pixmap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def product(x, y):
200200
else:
201201
assert rms == 0
202202
wt = pymupdf.TOOLS.mupdf_warnings()
203-
if pymupdf.mupdf_version_tuple >= (1, 26, 0):
203+
if (1, 26, 0) <= pymupdf.mupdf_version_tuple < (1, 27):
204204
assert wt == 'bogus font ascent/descent values (0 / 0)\nPDF stream Length incorrect'
205205
else:
206206
assert wt == 'PDF stream Length incorrect'
@@ -523,8 +523,8 @@ def test_4435():
523523
print(f'Calling page.get_pixmap().', flush=1)
524524
pixmap = page.get_pixmap(alpha=False, dpi=120)
525525
print(f'Called page.get_pixmap().', flush=1)
526-
wt = pymupdf.TOOLS.mupdf_warnings()
527-
assert wt == 'bogus font ascent/descent values (0 / 0)\n... repeated 9 times...'
526+
if pymupdf.mupdf_version_tuple < (1, 27):
527+
assert pymupdf.TOOLS.mupdf_warnings() == 'bogus font ascent/descent values (0 / 0)\n... repeated 9 times...'
528528

529529

530530
def test_4423():

0 commit comments

Comments
 (0)