Using a context manager instead of explicitly closing files
()
| 102 | |
| 103 | |
| 104 | def 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 | |
| 121 | def _test_insert_adobe(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…