Skip to content

Commit bf709be

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 bf709be

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

tests/test_clip_page.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ 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+
wt = pymupdf.TOOLS.mupdf_warnings()
22+
if pymupdf.mupdf_version_tuple >= (1, 27, 0):
23+
assert not wt
24+
else:
25+
assert wt == "bogus font ascent/descent values (0 / 0)"
2226
# extract all text characters and assert that each one
2327
# has a non-empty intersection with the rectangle.
2428
chars = [

tests/test_font.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,7 @@ 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, 0):
341+
assert not wt
342+
else:
343+
assert wt == 'bogus font ascent/descent values (0 / 0)\n... repeated 5 times...'

tests/test_general.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def test_iswrapped():
6363
page = doc[0]
6464
assert page.is_wrapped
6565
wt = pymupdf.TOOLS.mupdf_warnings()
66-
if pymupdf.mupdf_version_tuple >= (1, 26, 0):
66+
if pymupdf.mupdf_version_tuple >= (1, 27, 0):
67+
assert not wt
68+
elif pymupdf.mupdf_version_tuple >= (1, 26, 0):
6769
assert wt == 'bogus font ascent/descent values (0 / 0)'
6870
else:
6971
assert not wt
@@ -82,7 +84,9 @@ def test_wrapcontents():
8284
rebased = hasattr(pymupdf, 'mupdf')
8385
if rebased:
8486
wt = pymupdf.TOOLS.mupdf_warnings()
85-
if pymupdf.mupdf_version_tuple >= (1, 26, 0):
87+
if pymupdf.mupdf_version_tuple >= (1, 27, 0):
88+
assert wt == 'PDF stream Length incorrect'
89+
elif pymupdf.mupdf_version_tuple >= (1, 26, 0):
8690
assert wt == 'bogus font ascent/descent values (0 / 0)\nPDF stream Length incorrect'
8791
else:
8892
assert wt == 'PDF stream Length incorrect'
@@ -247,7 +251,9 @@ def test_get_text_dict():
247251
# Check no opaque types in `blocks`.
248252
json.dumps( blocks, indent=4)
249253
wt = pymupdf.TOOLS.mupdf_warnings()
250-
if pymupdf.mupdf_version_tuple >= (1, 26, 0):
254+
if pymupdf.mupdf_version_tuple >= (1, 27, 0):
255+
assert not wt
256+
elif pymupdf.mupdf_version_tuple >= (1, 26, 0):
251257
assert wt == 'bogus font ascent/descent values (0 / 0)'
252258
else:
253259
assert not wt

tests/test_pixmap.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ 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 pymupdf.mupdf_version_tuple >= (1, 27, 0):
204+
assert wt == 'PDF stream Length incorrect'
205+
elif pymupdf.mupdf_version_tuple >= (1, 26, 0):
204206
assert wt == 'bogus font ascent/descent values (0 / 0)\nPDF stream Length incorrect'
205207
else:
206208
assert wt == 'PDF stream Length incorrect'
@@ -524,7 +526,10 @@ def test_4435():
524526
pixmap = page.get_pixmap(alpha=False, dpi=120)
525527
print(f'Called page.get_pixmap().', flush=1)
526528
wt = pymupdf.TOOLS.mupdf_warnings()
527-
assert wt == 'bogus font ascent/descent values (0 / 0)\n... repeated 9 times...'
529+
if pymupdf.mupdf_version_tuple >= (1, 27, 0):
530+
assert not wt
531+
else:
532+
assert wt == 'bogus font ascent/descent values (0 / 0)\n... repeated 9 times...'
528533

529534

530535
def test_4423():

0 commit comments

Comments
 (0)