Skip to content

Commit

Permalink
tests/: added another stext bbox test, test_4179.
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-smith-artifex-com committed Jan 23, 2025
1 parent 518c213 commit 8f06592
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Binary file added tests/resources/test_4179.pdf
Binary file not shown.
Binary file added tests/resources/test_4179_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions tests/test_textextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,30 @@ def test_4182():
rms = gentle_compare.pixmaps_rms(path_expected, pixmap)
print(f'{rms=}')
assert rms < 0.01


def test_4179():
path = os.path.normpath(f'{__file__}/../../tests/resources/test_4179.pdf')
with pymupdf.open(path) as document:
page = document[3]
dict_ = page.get_text('dict')
linelist = []
for block in dict_['blocks']:
if block['type'] == 0:
paranum = block['number']
if 'lines' in block:
for line in block.get('lines', ()):
for span in line['spans']:
if span['text'].strip():
page.draw_rect(span['bbox'], color=(1, 0, 0))
linelist.append([paranum, span['bbox'], repr(span['text'])])
pixmap = page.get_pixmap()
path_out = os.path.normpath(f'{__file__}/../../tests/resources/test_4179_out.png')
pixmap.save(path_out)
if platform.system() != 'Windows': # Output on Windows can fail due to non-utf8 stdout.
for l in linelist:
print(l)
path_expected = os.path.normpath(f'{__file__}/../../tests/resources/test_4179_expected.png')
rms = gentle_compare.pixmaps_rms(path_expected, pixmap)
print(f'{rms=}')
assert rms < 0.01

0 comments on commit 8f06592

Please sign in to comment.