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

Function test_4182

tests/test_textextract.py:545–572  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

543
544
545def test_4182():
546 path = os.path.normpath(f'{__file__}/../../tests/resources/test_4182.pdf')
547 with pymupdf.open(path) as document:
548 page = document[0]
549 dict_ = page.get_text('dict')
550 linelist = []
551 for block in dict_['blocks']:
552 if block['type'] == 0:
553 paranum = block['number']
554 if 'lines' in block:
555 for line in block.get('lines', ()):
556 for span in line['spans']:
557 if span['text'].strip():
558 page.draw_rect(span['bbox'], color=(1, 0, 0))
559 linelist.append([paranum, span['bbox'], repr(span['text'])])
560 pixmap = page.get_pixmap()
561 path_out = os.path.normpath(f'{__file__}/../../tests/resources/test_4182_out.png')
562 pixmap.save(path_out)
563 if platform.system() != 'Windows': # Output on Windows can fail due to non-utf8 stdout.
564 for l in linelist:
565 print(l)
566 path_expected = os.path.normpath(f'{__file__}/../../tests/resources/test_4182_expected.png')
567 pixmap_diff = gentle_compare.pixmaps_diff(path_expected, pixmap)
568 path_diff = os.path.normpath(f'{__file__}/../../tests/resources/test_4182_diff.png')
569 pixmap_diff.save(path_diff)
570 rms = gentle_compare.pixmaps_rms(path_expected, pixmap)
571 print(f'{rms=}')
572 assert rms < 0.01
573
574
575def test_4179():

Callers

nothing calls this directly

Calls 6

get_textMethod · 0.45
getMethod · 0.45
draw_rectMethod · 0.45
appendMethod · 0.45
get_pixmapMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…