From ed9aec316b07ca6bfe89376f99bb1cd098e8a267 Mon Sep 17 00:00:00 2001 From: "Colin B. Macdonald" Date: Tue, 11 Jan 2022 20:26:33 -0800 Subject: [PATCH] test: insertpdf in a loop with context manager Related to Issue #1417. --- tests/test_insertpdf.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_insertpdf.py b/tests/test_insertpdf.py index 091dcad4e..af9383696 100644 --- a/tests/test_insertpdf.py +++ b/tests/test_insertpdf.py @@ -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 @@ -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()