Skip to content

Commit

Permalink
TST: Reader and page attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Apr 28, 2022
1 parent eef03d9 commit 5dc9628
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from PyPDF2 import PdfFileReader
from PyPDF2.generic import RectangleObject

TESTS_ROOT = os.path.abspath(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(TESTS_ROOT)
Expand Down Expand Up @@ -92,3 +93,21 @@ def test_compress_content_streams(pdf_path, password):
reader.decrypt(password)
for page in reader.pages:
page.compressContentStreams()


def test_page_properties():
reader = PdfFileReader(os.path.join(RESOURCE_ROOT, "crazyones.pdf"))
page = reader.pages[0]
assert page.mediaBox == RectangleObject([0, 0, 612, 792])
assert page.cropBox == RectangleObject([0, 0, 612, 792])
assert page.bleedBox == RectangleObject([0, 0, 612, 792])
assert page.trimBox == RectangleObject([0, 0, 612, 792])
assert page.artBox == RectangleObject([0, 0, 612, 792])


def test_page_rotation_non90():
reader = PdfFileReader(os.path.join(RESOURCE_ROOT, "crazyones.pdf"))
page = reader.pages[0]
with pytest.raises(ValueError) as exc:
page.rotateClockwise(91)
assert exc.value.args[0] == "Rotation angle must be a multiple of 90"
5 changes: 4 additions & 1 deletion Tests/test_pagerange.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ def test_parse_filename_page_ranges(params, expected):


def test_parse_filename_page_ranges_err():
with pytest.raises(ValueError):
with pytest.raises(ValueError) as exc:
parse_filename_page_ranges(["1:5", "foo.pdf"])
assert (
exc.value.args[0] == "The first argument must be a filename, not a page range."
)


def test_page_range_help():
Expand Down
31 changes: 31 additions & 0 deletions Tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,34 @@ def test_PdfReaderDecryptWhenNoID():
ipdf = PdfFileReader(inputfile)
ipdf.decrypt("")
assert ipdf.getDocumentInfo() == {"/Producer": "European Patent Office"}


def test_reader_properties():
reader = PdfFileReader(os.path.join(RESOURCE_ROOT, "crazyones.pdf"))
assert reader.outlines == []
assert len(reader.pages) == 1
assert reader.pageLayout is None
assert reader.pageMode is None
assert reader.isEncrypted is False


def test_decode_permissions():
reader = PdfFileReader(os.path.join(RESOURCE_ROOT, "crazyones.pdf"))
base = {
"accessability": False,
"annotations": False,
"assemble": False,
"copy": False,
"forms": False,
"modify": False,
"print_high_quality": False,
"print": False,
}

print_ = base.copy()
print_["print"] = True
assert reader.decode_permissions(4) == print_

modify = base.copy()
modify["modify"] = True
assert reader.decode_permissions(8) == modify
6 changes: 6 additions & 0 deletions Tests/test_xmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ def test_regression_issue774():
cls = PyPDF2.xmp.XmpInformation
date = cls._converter_date("2021-04-28T12:23:34.123Z")
assert date.year == 2021
assert date.month == 4
assert date.day == 28
assert date.hour == 12
assert date.minute == 23
assert date.second == 34
assert date.microsecond == 123000

0 comments on commit 5dc9628

Please sign in to comment.