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

Function test_1645

tests/test_annots.py:229–269  ·  view source on GitHub ↗

Test fix for #1645.

()

Source from the content-addressed store, hash-verified

227
228
229def test_1645():
230 '''
231 Test fix for #1645.
232 '''
233 # The expected output files assume annot_stem is 'jorj'. We need to always
234 # restore this before returning (this is checked by conftest.py).
235 annot_stem = pymupdf.JM_annot_id_stem
236 pymupdf.TOOLS.set_annot_stem('jorj')
237 try:
238 path_in = os.path.abspath( f'{__file__}/../resources/symbol-list.pdf')
239 if pymupdf.mupdf_version_tuple >= (1, 27):
240 path_expected = os.path.abspath( f'{__file__}/../../tests/resources/test_1645_expected-after-1.27.0.pdf')
241 else:
242 path_expected = os.path.abspath( f'{__file__}/../../tests/resources/test_1645_expected.pdf')
243 path_out = os.path.abspath( f'{__file__}/../test_1645_out.pdf')
244 doc = pymupdf.open(path_in)
245 page = doc[0]
246 page_bounds = page.bound()
247 annot_loc = pymupdf.Rect(page_bounds.x0, page_bounds.y0, page_bounds.x0 + 75, page_bounds.y0 + 15)
248 # Check type of page.derotation_matrix - this is #2911.
249 assert isinstance(page.derotation_matrix, pymupdf.Matrix), \
250 f'Bad type for page.derotation_matrix: {type(page.derotation_matrix)=} {page.derotation_matrix=}.'
251 page.add_freetext_annot(
252 annot_loc * page.derotation_matrix,
253 "TEST",
254 fontsize=18,
255 fill_color=pymupdf.utils.getColor("FIREBRICK1"),
256 rotate=page.rotation,
257 )
258 doc.save(path_out, garbage=1, deflate=True, no_new_id=True)
259 print(f'Have created {path_out}. comparing with {path_expected}.')
260 with pymupdf.open(path_expected) as doc_expected, pymupdf.open(path_out) as doc_out:
261 rms = gentle_compare.pixmaps_rms(
262 doc_expected[0].get_pixmap(),
263 doc_out[0].get_pixmap(),
264 )
265 print(f'test_1645: {rms=}')
266 assert rms < 0.1, f'Pixmaps differ: {path_expected=} {path_out=}'
267 finally:
268 # Restore annot_stem.
269 pymupdf.TOOLS.set_annot_stem(annot_stem)
270
271def test_1824():
272 ''&#x27;

Callers

nothing calls this directly

Calls 5

set_annot_stemMethod · 0.80
boundMethod · 0.80
add_freetext_annotMethod · 0.80
saveMethod · 0.45
get_pixmapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…