Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: test coverage #2796

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading