Skip to content

Commit cb860db

Browse files
tests/: removed support for mupdf < 1.26.
1 parent 20a69cf commit cb860db

9 files changed

Lines changed: 50 additions & 145 deletions

tests/test_annots.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,13 @@ def test_2270():
308308
print(f'{text=}')
309309
print(f'{getattr(textpage, "parent")=}')
310310

311-
if pymupdf.mupdf_version_tuple >= (1, 26):
312-
# Check Annotation.get_textpage()'s <clip> arg.
313-
clip = textBox.rect
314-
clip.x1 = clip.x0 + (clip.x1 - clip.x0) / 3
315-
textpage2 = textBox.get_textpage(clip=clip)
316-
text = textpage2.extractText()
317-
print(f'With {clip=}: {text=}')
318-
assert text == 'ab\n'
319-
else:
320-
assert not hasattr(pymupdf.mupdf, 'FZ_STEXT_CLIP_RECT')
311+
# Check Annotation.get_textpage()'s <clip> arg.
312+
clip = textBox.rect
313+
clip.x1 = clip.x0 + (clip.x1 - clip.x0) / 3
314+
textpage2 = textBox.get_textpage(clip=clip)
315+
text = textpage2.extractText()
316+
print(f'With {clip=}: {text=}')
317+
assert text == 'ab\n'
321318

322319

323320
def test_2934_add_redact_annot():
@@ -492,11 +489,7 @@ def test_4047():
492489

493490
def test_4079():
494491
path = os.path.normpath(f'{__file__}/../../tests/resources/test_4079.pdf')
495-
if pymupdf.mupdf_version_tuple >= (1, 25, 5):
496-
path_after = os.path.normpath(f'{__file__}/../../tests/resources/test_4079_after.pdf')
497-
else:
498-
# 2024-11-27 Expect incorrect behaviour.
499-
path_after = os.path.normpath(f'{__file__}/../../tests/resources/test_4079_after_1.25.pdf')
492+
path_after = os.path.normpath(f'{__file__}/../../tests/resources/test_4079_after.pdf')
500493

501494
path_out = os.path.normpath(f'{__file__}/../../tests/test_4079_out')
502495
with pymupdf.open(path_after) as document_after:

tests/test_barcode.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55

66
def test_barcode():
7-
if pymupdf.mupdf_version_tuple < (1, 26):
8-
print(f'Not testing barcode because {pymupdf.mupdf_version=} < 1.26')
9-
return
107
path = os.path.normpath(f'{__file__}/../../tests/test_barcode_out.pdf')
118

129
url = 'http://artifex.com'

tests/test_general.py

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -399,24 +399,17 @@ def test_2108():
399399
print(f'')
400400

401401
print(f'{pymupdf.mupdf_version_tuple=}')
402-
if pymupdf.mupdf_version_tuple >= (1, 21, 2):
403-
print('Asserting text==text_expected')
404-
assert text == text_expected
405-
else:
406-
print('Asserting text!=text_expected')
407-
assert text != text_expected
402+
print('Asserting text==text_expected')
403+
assert text == text_expected
408404

409405

410406
def test_2238():
411407
filepath = f'{scriptdir}/resources/test2238.pdf'
412408
doc = pymupdf.open(filepath)
413409
wt = pymupdf.TOOLS.mupdf_warnings()
414410
wt_expected = ''
415-
if pymupdf.mupdf_version_tuple >= (1, 26):
416-
wt_expected += 'garbage bytes before version marker\n'
417-
wt_expected += 'syntax error: expected \'obj\' keyword (6 0 ?)\n'
418-
else:
419-
wt_expected += 'format error: cannot recognize version marker\n'
411+
wt_expected += 'garbage bytes before version marker\n'
412+
wt_expected += 'syntax error: expected \'obj\' keyword (6 0 ?)\n'
420413
wt_expected += 'trying to repair broken xref\n'
421414
wt_expected += 'repairing PDF document'
422415
assert wt == wt_expected, f'{wt=}'
@@ -1606,18 +1599,17 @@ def dict_set_path(dict_, *items):
16061599
with open(path_out, 'w') as f:
16071600
json.dump(results, f, indent=4, sort_keys=1)
16081601

1609-
if pymupdf.mupdf_version_tuple >= (1, 26):
1610-
with open(os.path.normpath(f'{__file__}/../../tests/resources/test_open2_expected.json')) as f:
1611-
results_expected = json.load(f)
1612-
if results != results_expected:
1613-
print(f'results != results_expected:')
1614-
def show(r, name):
1615-
text = json.dumps(r, indent=4, sort_keys=1)
1616-
print(f'{name}:')
1617-
print(textwrap.indent(text, ' '))
1618-
show(results_expected, 'results_expected')
1619-
show(results, 'results')
1620-
assert 0
1602+
with open(os.path.normpath(f'{__file__}/../../tests/resources/test_open2_expected.json')) as f:
1603+
results_expected = json.load(f)
1604+
if results != results_expected:
1605+
print(f'results != results_expected:')
1606+
def show(r, name):
1607+
text = json.dumps(r, indent=4, sort_keys=1)
1608+
print(f'{name}:')
1609+
print(textwrap.indent(text, ' '))
1610+
show(results_expected, 'results_expected')
1611+
show(results, 'results')
1612+
assert 0
16211613

