Skip to content

Commit

Permalink
tests/: reduced verbose diagnostics.
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-smith-artifex-com committed Aug 23, 2024
1 parent 415cdc6 commit 205bd0f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
6 changes: 3 additions & 3 deletions tests/test_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ def test_load_system_font():
trace = list()
def font_f(name, bold, italic, needs_exact_metrics):
trace.append((name, bold, italic, needs_exact_metrics))
print(f'font_f(): Looking for font: {name=} {bold=} {italic=} {needs_exact_metrics=}.')
print(f'test_load_system_font():font_f(): Looking for font: {name=} {bold=} {italic=} {needs_exact_metrics=}.')
return None
def f_cjk(name, ordering, serif):
trace.append((name, ordering, serif))
print(f'f_cjk(): Looking for font: {name=} {ordering=} {serif=}.')
print(f'test_load_system_font():f_cjk(): Looking for font: {name=} {ordering=} {serif=}.')
return None
def f_fallback(script, language, serif, bold, italic):
trace.append((script, language, serif, bold, italic))
print(f'f_fallback(): looking for font: {script=} {language=} {serif=} {bold=} {italic=}.')
print(f'test_load_system_font():f_fallback(): looking for font: {script=} {language=} {serif=} {bold=} {italic=}.')
return None
pymupdf.mupdf.fz_install_load_system_font_funcs(font_f, f_cjk, f_fallback)
f = pymupdf.mupdf.fz_load_system_font("some-font-name", 0, 0, 0)
Expand Down
17 changes: 10 additions & 7 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_texttrace():
# Repeat, this time writing data to file.
import json
path = f'{scriptdir}/resources/test_texttrace.txt'
print( f'Writing to: {path}')
print( f'test_texttrace(): Writing to: {path}')
with open( path, 'w') as f:
for i, page in enumerate(document):
tt = page.get_texttrace()
Expand Down Expand Up @@ -592,6 +592,7 @@ def test_2730():

def test_2553():
"""Ensure identical output across text extractions."""
verbose = 0
doc = pymupdf.open(f"{scriptdir}/resources/test_2553.pdf")
page = doc[0]

Expand All @@ -616,9 +617,11 @@ def show(l):
else:
ret += f' [0x{hex(cc)}]'
return ret
print(f'list1:\n{show(list1)}')
print(f'list2:\n{show(list2)}')
print(f'list3:\n{show(list3)}')

if verbose:
print(f'list1:\n{show(list1)}')
print(f'list2:\n{show(list2)}')
print(f'list3:\n{show(list3)}')

# all sets must be equal
assert set1 == set2
Expand Down Expand Up @@ -1217,11 +1220,11 @@ def test_533():
doc = pymupdf.open(path)
print()
for p in doc:
print(f'for p in doc: {p=}.')
print(f'test_533(): for p in doc: {p=}.')
for p in list(doc)[:]:
print(f'for p in list(doc)[:]: {p=}.')
print(f'test_533(): for p in list(doc)[:]: {p=}.')
for p in doc[:]:
print(f'for p in doc[:]: {p=}.')
print(f'test_533(): for p in doc[:]: {p=}.')

def test_3354():
document = pymupdf.open(filename)
Expand Down
35 changes: 18 additions & 17 deletions tests/test_story.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def rectfn(rect_num, filled):
def make_pdf(html, path_out):
story = pymupdf.Story(html=html)
document = story.write_with_links(rectfn)
print(f'Writing to: {path_out=}.')
print(f'test_2753(): Writing to: {path_out=}.')
document.save(path_out)
return document

Expand Down Expand Up @@ -104,6 +104,7 @@ def test_fit_springer():
print(f'test_fit_springer(): not running on classic.')
return

verbose = 0
story = pymupdf.Story(springer_html)

def check(call, expected):
Expand All @@ -123,24 +124,24 @@ def check(call, expected):
print(f'Have saved document to {path}.')
assert abs(fit_result.parameter-expected) < 0.001, f'{expected=} {fit_result.parameter=}'

