diff --git a/Tests/test_page.py b/Tests/test_page.py index 03709176a..8c4edcd14 100644 --- a/Tests/test_page.py +++ b/Tests/test_page.py @@ -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) @@ -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" diff --git a/Tests/test_pagerange.py b/Tests/test_pagerange.py index 801f5b08d..4fffe238c 100644 --- a/Tests/test_pagerange.py +++ b/Tests/test_pagerange.py @@ -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(): diff --git a/Tests/test_reader.py b/Tests/test_reader.py index 45769f039..dcef0f471 100644 --- a/Tests/test_reader.py +++ b/Tests/test_reader.py @@ -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 diff --git a/Tests/test_xmp.py b/Tests/test_xmp.py index 70bd359ca..a477717a6 100644 --- a/Tests/test_xmp.py +++ b/Tests/test_xmp.py @@ -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