16221614

16231615
def test_533():
@@ -1773,10 +1765,7 @@ def test_3905():
17731765
else:
17741766
assert 0
17751767
wt = pymupdf.TOOLS.mupdf_warnings()
1776-
if pymupdf.mupdf_version_tuple >= (1, 26):
1777-
assert wt == 'format error: cannot find version marker\ntrying to repair broken xref\nrepairing PDF document'
1778-
else:
1779-
assert wt == 'format error: cannot recognize version marker\ntrying to repair broken xref\nrepairing PDF document'
1768+
assert wt == 'format error: cannot find version marker\ntrying to repair broken xref\nrepairing PDF document'
17801769

17811770
def test_3624():
17821771
path = os.path.normpath(f'{__file__}/../../tests/resources/test_3624.pdf')
@@ -1822,10 +1811,7 @@ def test_4034():
18221811
pixmap2 = document[0].get_pixmap()
18231812
rms = gentle_compare.pixmaps_rms(pixmap1, pixmap2)
18241813
print(f'test_4034(): Comparison of original/cleaned page 0 pixmaps: {rms=}.')
1825-
if pymupdf.mupdf_version_tuple < (1, 25, 2):
1826-
assert 30 < rms < 50
1827-
else:
1828-
assert rms == 0
1814+
assert rms == 0
18291815

18301816
def test_4309():
18311817
document = pymupdf.open()
@@ -1842,11 +1828,8 @@ def test_4263():
18421828
command = f'pymupdf clean -linear {path} {path_out}'
18431829
print(f'Running: {command}')
18441830
cp = subprocess.run(command, shell=1, check=0)
1845-
if pymupdf.mupdf_version_tuple < (1, 26):
1846-
assert cp.returncode == 0
1847-
else:
1848-
# Support for linerarisation dropped in MuPDF-1.26.
1849-
assert cp.returncode
1831+
# Support for linerarisation dropped in MuPDF-1.26.
1832+
assert cp.returncode
18501833

18511834
def test_4224():
18521835
path = os.path.normpath(f'{__file__}/../../tests/resources/test_4224.pdf')
@@ -1856,9 +1839,6 @@ def test_4224():
18561839
path_pixmap = f'{path}.{page.number}.png'
18571840
pixmap.save(path_pixmap)
18581841
print(f'Have created: {path_pixmap}')
1859-
if pymupdf.mupdf_version_tuple < (1, 25, 5):
1860-
wt = pymupdf.TOOLS.mupdf_warnings()
1861-
assert wt == 'format error: negative code in 1d faxd\npadding truncated image'
18621842

18631843
def test_4319():
18641844
# Have not seen this test reproduce issue #4319, but keeping it anyway.

tests/test_memory.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ def get_stat():
225225
if pv < (3, 11):
226226
# Python < 3.11 has less reliable memory usage so we exclude.
227227
print(f'test_4125(): Not checking on {platform.python_version()=} because < 3.11.')
228-
elif pymupdf.mupdf_version_tuple < (1, 25, 2):
229-
rss_delta_expected = 4915200 * (len(state.rsss) - 3)
230-
assert abs(1 - rss_delta / rss_delta_expected) < 0.15, f'{rss_delta_expected=}'
231228
else:
232229
# Before the fix, each iteration would leak 4.9MB.
233230
rss_delta_max = 100*1000 * (len(state.rsss) - 3)

tests/test_mupdf_regressions.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ def test_707727():
5050
print(f'{rms=}', flush=1)
5151
pix0.save(os.path.normpath(f'{__file__}/../../tests/test_707727_pix0.png'))
5252
pix1.save(os.path.normpath(f'{__file__}/../../tests/test_707727_pix1.png'))
53-
if pymupdf.mupdf_version_tuple >= (1, 25, 2):
54-
# New sanitising gives small fp rounding errors.
55-
assert rms < 0.05
56-
else:
57-
assert rms == 0
53+
# New sanitising gives small fp rounding errors.
54+
assert rms < 0.05
5855

5956

6057
def test_707721():

