Skip to content

Commit

Permalink
MAINT: Improve test coverage (#2796)
Browse files Browse the repository at this point in the history
  • Loading branch information
pubpub-zz authored Aug 12, 2024
1 parent 46c89dd commit a9758ae
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
10 changes: 10 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2188,6 +2188,10 @@ def test_replace_object():
reader._replace_object(reader.pages[0].indirect_reference, reader.pages[0])
pg = PageObject.create_blank_page(writer, 1000, 1000)
reader._replace_object(reader.pages[0].indirect_reference, pg)
pg = PageObject.create_blank_page(None, 1000, 1000)
pg[NameObject("/Contents")] = writer.pages[0]["/Contents"]
writer._add_object(pg)
writer.add_page(pg)


def test_mime_jupyter():
Expand Down Expand Up @@ -2300,3 +2304,9 @@ def test_matrix_entry_in_field_annots():
auto_regenerate=False,
)
assert "/Matrix" in writer.pages[0]["/Annots"][5].get_object()["/AP"]["/N"]


def test_set_need_appearances_writer():
"""Minimal test for coverage"""
writer = PdfWriter()
writer.set_need_appearances_writer()
31 changes: 30 additions & 1 deletion tests/test_xmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pypdf.generic
import pypdf.xmp
from pypdf import PdfReader
from pypdf import PdfReader, PdfWriter
from pypdf.errors import PdfReadError

from . import get_data_from_url
Expand Down Expand Up @@ -42,6 +42,35 @@ def test_read_xmp_metadata_samples(src):
}


def test_writer_xmp_metadata_samples():
writer = PdfWriter(SAMPLE_ROOT / "020-xmp/output_with_metadata_pymupdf.pdf")
xmp = writer.xmp_metadata
assert xmp
assert xmp.dc_contributor == []
assert xmp.dc_creator == ["John Doe"]
assert xmp.dc_source == "Martin Thoma" # attribute node
assert xmp.dc_description == {"x-default": "This is a text"}
assert xmp.dc_date == [datetime(1990, 4, 28, 0, 0)]
assert xmp.dc_title == {"x-default": "Sample PDF with XMP Metadata"}
assert xmp.custom_properties == {
"Style": "FooBarStyle",
"other": "worlds",
"⏰": "time",
}
co = pypdf.generic.ContentStream(None, None)
co.set_data(
xmp.stream.get_data().replace(
b'dc:source="Martin Thoma"', b'dc:source="Pubpub-Zz"'
)
)
writer.xmp_metadata = pypdf.xmp.XmpInformation(co)
b = BytesIO()
writer.write(b)
reader = PdfReader(b)
xmp2 = reader.xmp_metadata
assert xmp2.dc_source == "Pubpub-Zz"


@pytest.mark.parametrize(
("src", "has_xmp"),
[
Expand Down

0 comments on commit a9758ae

Please sign in to comment.