|
1 | 1 | import pymupdf |
2 | | - |
3 | | -import os.path |
| 2 | +from pathlib import Path |
4 | 3 |
|
5 | 4 |
|
6 | 5 | def test_4141(): |
7 | | - """survive missing /Resources object in a number of cases.""" |
8 | | - path = os.path.abspath(f"{__file__}/../../tests/resources/test_4141.pdf") |
9 | | - doc = pymupdf.open(path) |
10 | | - page = doc[0] |
11 | | - # make sure the right test file |
12 | | - assert doc.xref_get_key(page.xref, "Resources") == ("null", "null") |
13 | | - page.insert_htmlbox((100, 100, 200, 200), "Hallo") # will fail without the fix |
14 | | - doc.close() |
15 | | - doc = pymupdf.open(doc.name) |
16 | | - page = doc[0] |
17 | | - tw = pymupdf.TextWriter(page.rect) |
18 | | - tw.append((100, 100), "Hallo") |
19 | | - tw.write_text(page) # will fail without the fix |
| 6 | + """Survive missing /Resources object in multiple situations.""" |
| 7 | + |
| 8 | + # Resolve the test file path |
| 9 | + test_pdf = Path(__file__).resolve().parent.parent / "tests" / "resources" / "test_4141.pdf" |
| 10 | + assert test_pdf.exists(), f"Missing test file: {test_pdf}" |
| 11 | + |
| 12 | + # Case 1: Insert HTML box |
| 13 | + with pymupdf.open(test_pdf) as doc: |
| 14 | + page = doc[0] |
| 15 | + |
| 16 | + # Ensure we are using the correct test file |
| 17 | + assert doc.xref_get_key(page.xref, "Resources") == ("null", "null") |
| 18 | + |
| 19 | + # Should not fail after the fix |
| 20 | + page.insert_htmlbox((100, 100, 200, 200), "Hallo") |
| 21 | + |
| 22 | + # Case 2: TextWriter operations after reopen |
| 23 | + with pymupdf.open(test_pdf) as doc: |
| 24 | + page = doc[0] |
| 25 | + tw = pymupdf.TextWriter(page.rect) |
| 26 | + tw.append((100, 100), "Hallo") |
| 27 | + tw.write_text(page) # Should also not fail |
0 commit comments