Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Jun 18, 2022
1 parent dc503ae commit ce9c9dd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/test_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ def test_zoom():
os.remove("tmp-merger-do-not-commit.pdf")


def test_zoom_xyz_no_left():
url = "https://corpora.tika.apache.org/base/docs/govdocs1/933/933322.pdf"
name = "tika-933322.pdf"
reader = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
merger = PdfMerger()
merger.append(reader)
merger.write("tmp-merger-do-not-commit.pdf")

# cleanup
os.remove("tmp-merger-do-not-commit.pdf")


def test_bookmark():
url = "https://corpora.tika.apache.org/base/docs/govdocs1/997/997511.pdf"
name = "tika-997511.pdf"
Expand Down
18 changes: 17 additions & 1 deletion tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

import pytest

from PyPDF2 import PdfReader, PdfWriter
from PyPDF2 import PdfMerger, PdfReader, PdfWriter
from PyPDF2.errors import PageSizeNotDefinedError
from PyPDF2.generic import RectangleObject

from . import get_pdf_from_url

TESTS_ROOT = os.path.abspath(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(TESTS_ROOT)
RESOURCE_ROOT = os.path.join(PROJECT_ROOT, "resources")
Expand Down Expand Up @@ -455,3 +457,17 @@ def test_issue301():
writer.append_pages_from_reader(reader)
o = BytesIO()
writer.write(o)


def test_sweep_indirect_references_nullobject_exception():
# TODO: Check this more closely... this looks weird
url = "https://corpora.tika.apache.org/base/docs/govdocs1/924/924666.pdf"
name = "tika-924666.pdf"
reader = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
merger = PdfMerger()
merger.append(reader)
with pytest.warns(UserWarning, match="returning NullObject instead"):
merger.write("tmp-merger-do-not-commit.pdf")

# cleanup
os.remove("tmp-merger-do-not-commit.pdf")

0 comments on commit ce9c9dd

Please sign in to comment.