Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
720b9bb
#3591: Extending typing to tests; cover generic and scripts folder files
iso-techdev Feb 26, 2026
44f2ba0
Merge branch 'main' into issue-3591-PR-1
iso-techdev Mar 12, 2026
88ab7d6
Merge branch 'main' into issue-3591-PR-1
iso-techdev Mar 16, 2026
8f849a6
Ci now runs the checking. New test files also included
iso-techdev Mar 16, 2026
84675bd
fixing workflow
iso-techdev Mar 16, 2026
2984380
Merge branch 'main' into issue-3591-PR-1
iso-techdev Mar 17, 2026
0fa3f6a
Merge branch 'main' into issue-3591-PR-1
iso-techdev Mar 17, 2026
b88e66b
(used black formatter) added type to new test files and methods added…
iso-techdev Mar 17, 2026
912a521
Fixing the workflow, reverting changes, fixing comments
iso-techdev Mar 18, 2026
ee4b135
fixing ci
iso-techdev Mar 18, 2026
1de2a7e
fixing the ci
iso-techdev Mar 18, 2026
49cf240
ruff was commented out from the requirements
iso-techdev Mar 18, 2026
007e957
fixed the ci, regenerated ci requirements to include the missing stubs
iso-techdev Mar 19, 2026
7c7d08c
fixing comments
iso-techdev Mar 20, 2026
1fc402c
Merge branch 'main' into issue-3591-PR-1
iso-techdev Mar 24, 2026
0f21b9f
fxing comments, and new files
iso-techdev Mar 24, 2026
3b8098d
Merge branch 'main' into issue-3591-PR-1
iso-techdev Mar 27, 2026
8516bc2
Fixed the comments
iso-techdev Mar 27, 2026
2886bfe
Merge branch 'main' into issue-3591-PR-1
iso-techdev Mar 30, 2026
1a93cda
Merge branch 'main' into issue-3591-PR-1
iso-techdev Mar 31, 2026
8f6e1b2
Merge branch 'main' into issue-3591-PR-1
iso-techdev Apr 7, 2026
86b9c82
fixing comment
iso-techdev Apr 7, 2026
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
2 changes: 1 addition & 1 deletion tests/generic/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_text_string_object__looks_like_bom(source: bytes, expected: str) -> Non


@pytest.mark.enable_socket
def test_text_string_object__wrongly_detected_bom():
def test_text_string_object__wrongly_detected_bom() -> None:
url = "https://github.com/user-attachments/files/24401507/minimal.pdf"
name = "issue3587.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
Expand Down
6 changes: 3 additions & 3 deletions tests/generic/test_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tests import RESOURCE_ROOT, get_data_from_url


def test_dictionary_object__get_next_object_position():
def test_dictionary_object__get_next_object_position() -> None:
reader = PdfReader(RESOURCE_ROOT / "crazyones.pdf")

# reader.xref = {0: {7: 15, 9: 10245, 12: 939, 14: 2999, 16: 4982, 18: 9949, 22: 11160}}
Expand All @@ -29,7 +29,7 @@ def test_dictionary_object__get_next_object_position():
) == 15


def test_tree_object__cyclic_reference(caplog):
def test_tree_object__cyclic_reference(caplog: pytest.LogCaptureFixture) -> None:
writer = PdfWriter()
child1 = writer._add_object(DictionaryObject())
child2 = writer._add_object(DictionaryObject({NameObject("/Next"): child1}))
Expand All @@ -44,7 +44,7 @@ def test_tree_object__cyclic_reference(caplog):


@pytest.mark.enable_socket
def test_array_object__clone_same_object_multiple_times(caplog):
def test_array_object__clone_same_object_multiple_times(caplog: pytest.LogCaptureFixture) -> None:
url = "https://github.com/user-attachments/files/25412858/Draft_OSMF_financial_statement_2013.pdf"
name = "issue2991.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url=url, name=name)))
Expand Down
56 changes: 29 additions & 27 deletions tests/generic/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import subprocess
from io import BytesIO

import py
import pytest

from pypdf import PdfReader, PdfWriter
Expand All @@ -27,7 +28,8 @@


@pytest.mark.skipif(PDFATTACH_BINARY is None, reason="Requires poppler-utils")
def test_embedded_file__basic(tmpdir):
def test_embedded_file__basic(tmpdir: py.path.LocalPath) -> None:
Comment thread
stefan6419846 marked this conversation as resolved.
Outdated
assert PDFATTACH_BINARY is not None
clean_path = SAMPLE_ROOT / "002-trivial-libre-office-writer" / "002-trivial-libre-office-writer.pdf"
attached_path = tmpdir / "attached.pdf"
file_path = tmpdir / "test.txt"
Expand All @@ -49,7 +51,7 @@ def test_embedded_file__basic(tmpdir):
assert repr(attachment) == "<EmbeddedFile name='test.txt'>"


def test_embedded_file__artificial():
def test_embedded_file__artificial() -> None:
# No alternative name.
pdf_object = DictionaryObject(answer=42)
attachment = EmbeddedFile(name="dummy", pdf_object=pdf_object)
Expand Down Expand Up @@ -80,7 +82,7 @@ def test_embedded_file__artificial():


