Skip to content

Commit

Permalink
TST: PdfWriter (py-pdf#1781)
Browse files Browse the repository at this point in the history
* TST: Deprecation error for arguments of PdfWriter.encrypt
* TST: PdfWriter
  • Loading branch information
MartinThoma authored Apr 10, 2023
1 parent 432229e commit 6836174
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ def writer_operate(writer: PdfWriter) -> None:
)
writer.add_blank_page()
writer.add_uri(2, "https://example.com", RectangleObject([0, 0, 100, 100]))
with pytest.warns(
DeprecationWarning, match="'pagenum' argument of add_uri is deprecated"
):
writer.add_uri(
2, "https://example.com", RectangleObject([0, 0, 100, 100]), pagenum=2
)
with pytest.raises(DeprecationError):
writer.add_link(2, 1, RectangleObject([0, 0, 100, 100]))
assert writer._get_page_layout() is None
Expand All @@ -179,6 +185,8 @@ def writer_operate(writer: PdfWriter) -> None:
assert writer._get_page_mode() is None
writer.set_page_mode("/UseNone")
assert writer._get_page_mode() == "/UseNone"
writer.set_page_mode(NameObject("/UseOC"))
assert writer._get_page_mode() == "/UseOC"
writer.insert_blank_page(width=100, height=100)
writer.insert_blank_page() # without parameters

Expand Down Expand Up @@ -565,6 +573,14 @@ def test_add_named_destination(pdf_file_path):
writer.add_named_destination(TextStringObject("A named dest"), 2)
writer.add_named_destination(TextStringObject("A named dest2"), 2)

with pytest.warns(DeprecationWarning, match="pagenum is deprecated as an argument"):
writer.add_named_destination(TextStringObject("A named dest3"), pagenum=2)

with pytest.raises(ValueError):
writer.add_named_destination(
TextStringObject("A named dest3"), pagenum=2, page_number=2
)

root = writer.get_named_dest_root()
assert root[0] == "A named dest"
assert root[1].pdf == writer
Expand All @@ -574,6 +590,7 @@ def test_add_named_destination(pdf_file_path):
assert root[3].pdf == writer
assert root[3].get_object()["/S"] == NameObject("/GoTo")
assert root[3].get_object()["/D"][0] == writer.pages[2].indirect_reference
assert root[4] == "A named dest3"

# test get_object

Expand Down Expand Up @@ -1263,7 +1280,7 @@ def test_new_removes():
name = "GeoBaseWithComments.pdf"
in_pdf = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
out_pdf.append(in_pdf)
out_pdf.remove_objects_from_page(out_pdf.pages[0], ObjectDeletionFlag.LINKS)
out_pdf.remove_objects_from_page(out_pdf.pages[0], [ObjectDeletionFlag.LINKS])
assert "/Links" not in [
a.get_object()["/Subtype"] for a in out_pdf.pages[0]["/Annots"]
]
Expand All @@ -1285,6 +1302,8 @@ def test_new_removes():
assert len(out_pdf.pages[0]["/Annots"]) == 0
assert len(out_pdf.pages[3]["/Annots"]) == 0

out_pdf.remove_annotations("/Text")


@pytest.mark.enable_socket()
def test_late_iss1654():
Expand Down

0 comments on commit 6836174

Please sign in to comment.