tests/test_pixmap.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,7 @@ def product(x, y):
195195
path_expected = os.path.normpath(f'{__file__}/../../tests/resources/test_3050_expected.png')
196196
rms = gentle_compare.pixmaps_rms(path_expected, path_out2)
197197
print(f'{rms=}')
198-
if pymupdf.mupdf_version_tuple < (1, 26):
199-
# Slight differences in rendering from fix for mupdf bug 708274.
200-
assert rms < 0.2
201-
else:
202-
assert rms == 0
198+
assert rms == 0
203199
wt = pymupdf.TOOLS.mupdf_warnings()
204200
if (1, 26, 0) <= pymupdf.mupdf_version_tuple < (1, 27):
205201
assert wt == 'bogus font ascent/descent values (0 / 0)\nPDF stream Length incorrect'
@@ -416,11 +412,7 @@ def test_3448():
416412
path_diff = os.path.normpath(f'{__file__}/../../tests/test_3448-diff.png')
417413
diff.save(path_diff)
418414
print(f'{rms=}')
419-
if pymupdf.mupdf_version_tuple < (1, 25, 5):
420-
# Prior to fix for mupdf bug 708274.
421-
assert 1 < rms < 2
422-
else:
423-
assert rms == 0
415+
assert rms == 0
424416

425417

426418
def test_3854():
@@ -442,9 +434,6 @@ def test_3854():
442434
# MuPDF using external third-party libs gives slightly different
443435
# behaviour.
444436
assert rms < 2
445-
elif pymupdf.mupdf_version_tuple < (1, 25, 5):
446-
# # Prior to fix for mupdf bug 708274.
447-
assert 0.5 < rms < 2
448437
else:
449438
assert rms == 0
450439

@@ -558,14 +547,9 @@ def test_4423():
558547
print(f'Exception: {e}')
559548
ee = e
560549

561-
if (1, 25, 5) <= pymupdf.mupdf_version_tuple < (1, 26):
562-
assert ee, f'Did not receive the expected exception.'
563-
wt = pymupdf.TOOLS.mupdf_warnings()
564-
assert wt == 'dropping unclosed output'
565-
else:
566-
assert not ee, f'Received unexpected exception: {e}'
567-
wt = pymupdf.TOOLS.mupdf_warnings()
568-
assert wt == 'format error: cannot find object in xref (56 0 R)\nformat error: cannot find object in xref (68 0 R)'
550+
assert not ee, f'Received unexpected exception: {e}'
551+
wt = pymupdf.TOOLS.mupdf_warnings()
552+
assert wt == 'format error: cannot find object in xref (56 0 R)\nformat error: cannot find object in xref (68 0 R)'
569553

570554

571555
def test_4445():
@@ -587,10 +571,7 @@ def test_4445():
587571
pixmap = page.get_pixmap()
588572
print(f'{pixmap.width=}')
589573
print(f'{pixmap.height=}')
590-
if pymupdf.mupdf_version_tuple >= (1, 26):
591-
assert (pixmap.width, pixmap.height) == (792, 612)
592-
else:
593-
assert (pixmap.width, pixmap.height) == (612, 792)
574+
assert (pixmap.width, pixmap.height) == (792, 612)
594575
if 0:
595576
path_pixmap = f'{path}.png'
596577
pixmap.save(path_pixmap)

tests/test_tables.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,10 @@ def test_2979():
184184
), f"{pymupdf.TOOLS.set_small_glyph_heights()=}"
185185

186186
wt = pymupdf.TOOLS.mupdf_warnings()
187-
if pymupdf.mupdf_version_tuple >= (1, 26, 0):
188-
assert (
189-
wt
190-
== "bogus font ascent/descent values (3117 / -2463)\n... repeated 2 times..."
191-
)
192-
else:
193-
assert not wt
187+
assert (
188+
wt
189+
== "bogus font ascent/descent values (3117 / -2463)\n... repeated 2 times..."
190+
)
194191

195192

196193
def test_3062():

tests/test_tesseract.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ def test_tesseract():
1818
path = os.path.abspath( f'{__file__}/../resources/2.pdf')
1919
doc = pymupdf.open( path)
2020
page = doc[5]
21-
if pymupdf.mupdf_version_tuple < (1, 25, 4):
22-
tail = 'OCR initialisation failed'
23-
else:
24-
tail = 'Tesseract language initialisation failed'
21+
tail = 'Tesseract language initialisation failed'
2522
if os.environ.get('PYODIDE_ROOT'):
2623
e_expected = 'code=6: No OCR support in this build'
2724
e_expected_type = pymupdf.mupdf.FzErrorUnsupported
@@ -52,14 +49,6 @@ def test_tesseract():
5249
assert type(e) == e_expected_type, f'{type(e)=} != {e_expected_type=}.'
5350
else:
5451
assert 0, f'Expected exception {e_expected!r}'
55-
wt = pymupdf.TOOLS.mupdf_warnings()
56-
if pymupdf.mupdf_version_tuple < (1, 25, 4):
57-
assert wt == (
58-
'UNHANDLED EXCEPTION!\n'
59-
'library error: Tesseract initialisation failed'
60-
)
61-
else:
62-
assert not wt
6352