@pytest.mark.enable_socket
def test_embedded_file__kids():
def test_embedded_file__kids() -> None:
# Generated using the instructions available from
# https://medium.com/@pymupdf/zugferd-and-ghostscript-how-to-create-industry-standard-and-compliant-pdf-e-invoices-83c9fde31ee5
# Notes:
Expand Down Expand Up @@ -119,7 +121,7 @@ def test_embedded_file__kids():


@pytest.mark.enable_socket
def test_embedded_file__ensure_params__existing_params():
def test_embedded_file__ensure_params__existing_params() -> None:
url = "https://github.com/user-attachments/files/18691309/embedded_files_kids.pdf"
name = "embedded_files_kids.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
Expand All @@ -145,7 +147,7 @@ def test_embedded_file__ensure_params__existing_params():
assert params_dict2[NameObject("/TestParam")] == TextStringObject("test_value")


def test_embedded_file__name_is_read_only():
def test_embedded_file__name_is_read_only() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

Expand All @@ -155,7 +157,7 @@ def test_embedded_file__name_is_read_only():
embedded_file.name = "new_name.txt"


def test_embedded_file__alternative_name_setter():
def test_embedded_file__alternative_name_setter() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

Expand All @@ -174,7 +176,7 @@ def test_embedded_file__alternative_name_setter():
assert embedded_file.alternative_name == "PDF String"


def test_embedded_file__alternative_name__uf_key_only():
def test_embedded_file__alternative_name__uf_key_only() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

Expand All @@ -193,7 +195,7 @@ def test_embedded_file__alternative_name__uf_key_only():
assert embedded_file.pdf_object[NameObject("/F")] == create_string_object("new_uf")


def test_embedded_file__alternative_name__f_key_only():
def test_embedded_file__alternative_name__f_key_only() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

Expand All @@ -213,7 +215,7 @@ def test_embedded_file__alternative_name__f_key_only():
assert embedded_file.pdf_object[NameObject("/UF")] == create_string_object("new_f")


def test_embedded_file__alternative_name__both_f_and_uf():
def test_embedded_file__alternative_name__both_f_and_uf() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

Expand All @@ -231,7 +233,7 @@ def test_embedded_file__alternative_name__both_f_and_uf():
assert embedded_file.alternative_name is None


def test_embedded_file__description_setter():
def test_embedded_file__description_setter() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

Expand All @@ -246,7 +248,7 @@ def test_embedded_file__description_setter():
assert embedded_file.description == "PDF Description"


def test_embedded_file__subtype_setter():
def test_embedded_file__subtype_setter() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

Expand All @@ -261,7 +263,7 @@ def test_embedded_file__subtype_setter():
assert embedded_file.subtype == "/application#2Fjson"


def test_embedded_file__content_setter():
def test_embedded_file__content_setter() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")
assert embedded_file.content == b"content"
Expand All @@ -273,7 +275,7 @@ def test_embedded_file__content_setter():
assert embedded_file.content == b"Lorem ipsum dolor sit amet"


def test_embedded_file__size_setter():
def test_embedded_file__size_setter() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

Expand All @@ -288,7 +290,7 @@ def test_embedded_file__size_setter():
assert embedded_file.size == 2048


def test_embedded_file__size_getter():
def test_embedded_file__size_getter() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

Expand All @@ -300,7 +302,7 @@ def test_embedded_file__size_getter():
assert retrieved_size == 4096


def test_embedded_file__creation_date_setter():
def test_embedded_file__creation_date_setter() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

Expand All @@ -312,7 +314,7 @@ def test_embedded_file__creation_date_setter():
assert embedded_file._ensure_params[NameObject("/CreationDate")] == NullObject()


def test_embedded_file__modification_date_setter():
def test_embedded_file__modification_date_setter() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

Expand All @@ -324,7 +326,7 @@ def test_embedded_file__modification_date_setter():
assert embedded_file._ensure_params[NameObject("/ModDate")] == NullObject()


def test_embedded_file__checksum_setter():
def test_embedded_file__checksum_setter() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

Expand All @@ -340,15 +342,15 @@ def test_embedded_file__checksum_setter():
assert embedded_file.checksum == b"pdf_checksum"


def test_embedded_file__associated_file_relationship_setter():
def test_embedded_file__associated_file_relationship_setter() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

embedded_file.associated_file_relationship = NameObject("/Data")
assert embedded_file.associated_file_relationship == "/Data"


def test_embedded_file__setters_integration():
def test_embedded_file__setters_integration() -> None:
writer = PdfWriter()
writer.add_blank_page(100, 100)

Expand All @@ -374,7 +376,7 @@ def test_embedded_file__setters_integration():
assert "test.txt" in reader.attachments


def test_embedded_file__null_object_handling():
def test_embedded_file__null_object_handling() -> None:
writer = PdfWriter()
embedded_file = writer.add_attachment("test.txt", b"content")

Expand All @@ -397,13 +399,13 @@ def test_embedded_file__null_object_handling():
assert embedded_file.checksum is None


