rect obj
This commit is contained in:
1 parent
3f5bac98b3
commit
e33d13a3e1
5 files changed
+145
-12
No files matched your search
+71
-1
@@ -1,3 +1,9 @@
|
||||
from decimal import Decimal
|
||||
from pdfmajor.document.exceptions import BrokenFilePDF, TooManyRectField
|
||||
from typing import List
|
||||
from pdfmajor.parser.objects.base import PDFObject
|
||||
from pdfmajor.parser.objects.collections import PDFArray
|
||||
from pdfmajor.document.structures import PDFRectangle
|
||||
from unittest import TestCase
|
||||
|
||||
from pdfmajor.document.PDFDocumentCatalog import PDFDocumentCatalog
|
||||
@@ -7,12 +13,13 @@ from pdfmajor.parser.objects.primitives import (
|
||||
PDFBoolean,
|
||||
PDFInteger,
|
||||
PDFName,
|
||||
PDFReal,
|
||||
PDFString,
|
||||
)
|
||||
from tests.util import all_pdf_files
|
||||
|
||||
|
||||
class Catalog(TestCase):
|
||||
class ParsingState(TestCase):
|
||||
def run_test(self, file_name: str, expcat: PDFDocumentCatalog):
|
||||
with all_pdf_files[file_name].get_window() as buffer:
|
||||
pdf = PDFParsingContext(buffer)
|
||||
@@ -77,3 +84,66 @@ class Catalog(TestCase):
|
||||
parser.get_catalog()
|
||||
self.assertEqual(len(parser.health_report), 0)
|
||||
parser.get_info()
|
||||
|
||||
|
||||
class Structures(TestCase):
|
||||
def run_rect_test(self, arr_vals: List[PDFObject], exprect: PDFRectangle):
|
||||
self.assertEqual(
|
||||
PDFRectangle.from_pdfarray(PDFArray.from_list(arr_vals)),
|
||||
exprect,
|
||||
)
|
||||
|
||||
def test_rect(self):
|
||||
self.run_rect_test(
|
||||
[
|
||||
PDFInteger(20, 0, 0),
|
||||
PDFInteger(10, 0, 0),
|
||||
PDFInteger(0, 0, 0),
|
||||
PDFInteger(3, 0, 0),
|
||||
],
|
||||
PDFRectangle(Decimal(20), Decimal(10), Decimal(0), Decimal(3)),
|
||||
)
|
||||
self.run_rect_test(
|
||||
[
|
||||
PDFReal(Decimal("0.23"), 0, 0),
|
||||
PDFInteger(10, 0, 0),
|
||||
PDFInteger(Decimal("3.3"), 0, 0),
|
||||
PDFInteger(3, 0, 0),
|
||||
],
|
||||
PDFRectangle(Decimal("0.23"), Decimal(10), Decimal("3.3"), Decimal(3)),
|
||||
)
|
||||
|
||||
def test_rect_fail(self):
|
||||
with self.assertRaises(BrokenFilePDF):
|
||||
PDFRectangle.from_pdfarray(
|
||||
PDFArray.from_list(
|
||||
[
|
||||
PDFString("h0", 0, 0),
|
||||
PDFString("h0", 0, 0),
|
||||
PDFString("h0", 0, 0),
|
||||
PDFString("h0", 0, 0),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
with self.assertRaises(TooManyRectField):
|
||||
PDFRectangle.from_pdfarray(
|
||||
PDFArray.from_list(
|
||||
[
|
||||
PDFInteger(3, 0, 0),
|
||||
PDFInteger(3, 0, 0),
|
||||
PDFInteger(3, 0, 0),
|
||||
PDFInteger(3, 0, 0),
|
||||
PDFInteger(3, 0, 0),
|
||||
]
|
||||
)
|
||||
)
|
||||
with self.assertRaises(BrokenFilePDF):
|
||||
PDFRectangle.from_pdfarray(
|
||||
PDFArray.from_list(
|
||||
[
|
||||
PDFInteger(3, 0, 0),
|
||||
PDFInteger(3, 0, 0),
|
||||
]
|
||||
)
|
||||
)
|
||||
Reference in new issue
Block a user