MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / test_2553

Function test_2553

tests/test_general.py:627–668  ·  view source on GitHub ↗

Ensure identical output across text extractions.

()

Source from the content-addressed store, hash-verified

625
626
627def test_2553():
628 """Ensure identical output across text extractions."""
629 verbose = 0
630 doc = pymupdf.open(f"{scriptdir}/resources/test_2553.pdf")
631 page = doc[0]
632
633 # extract plain text, build set of all characters
634 list1 = page.get_text()
635 set1 = set(list1)
636
637 # extract text blocks, build set of all characters
638 list2 = page.get_text(sort=True) # internally uses "blocks"
639 set2 = set(list2)
640
641 # extract textbox content, build set of all characters
642 list3 = page.get_textbox(page.rect)
643 set3 = set(list3)
644
645 def show(l):
646 ret = f'len={len(l)}\n'
647 for c in l:
648 cc = ord(c)
649 if (cc >= 32 and cc < 127) or c == '\n':
650 ret += c
651 else:
652 ret += f' [0x{hex(cc)}]'
653 return ret
654
655 if verbose:
656 print(f'list1:\n{show(list1)}')
657 print(f'list2:\n{show(list2)}')
658 print(f'list3:\n{show(list3)}')
659
660 # all sets must be equal
661 assert set1 == set2
662 assert set1 == set3
663
664 # With mupdf later than 1.23.4, this special page contains no invalid
665 # Unicodes.
666 #
667 print(f'Checking no occurrence of 0xFFFD, {pymupdf.mupdf_version_tuple=}.')
668 assert chr(0xFFFD) not in set1
669
670def test_2553_2():
671 doc = pymupdf.open(f"{scriptdir}/resources/test_2553-2.pdf")

Callers

nothing calls this directly

Calls 3

showFunction · 0.70
get_textMethod · 0.45
get_textboxMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…