Skip to content

Commit

Permalink
Merge pull request #1529 from cbm755/test1417
Browse files Browse the repository at this point in the history
test: insertpdf in a loop with context manager
  • Loading branch information
JorjMcKie authored Jan 12, 2022
2 parents f0a614e + ed9aec3 commit c033e10
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/test_insertpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Compare with stored earlier result:
- must have identical object definitions
- must have different trailers
* Try inserting files in a loop.
"""
import os

Expand Down Expand Up @@ -35,3 +36,13 @@ def test_joining():
)
assert old_output.xref_get_keys(-1) == new_output.xref_get_keys(-1)
assert old_output.xref_get_key(-1, "ID") != new_output.xref_get_key(-1, "ID")


def test_issue1417_insertpdf_in_loop():
"""Using a context manager instead of explicitly closing files"""
f = os.path.join(resources, "1.pdf")
big_doc = fitz.open()
for n in range(0, 1025):
with fitz.open(f) as pdf:
big_doc.insert_pdf(pdf)
big_doc.close()

0 comments on commit c033e10

Please sign in to comment.