-
Notifications
You must be signed in to change notification settings - Fork 724
/
Copy pathtest_oss_fuzz.py
executable file
·40 lines (33 loc) · 1.2 KB
/
test_oss_fuzz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
import logging
import os
import unittest
from pathlib import Path
import pdfplumber
from pdfplumber.utils.exceptions import MalformedPDFException, PdfminerException
logging.disable(logging.ERROR)
HERE = Path(os.path.abspath(os.path.dirname(__file__)))
ACCEPTABLE_EXCEPTIONS = (MalformedPDFException, PdfminerException)
class Test(unittest.TestCase):
def test_load(self):
def test_conversions(pdf):
methods = [pdf.to_dict, pdf.to_json, pdf.to_csv, pdf.pages[0].to_image]
for method in methods:
try:
method()
except ACCEPTABLE_EXCEPTIONS:
continue
except Exception as e:
print(f"Failed on: {path.name}")
raise e
paths = sorted((HERE / "pdfs/from-oss-fuzz/load/").glob("*.pdf"))
for path in paths:
try:
with pdfplumber.open(path) as pdf:
assert pdf.pages
test_conversions(pdf)
except ACCEPTABLE_EXCEPTIONS:
continue
except Exception as e:
print(f"Failed on: {path.name}")
raise e