Skip to content

Commit 97d47a0

Browse files
TST: Improve test coverage (#3584)
1 parent bda80a4 commit 97d47a0

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

tests/test_filters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Test the pypdf.filters module."""
22
import os
3-
import shutil
43
import string
54
import subprocess
5+
import sys
66
import zlib
77
from io import BytesIO
88
from itertools import product as cartesian_product
@@ -307,7 +307,7 @@ def test_image_without_pillow(tmp_path):
307307
except KeyError:
308308
env["PYTHONPATH"] = "."
309309
result = subprocess.run( # noqa: S603 # We have the control here.
310-
[shutil.which("python"), source_file],
310+
[sys.executable, source_file],
311311
capture_output=True,
312312
env=env,
313313
)

tests/test_page.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
import json
33
import logging
44
import math
5+
import os
56
import re
67
import shutil
78
import subprocess
9+
import sys
810
from copy import deepcopy
911
from io import BytesIO
1012
from pathlib import Path
@@ -1639,11 +1641,52 @@ def test_merge_page__coverage():
16391641
assert page.mediabox == RectangleObject((0.0, 0.0, 20, 10))
16401642

16411643
# 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)
16431648
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))
16461655

16471656
# 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

Comments
 (0)