Skip to content

Commit

Permalink
improve coverage for cases where the loop bodies are skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan6419846 authored Mar 31, 2024
1 parent df7f552 commit 19471bd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/test_page_labels.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Test the pypdf._page_labels module."""
from io import BytesIO
from pathlib import Path

import pytest

from pypdf import PdfReader
from pypdf._page_labels import (
get_label_from_nums,
index2label,
number2lowercase_letter,
number2lowercase_roman_numeral,
Expand All @@ -15,6 +17,7 @@
nums_next,
)
from pypdf.generic import (
ArrayObject,
DictionaryObject,
NameObject,
NullObject,
Expand All @@ -23,6 +26,10 @@

from . import get_data_from_url

TESTS_ROOT = Path(__file__).parent.resolve()
PROJECT_ROOT = TESTS_ROOT.parent
RESOURCE_ROOT = PROJECT_ROOT / "resources"


@pytest.mark.parametrize(
("number", "expected"),
Expand Down Expand Up @@ -119,3 +126,19 @@ def test_index2label_kids():
# whole list itself here.
expected.remove(x)
assert r.page_labels == expected


def test_get_label_from_nums__empty_nums_list():
dictionary_object = DictionaryObject()
dictionary_object[NameObject("/Nums")] = ArrayObject()
assert get_label_from_nums(dictionary_object, 13) == "14"


def test_index2label__empty_kids_list():
reader = PdfReader(RESOURCE_ROOT / "crazyones.pdf")
number_tree = DictionaryObject()
number_tree[NameObject("/Kids")] = ArrayObject()
root = reader.root_object
root[NameObject("/PageLabels")] = number_tree

assert index2label(reader, 42) == "43"

0 comments on commit 19471bd

Please sign in to comment.