Skip to content

Commit 5e66dd1

Browse files
julian-smith-artifex-comJorjMcKie
authored andcommitted
tests/test_font.py:test_3677: don't modify global state.
This was breaking new test_tables.test_md_styles() test. We now always restore state of by calling pymupdf.TOOLS.set_subset_fontnames(False).
1 parent a3c2b77 commit 5e66dd1

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

tests/test_font.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,28 @@ def test_mupdf_subset_fonts2():
139139

140140
def test_3677():
141141
pymupdf.TOOLS.set_subset_fontnames(True)
142-
path = os.path.abspath(f'{__file__}/../../tests/resources/test_3677.pdf')
143-
font_names_expected = [
144-
'BCDEEE+Aptos',
145-
'BCDFEE+Aptos',
146-
'BCDGEE+Calibri-Light',
147-
'BCDHEE+Calibri-Light',
148-
]
149-
font_names = list()
150-
with pymupdf.open(path) as document:
151-
for page in document:
152-
for block in page.get_text('dict')['blocks']:
153-
if block['type'] == 0:
154-
if 'lines' in block.keys():
155-
for line in block['lines']:
156-
for span in line['spans']:
157-
font_name=span['font']
158-
print(font_name)
159-
font_names.append(font_name)
160-
assert font_names == font_names_expected, f'{font_names=}'
142+
try:
143+
path = os.path.abspath(f'{__file__}/../../tests/resources/test_3677.pdf')
144+
font_names_expected = [
145+
'BCDEEE+Aptos',
146+
'BCDFEE+Aptos',
147+
'BCDGEE+Calibri-Light',
148+
'BCDHEE+Calibri-Light',
149+
]
150+
font_names = list()
151+
with pymupdf.open(path) as document:
152+
for page in document:
153+
for block in page.get_text('dict')['blocks']:
154+
if block['type'] == 0:
155+
if 'lines' in block.keys():
156+
for line in block['lines']:
157+
for span in line['spans']:
158+
font_name=span['font']
159+
print(font_name)
160+
font_names.append(font_name)
161+
assert font_names == font_names_expected, f'{font_names=}'
162+
finally:
163+
pymupdf.TOOLS.set_subset_fontnames(False)
161164

162165

163166
def test_3933():

0 commit comments

Comments
 (0)