added test for warnings
This commit is contained in:
1 parent
f6b3252088
commit
54179b7dd1
4 files changed
+22
-7
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
from typing import BinaryIO, Iterator, List, Optional
|
||||
|
||||
@@ -60,8 +61,8 @@ class PDFDocument:
|
||||
yield page
|
||||
self.__processed_pages_done = True
|
||||
if len(self.__processed_pages) != self.num_pages:
|
||||
print(
|
||||
"WARN! number of pages proceseed with iter_pages did not match number of pages specified by the document's metadata!"
|
||||
warnings.warn(
|
||||
"Number of pages proceseed with iter_pages did not match number of pages specified by the document's metadata!"
|
||||
f"\n --> expected pages = {self.num_pages}"
|
||||
f"\n --> found pages = {len(self.__processed_pages)}"
|
||||
)
|
||||
|
||||
Binary file not shown.
+14
-5
@@ -1,3 +1,4 @@
|
||||
import warnings
|
||||
from decimal import Decimal
|
||||
from typing import List
|
||||
from unittest import TestCase
|
||||
@@ -20,7 +21,7 @@ from pdfmajor.parser.objects.primitives import (
|
||||
PDFReal,
|
||||
PDFString,
|
||||
)
|
||||
from tests.util import all_pdf_files
|
||||
from tests.util import all_corrupt_pdf_files, all_pdf_files
|
||||
|
||||
|
||||
class ParsingState(TestCase):
|
||||
@@ -138,11 +139,19 @@ class ParsingState(TestCase):
|
||||
actual_pages = len(list(parser.iter_pages()))
|
||||
self.assertEqual(actual_pages, parser.num_pages)
|
||||
|
||||
def test_doc(self):
|
||||
with all_pdf_files["bad-unicode.pdf"].get_window() as buffer:
|
||||
# def test_doc(self):
|
||||
# with all_pdf_files["bad-unicode.pdf"].get_window() as buffer:
|
||||
# parser = PDFDocument(buffer)
|
||||
# actual_pages = len(list(parser.iter_pages()))
|
||||
# self.assertEqual(actual_pages, parser.num_pages)
|
||||
|
||||
def test_warning_pagecount(self):
|
||||
with all_corrupt_pdf_files["bad-page-count.pdf"].get_window() as buffer:
|
||||
parser = PDFDocument(buffer)
|
||||
actual_pages = len(list(parser.iter_pages()))
|
||||
self.assertEqual(actual_pages, parser.num_pages)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
actual_pages = len(list(parser.iter_pages()))
|
||||
self.assertEqual(len(w), 1)
|
||||
self.assertNotEqual(actual_pages, parser.num_pages)
|
||||
|
||||
|
||||
class Structures(TestCase):
|
||||
|
||||
@@ -8,3 +8,8 @@ all_pdf_files = {
|
||||
file_path.name: BufferStream(file_path.open("rb"))
|
||||
for file_path in (CURRENT_FOLDER / "samples" / "pdf").iterdir()
|
||||
}
|
||||
|
||||
all_corrupt_pdf_files = {
|
||||
file_path.name: BufferStream(file_path.open("rb"))
|
||||
for file_path in (CURRENT_FOLDER / "samples" / "corrupt-pdfs").iterdir()
|
||||
}
|
||||
Reference in new issue
Block a user