Skip to content

Commit

Permalink
improve pageobjects testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Sep 15, 2022
1 parent 3f03597 commit d2cfcc9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion tests/helpers/test_opener.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_open_invalid():

def test_object_hierarchy():

pdf = pdfium.PdfDocument(TestFiles.empty)
pdf = pdfium.PdfDocument(TestFiles.images)
assert isinstance(pdf, pdfium.PdfDocument)
assert isinstance(pdf.raw, pdfium.FPDF_DOCUMENT)

Expand All @@ -211,6 +211,12 @@ def test_object_hierarchy():
assert isinstance(page.raw, pdfium.FPDF_PAGE)
assert page.pdf is pdf

pageobj = next(page.get_objects())
assert isinstance(pageobj, pdfium.PdfPageObject)
assert isinstance(pageobj.raw, pdfium.FPDF_PAGEOBJECT)
assert isinstance(pageobj.type, int)
assert pageobj.page is page

textpage = page.get_textpage()
assert isinstance(textpage, pdfium.PdfTextPage)
assert isinstance(textpage.raw, pdfium.FPDF_TEXTPAGE)
Expand Down
8 changes: 7 additions & 1 deletion tests/helpers/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest
import pypdfium2 as pdfium
from pypdfium2._helpers._utils import ObjtypeToName
from ..conftest import TestFiles


Expand Down Expand Up @@ -52,7 +53,12 @@ def test_pageobjects():
pdf = pdfium.PdfDocument(TestFiles.images)
page = pdf.get_page(0)

images = [obj for obj in page.get_objects() if obj.type == pdfium.FPDF_PAGEOBJ_IMAGE]
images = []
for obj in page.get_objects():
assert obj.type in ObjtypeToName.keys()
if obj.type == pdfium.FPDF_PAGEOBJ_IMAGE:
assert obj.level == 0
images.append(obj)
assert len(images) == 3

positions = [img.get_pos() for img in images]
Expand Down

0 comments on commit d2cfcc9

Please sign in to comment.