@@ -227,13 +227,15 @@ def test_text_urls():
227
227
with pikepdf .Pdf .open (fd ) as pdf :
228
228
annots = pdf .pages [0 ].Annots
229
229
230
- for y , fragment in [('0.1' , 'plain' ), ('0.4' , 'mathtext' )]:
231
- annot = next (
232
- (a for a in annots if a .A .URI == f'{ test_url } { fragment } ' ),
233
- None )
234
- assert annot is not None
235
- # Positions in points (72 per inch.)
236
- assert annot .Rect [1 ] == decimal .Decimal (y ) * 72
230
+ # Iteration over Annots must occur within the context manager,
231
+ # otherwise it may fail depending on the pdf structure.
232
+ for y , fragment in [('0.1' , 'plain' ), ('0.4' , 'mathtext' )]:
233
+ annot = next (
234
+ (a for a in annots if a .A .URI == f'{ test_url } { fragment } ' ),
235
+ None )
236
+ assert annot is not None
237
+ # Positions in points (72 per inch.)
238
+ assert annot .Rect [1 ] == decimal .Decimal (y ) * 72
237
239
238
240
239
241
@needs_usetex
@@ -251,12 +253,14 @@ def test_text_urls_tex():
251
253
with pikepdf .Pdf .open (fd ) as pdf :
252
254
annots = pdf .pages [0 ].Annots
253
255
254
- annot = next (
255
- (a for a in annots if a .A .URI == f'{ test_url } tex' ),
256
- None )
257
- assert annot is not None
258
- # Positions in points (72 per inch.)
259
- assert annot .Rect [1 ] == decimal .Decimal ('0.7' ) * 72
256
+ # Iteration over Annots must occur within the context manager,
257
+ # otherwise it may fail depending on the pdf structure.
258
+ annot = next (
259
+ (a for a in annots if a .A .URI == f'{ test_url } tex' ),
260
+ None )
261
+ assert annot is not None
262
+ # Positions in points (72 per inch.)
263
+ assert annot .Rect [1 ] == decimal .Decimal ('0.7' ) * 72
260
264
261
265
262
266
def test_pdfpages_fspath ():
0 commit comments