def test_embedded_file__delete_without_parent():
def test_embedded_file__delete_without_parent() -> None:
attachment = EmbeddedFile(name="test.txt", pdf_object=DictionaryObject())
with pytest.raises(PyPdfError, match=r"^Parent required to delete file from document\.$"):
attachment.delete()


def test_embedded_file__delete_known():
def test_embedded_file__delete_known() -> None:
writer = PdfWriter()
writer.add_blank_page(100, 100)
attachment = writer.add_attachment("test.txt", b"content")
Expand All @@ -424,7 +426,7 @@ def test_embedded_file__delete_known():
attachment.delete()


def test_embedded_file__delete__no_indirect_reference():
def test_embedded_file__delete__no_indirect_reference() -> None:
writer = PdfWriter()
writer.add_blank_page(100, 100)

Expand All @@ -441,7 +443,7 @@ def test_embedded_file__delete__no_indirect_reference():


@pytest.mark.enable_socket
def test_embedded_file__create__kids_based_name_tree():
def test_embedded_file__create__kids_based_name_tree() -> None:
"""Test for issue #3473."""
url = "https://github.com/user-attachments/files/18691309/embedded_files_kids.pdf"
name = "embedded_files_kids.pdf"
Expand Down Expand Up @@ -476,7 +478,7 @@ def test_embedded_file__create__kids_based_name_tree():
]


def test_embedded_file__create__neither_kids_nor_names():
def test_embedded_file__create__neither_kids_nor_names() -> None:
writer = PdfWriter()
writer.add_blank_page(100, 100)

Expand All @@ -488,7 +490,7 @@ def test_embedded_file__create__neither_kids_nor_names():
writer.add_attachment("test2.txt", b"content2")


def test_embedded_file__get_insertion_index():
def test_embedded_file__get_insertion_index() -> None:
# Empty list.
assert EmbeddedFile._get_insertion_index(ArrayObject(), "test.txt") == 0

Expand Down Expand Up @@ -549,7 +551,7 @@ def test_embedded_file__get_insertion_index():
) == 2


def test_embedded_file__order():
def test_embedded_file__order() -> None:
writer = PdfWriter()
writer.add_blank_page(100, 100)

Expand Down
6 changes: 3 additions & 3 deletions tests/generic/test_image_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tests import get_data_from_url


def test_is_followed_by_binary_data():
def test_is_followed_by_binary_data() -> None:
# Empty/too short stream.
stream = BytesIO()
assert not is_followed_by_binary_data(stream)
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_is_followed_by_binary_data():


@pytest.mark.enable_socket
def test_extract_inline_dct__early_end_of_file():
def test_extract_inline_dct__early_end_of_file() -> None:
url = "https://github.com/user-attachments/files/23056988/inline_dct__early_eof.pdf"
name = "inline_dct__early_eof.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
Expand All @@ -78,7 +78,7 @@ def test_extract_inline_dct__early_end_of_file():


@pytest.mark.enable_socket
def test_extract_inline_dct__multiple_eod():
def test_extract_inline_dct__multiple_eod() -> None:
url = "https://github.com/user-attachments/files/23900687/cedolini_esempio-1.pdf"
name = "issue3517.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
Expand Down
4 changes: 2 additions & 2 deletions tests/generic/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@pytest.mark.enable_socket
def test_extract_links__null_object_in_old_page():
def test_extract_links__null_object_in_old_page() -> None:
url = "https://github.com/user-attachments/files/25507697/sample.pdf"
name = "issue3656.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url=url, name=name)))
Expand All @@ -18,7 +18,7 @@ def test_extract_links__null_object_in_old_page():
writer.append(reader)


def test_extract_links(caplog):
def test_extract_links(caplog: pytest.LogCaptureFixture) -> None:
page1 = PageObject()
page2 = PageObject()

Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/test_example_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from tests import read_yaml_to_list_of_dicts


def test_consistency():
def test_consistency() -> None:
pdfs = read_yaml_to_list_of_dicts(Path(__file__).parent.parent / "example_files.yaml")

# Ensure the names are unique
Expand Down
8 changes: 4 additions & 4 deletions tests/scripts/test_make_release.py
Comment thread
stefan6419846 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
("# CHANGELOG #", "#"),
]
)
def test_strip_header(data, expected):
def test_strip_header(data: str, expected: str) -> None:
"""Removal of the 'CHANGELOG' header."""
make_release = pytest.importorskip("make_release")
assert make_release.strip_header(data) == expected


def test_get_git_commits_since_tag():
def test_get_git_commits_since_tag() -> None:
make_release = pytest.importorskip("make_release")

with open(COMMITS__VERSION_4_0_1, mode="rb") as commits, mock.patch(
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_get_git_commits_since_tag():
]


def test_get_formatted_changes():
def test_get_formatted_changes() -> None:
make_release = pytest.importorskip("make_release")

with open(COMMITS__VERSION_4_0_1, mode="rb") as commits, mock.patch(
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_get_formatted_changes():
)


def test_get_formatted_changes__other():
def test_get_formatted_changes__other() -> None:
Comment thread
iso-techdev marked this conversation as resolved.
make_release = pytest.importorskip("make_release")

changes = [
Expand Down
Loading