Skip to content

Commit 39a91b6

Browse files
committed
fixup! 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 bf709be commit 39a91b6

File tree

4 files changed

+11
-33
lines changed

4 files changed

+11
-33
lines changed

tests/test_clip_page.py

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

tests/test_font.py

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

tests/test_general.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +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, 27, 0):
67-
assert not wt
68-
elif pymupdf.mupdf_version_tuple >= (1, 26, 0):
69-
assert wt == 'bogus font ascent/descent values (0 / 0)'
70-
else:
71-
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)'
7267

7368

7469
def test_wrapcontents():
@@ -84,9 +79,7 @@ def test_wrapcontents():
8479
rebased = hasattr(pymupdf, 'mupdf')
8580
if rebased:
8681
wt = pymupdf.TOOLS.mupdf_warnings()
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):
82+
if (1, 26, 0) <= pymupdf.mupdf_version_tuple < (1, 27):
9083
assert wt == 'bogus font ascent/descent values (0 / 0)\nPDF stream Length incorrect'
9184
else:
9285
assert wt == 'PDF stream Length incorrect'
@@ -250,13 +243,8 @@ def test_get_text_dict():
250243
blocks=page.get_text("dict")["blocks"]
251244
# Check no opaque types in `blocks`.
252245
json.dumps( blocks, indent=4)
253-
wt = pymupdf.TOOLS.mupdf_warnings()
254-
if pymupdf.mupdf_version_tuple >= (1, 27, 0):
255-
assert not wt
256-
elif pymupdf.mupdf_version_tuple >= (1, 26, 0):
257-
assert wt == 'bogus font ascent/descent values (0 / 0)'
258-
else:
259-
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)'
260248

261249
def test_font():
262250
font = pymupdf.Font()

tests/test_pixmap.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +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, 27, 0):
204-
assert wt == 'PDF stream Length incorrect'
205-
elif pymupdf.mupdf_version_tuple >= (1, 26, 0):
203+
if (1, 26, 0) <= pymupdf.mupdf_version_tuple < (1, 27):
206204
assert wt == 'bogus font ascent/descent values (0 / 0)\nPDF stream Length incorrect'
207205
else:
208206
assert wt == 'PDF stream Length incorrect'
@@ -525,11 +523,8 @@ def test_4435():
525523
print(f'Calling page.get_pixmap().', flush=1)
526524
pixmap = page.get_pixmap(alpha=False, dpi=120)
527525
print(f'Called page.get_pixmap().', flush=1)
528-
wt = pymupdf.TOOLS.mupdf_warnings()
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...'
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...'
533528

534529

535530
def test_4423():

0 commit comments

Comments
 (0)