From ce9c9dd079d9ca9d0deebe0b33bd948cc702ee83 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sat, 18 Jun 2022 11:14:39 +0200 Subject: [PATCH] More tests --- tests/test_merger.py | 12 ++++++++++++ tests/test_writer.py | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/test_merger.py b/tests/test_merger.py index b78028223..beba5cdad 100644 --- a/tests/test_merger.py +++ b/tests/test_merger.py @@ -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" diff --git a/tests/test_writer.py b/tests/test_writer.py index 9f9bc1fc9..5c034e269 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -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") @@ -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")