comparison tests/test_pixmap.py @ 39:a6bc019ac0b2 upstream

ADD: PyMuPDF v1.26.5: the original sdist.
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 11 Oct 2025 11:19:58 +0200
parents 1d09e1dec1d9
children
comparison
equal deleted inserted replaced
2:b50eed0cc0ef 39:a6bc019ac0b2
68 pix1 = pymupdf.Pixmap(imgfile) 68 pix1 = pymupdf.Pixmap(imgfile)
69 stream = pix1.pil_tobytes("JPEG") 69 stream = pix1.pil_tobytes("JPEG")
70 pix2 = pymupdf.Pixmap(stream) 70 pix2 = pymupdf.Pixmap(stream)
71 assert repr(pix1) == repr(pix2) 71 assert repr(pix1) == repr(pix2)
72 except ModuleNotFoundError: 72 except ModuleNotFoundError:
73 assert platform.system() == 'Windows' and sys.maxsize == 2**31 - 1 73 assert platform.system() in ('Windows', 'Emscripten') and sys.maxsize == 2**31 - 1
74 74
75 75
76 def test_save(tmpdir): 76 def test_save(tmpdir):
77 # pixmaps from file then save to image 77 # pixmaps from file then save to image
78 # make pixmap from this and confirm equality 78 # make pixmap from this and confirm equality
554 wt = pymupdf.TOOLS.mupdf_warnings() 554 wt = pymupdf.TOOLS.mupdf_warnings()
555 assert wt == 'format error: cannot find object in xref (56 0 R)\nformat error: cannot find object in xref (68 0 R)' 555 assert wt == 'format error: cannot find object in xref (56 0 R)\nformat error: cannot find object in xref (68 0 R)'
556 556
557 557
558 def test_4445(): 558 def test_4445():
559 if os.environ.get('PYODIDE_ROOT'):
560 print('test_4445(): not running on Pyodide - cannot run child processes.')
561 return
559 print() 562 print()
560 # Test case is large so we download it instead of having it in PyMuPDF 563 # Test case is large so we download it instead of having it in PyMuPDF
561 # git. We put it in `cache/` directory do it is not removed by `git clean` 564 # git. We put it in `cache/` directory do it is not removed by `git clean`
562 # (unless `-d` is specified). 565 # (unless `-d` is specified).
563 import util 566 import util
626 print(f'{rms=}') 629 print(f'{rms=}')
627 if pymupdf.mupdf_version_tuple >= (1, 26, 6): 630 if pymupdf.mupdf_version_tuple >= (1, 26, 6):
628 assert rms == 0 631 assert rms == 0
629 else: 632 else:
630 assert rms >= 10 633 assert rms >= 10
634
635
636 def test_4699():
637 path = os.path.normpath(f'{__file__}/../../tests/resources/test_4699.pdf')
638 path_png_expected = os.path.normpath(f'{__file__}/../../tests/resources/test_4699.png')
639 path_png_actual = os.path.normpath(f'{__file__}/../../tests/test_4699.png')
640 with pymupdf.open(path) as document:
641 page = document[0]
642 pixmap = page.get_pixmap()
643 pixmap.save(path_png_actual)
644 print(f'Have saved to {path_png_actual=}.')
645 rms = gentle_compare.pixmaps_rms(path_png_expected, pixmap)
646 print(f'test_4699(): {rms=}')
647 if pymupdf.mupdf_version_tuple >= (1, 27):
648 assert rms == 0
649 else:
650 wt = pymupdf.TOOLS.mupdf_warnings()
651 assert 'syntax error: cannot find ExtGState resource' in wt
652 assert rms > 20