|
2 | 2 | import json |
3 | 3 | import logging |
4 | 4 | import math |
| 5 | +import os |
5 | 6 | import re |
6 | 7 | import shutil |
7 | 8 | import subprocess |
| 9 | +import sys |
8 | 10 | from copy import deepcopy |
9 | 11 | from io import BytesIO |
10 | 12 | from pathlib import Path |
@@ -1639,11 +1641,52 @@ def test_merge_page__coverage(): |
1639 | 1641 | assert page.mediabox == RectangleObject((0.0, 0.0, 20, 10)) |
1640 | 1642 |
|
1641 | 1643 | # With transformation. |
1642 | | - page = PageObject.create_blank_page(width=10, height=10) |
| 1644 | + path = RESOURCE_ROOT / "crazyones.pdf" |
| 1645 | + page = PdfWriter(clone_from=path).pages[0] |
| 1646 | + page.indirect_reference = None |
| 1647 | + page2 = PageObject.create_blank_page(width=20, height=5) |
1643 | 1648 | transformation = Transformation().rotate(90) |
1644 | | - page.merge_transformed_page(PageObject.create_blank_page(width=20, height=5), ctm=transformation, expand=True) |
1645 | | - assert page.mediabox == RectangleObject((-5, 0.0, 10, 20)) |
| 1649 | + page2.merge_transformed_page(page, ctm=transformation, expand=True) |
| 1650 | + assert page2.mediabox == RectangleObject((-792, 0.0, 20, 612)) |
| 1651 | + |
| 1652 | + page2 = PageObject.create_blank_page(width=20, height=5) |
| 1653 | + page2.merge_transformed_page(page, ctm=transformation.ctm, expand=True) |
| 1654 | + assert page2.mediabox == RectangleObject((-792, 0.0, 20, 612)) |
1646 | 1655 |
|
1647 | 1656 | # Not over. |
1648 | | - page = PageObject.create_blank_page(width=10, height=10) |
1649 | | - page.merge_page(PageObject.create_blank_page(width=20, height=30), over=False) |
| 1657 | + page = PdfWriter(clone_from=path).pages[0] |
| 1658 | + page.indirect_reference = None |
| 1659 | + page2 = PageObject.create_blank_page(width=20, height=5) |
| 1660 | + page2.merge_page(page, over=False) |
| 1661 | + |
| 1662 | + |
| 1663 | +@pytest.mark.enable_socket |
| 1664 | +def test_importing_without_pillow(tmp_path): |
| 1665 | + env = os.environ.copy() |
| 1666 | + env["COVERAGE_PROCESS_START"] = "pyproject.toml" |
| 1667 | + |
| 1668 | + source_file = tmp_path / "script.py" |
| 1669 | + source_file.write_text( |
| 1670 | + """ |
| 1671 | +import sys |
| 1672 | +sys.modules["PIL"] = None |
| 1673 | +
|
| 1674 | +from pypdf import PageObject |
| 1675 | +from pypdf._page import pil_not_imported |
| 1676 | +
|
| 1677 | +print(pil_not_imported) |
| 1678 | +""" |
| 1679 | + ) |
| 1680 | + |
| 1681 | + try: |
| 1682 | + env["PYTHONPATH"] = "." + os.pathsep + env["PYTHONPATH"] |
| 1683 | + except KeyError: |
| 1684 | + env["PYTHONPATH"] = "." |
| 1685 | + result = subprocess.run( # noqa: S603 # We have the control here. |
| 1686 | + [sys.executable, source_file], |
| 1687 | + capture_output=True, |
| 1688 | + env=env, |
| 1689 | + ) |
| 1690 | + assert result.returncode == 0 |
| 1691 | + assert result.stdout.replace(b"\r\n", b"\n") == b"True\n" |
| 1692 | + assert result.stderr == b"" |
0 commit comments