6453

6554
def test_3842b():
@@ -81,13 +70,7 @@ def test_3842b():
8170
if 'No tessdata specified and Tesseract is not installed' in str(e):
8271
pass
8372
else:
84-
if pymupdf.mupdf_version_tuple < (1, 25, 4):
85-
assert 'OCR initialisation failed' in str(e)
86-
wt = pymupdf.TOOLS.mupdf_warnings()
87-
assert wt == 'UNHANDLED EXCEPTION!\nlibrary error: Tesseract initialisation failed\nUNHANDLED EXCEPTION!\nlibrary error: Tesseract initialisation failed', \
88-
f'Unexpected {wt=}'
89-
else:
90-
assert 'Tesseract language initialisation failed' in str(e)
73+
assert 'Tesseract language initialisation failed' in str(e)
9174

9275

9376
def test_3842():

tests/test_textextract.py

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -446,16 +446,12 @@ def test_4147():
446446
#print(f' line')
447447
for span in line['spans']:
448448
#print(f' span')
449-
if pymupdf.mupdf_version_tuple >= (1, 25, 2):
450-
#print(f' span: {span["flags"]=:#x} {span["char_flags"]=:#x}')
451-
if expect_visible:
452-
assert span['char_flags'] & pymupdf.mupdf.FZ_STEXT_FILLED
453-
else:
454-
assert not (span['char_flags'] & pymupdf.mupdf.FZ_STEXT_FILLED)
455-
assert not (span['char_flags'] & pymupdf.mupdf.FZ_STEXT_STROKED)
449+
#print(f' span: {span["flags"]=:#x} {span["char_flags"]=:#x}')
450+
if expect_visible:
451+
assert span['char_flags'] & pymupdf.mupdf.FZ_STEXT_FILLED
456452
else:
457-
#print(f' span: {span["flags"]=:#x}')
458-
assert 'char_flags' not in span
453+
assert not (span['char_flags'] & pymupdf.mupdf.FZ_STEXT_FILLED)
454+
assert not (span['char_flags'] & pymupdf.mupdf.FZ_STEXT_STROKED)
459455
# Check commit `add 'bidi' to span dict, add 'synthetic' to char dict.`
460456
assert span['bidi'] == 0
461457
for ch in span['chars']:
@@ -507,11 +503,7 @@ def test_4245():
507503
path_diff = os.path.normpath(f'{__file__}/../../tests/resources/test_4245_diff.png')
508504
pixmap_diff.save(path_diff)
509505
print(f'{rms=}')
510-
if pymupdf.mupdf_version_tuple < (1, 25, 5):
511-
# Prior to fix for mupdf bug 708274.
512-
assert 0.1 < rms < 0.2
513-
else:
514-
assert rms < 0.01
506+
assert rms < 0.01
515507

516508

517509
def test_4180():
@@ -532,11 +524,7 @@ def test_4180():
532524
path_diff = os.path.normpath(f'{__file__}/../../tests/resources/test_4180_diff.png')
533525
pixmap_diff.save(path_diff)
534526
print(f'{rms=}')
535-
if pymupdf.mupdf_version_tuple < (1, 25, 5):
536-
# Prior to fix for mupdf bug 708274.
537-
assert 0.2 < rms < 0.3
538-
else:
539-
assert rms < 0.01
527+
assert rms < 0.01
540528

541529

542530
def test_4182():
@@ -566,11 +554,7 @@ def test_4182():
566554
pixmap_diff.save(path_diff)
567555
rms = gentle_compare.pixmaps_rms(path_expected, pixmap)
568556
print(f'{rms=}')
569-
if pymupdf.mupdf_version_tuple < (1, 25, 5):
570-
# Prior to fix for mupdf bug 708274.
571-
assert 3 < rms < 3.5
572-
else:
573-
assert rms < 0.01
557+
assert rms < 0.01
574558

575559

576560
def test_4179():
@@ -655,11 +639,7 @@ def test_4179():
655639
pixmap_diff.save(path_out_diff)
656640
print(f'Have saved to: {path_out_diff=}')
657641
print(f'{rms=}')
658-
if pymupdf.mupdf_version_tuple < (1, 25, 5):
659-
# Prior to fix for mupdf bug 708274, our rects are rendered slightly incorrectly.
660-
assert 3.5 < rms < 4.5
661-
else:
662-
assert rms < 0.01
642+
assert rms < 0.01
663643

664644
finally:
665645
pymupdf.TOOLS.set_aa_level(aa)

0 commit comments

Comments
 (0)