MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / test_issue1417_insertpdf_in_loop

Function test_issue1417_insertpdf_in_loop

tests/test_insertpdf.py:104–118  ·  view source on GitHub ↗

Using a context manager instead of explicitly closing files

()

Source from the content-addressed store, hash-verified

102
103
104def test_issue1417_insertpdf_in_loop():
105 """Using a context manager instead of explicitly closing files"""
106 f = os.path.join(resources, "1.pdf")
107 big_doc = pymupdf.open()
108 fd1 = os.open( f, os.O_RDONLY)
109 os.close( fd1)
110 for n in range(0, 1025):
111 with pymupdf.open(f) as pdf:
112 big_doc.insert_pdf(pdf)
113 # Create a raw file descriptor. If the above pymupdf.open() context leaks
114 # a file descriptor, fd will be seen to increment.
115 fd2 = os.open( f, os.O_RDONLY)
116 assert fd2 == fd1
117 os.close( fd2)
118 big_doc.close()
119
120
121def _test_insert_adobe():

Callers

nothing calls this directly

Calls 2

insert_pdfMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…