check('story.fit_scale(pymupdf.Rect(0, 0, 200, 200), scale_min=1, verbose=1)', 3.685728073120117)
check('story.fit_scale(pymupdf.Rect(0, 0, 595, 842), scale_min=1, verbose=1)', 1.0174560546875)
check('story.fit_scale(pymupdf.Rect(0, 0, 300, 421), scale_min=1, verbose=1)', 2.02752685546875)
check('story.fit_scale(pymupdf.Rect(0, 0, 600, 900), scale_min=1, scale_max=1, verbose=1)', 1)
check(f'story.fit_scale(pymupdf.Rect(0, 0, 200, 200), scale_min=1, verbose={verbose})', 3.685728073120117)
check(f'story.fit_scale(pymupdf.Rect(0, 0, 595, 842), scale_min=1, verbose={verbose})', 1.0174560546875)
check(f'story.fit_scale(pymupdf.Rect(0, 0, 300, 421), scale_min=1, verbose={verbose})', 2.02752685546875)
check(f'story.fit_scale(pymupdf.Rect(0, 0, 600, 900), scale_min=1, scale_max=1, verbose={verbose})', 1)

check('story.fit_height(20, verbose=1)', 10782.3291015625)
check('story.fit_height(200, verbose=1)', 2437.4990234375)
check('story.fit_height(2000, verbose=1)', 450.2998046875)
check('story.fit_height(5000, verbose=1)', 378.2998046875)
check('story.fit_height(5500, verbose=1)', 378.2998046875)
check(f'story.fit_height(20, verbose={verbose})', 10782.3291015625)
check(f'story.fit_height(200, verbose={verbose})', 2437.4990234375)
check(f'story.fit_height(2000, verbose={verbose})', 450.2998046875)
check(f'story.fit_height(5000, verbose={verbose})', 378.2998046875)
check(f'story.fit_height(5500, verbose={verbose})', 378.2998046875)

check('story.fit_width(3000, verbose=1)', 167.30859375)
check('story.fit_width(2000, verbose=1)', 239.595703125)
check('story.fit_width(1000, verbose=1)', 510.85546875)
check('story.fit_width(500, verbose=1)', 1622.1272945404053)
check('story.fit_width(400, verbose=1)', 2837.507724761963)
check('story.fit_width(300, width_max=200000, verbose=1)', None)
check('story.fit_width(200, width_max=200000, verbose=1)', None)
check(f'story.fit_width(3000, verbose={verbose})', 167.30859375)
check(f'story.fit_width(2000, verbose={verbose})', 239.595703125)
check(f'story.fit_width(1000, verbose={verbose})', 510.85546875)
check(f'story.fit_width(500, verbose={verbose})', 1622.1272945404053)
check(f'story.fit_width(400, verbose={verbose})', 2837.507724761963)
check(f'story.fit_width(300, width_max=200000, verbose={verbose})', None)
check(f'story.fit_width(200, width_max=200000, verbose={verbose})', None)

# Run without verbose to check no calls to log() - checked by assert.
check('story.fit_scale(pymupdf.Rect(0, 0, 600, 900), scale_min=1, scale_max=1, verbose=0)', 1)
Expand Down
8 changes: 5 additions & 3 deletions tests/test_textextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,16 @@ def llen(texts):


def test_3594():
verbose = 0
print()
d = pymupdf.open(os.path.abspath(f'{__file__}/../../tests/resources/test_3594.pdf'))
for i, p in enumerate(d.pages()):
text = p.get_text()
print('='*40)
print(f'Page {i}:')
for line in text.split('\n'):
print(f' {line!r}')
if verbose:
for line in text.split('\n'):
print(f' {line!r}')
print('='*40)
if pymupdf.mupdf_version_tuple < (1, 24, 3):
# We expect MuPDF warnings.
wt = pymupdf.TOOLS.mupdf_warnings()
Expand Down

0 comments on commit 205bd0f

Please sign in to comment.