2020-05-23 16:04:34 +00:00
|
|
|
import warnings
|
2016-11-08 19:01:11 +00:00
|
|
|
|
2019-10-26 16:42:33 +00:00
|
|
|
from helpers import absolute_sample_path
|
2020-10-26 09:10:11 +00:00
|
|
|
from tempfilepath import TemporaryFilePath
|
2020-05-23 16:04:34 +00:00
|
|
|
from pdfminer.pdfdocument import PDFNoValidXRefWarning
|
2019-10-26 16:42:33 +00:00
|
|
|
from tools import dumppdf
|
2014-09-03 11:17:41 +00:00
|
|
|
|
|
|
|
|
2019-10-26 16:42:33 +00:00
|
|
|
def run(filename, options=None):
|
|
|
|
absolute_path = absolute_sample_path(filename)
|
2020-10-26 09:10:11 +00:00
|
|
|
with TemporaryFilePath() as output_file_name:
|
2019-10-26 16:42:33 +00:00
|
|
|
if options:
|
2020-10-26 09:10:11 +00:00
|
|
|
s = 'dumppdf -o %s %s %s' % (output_file_name,
|
2019-12-29 20:20:20 +00:00
|
|
|
options, absolute_path)
|
2019-10-26 16:42:33 +00:00
|
|
|
else:
|
2020-10-26 09:10:11 +00:00
|
|
|
s = 'dumppdf -o %s %s' % (output_file_name, absolute_path)
|
|
|
|
|
2019-10-27 20:40:04 +00:00
|
|
|
dumppdf.main(s.split(' ')[1:])
|
2014-09-03 11:17:41 +00:00
|
|
|
|
|
|
|
|
2014-09-04 07:36:19 +00:00
|
|
|
class TestDumpPDF():
|
2020-05-23 16:04:34 +00:00
|
|
|
def test_simple1(self):
|
|
|
|
"""dumppdf.py simple1.pdf raises a warning because it has no xref"""
|
|
|
|
with warnings.catch_warnings(record=True) as ws:
|
|
|
|
run('simple1.pdf', '-t -a')
|
|
|
|
assert any(w.category == PDFNoValidXRefWarning for w in ws)
|
|
|
|
|
|
|
|
def test_simple2(self):
|
2019-10-26 16:42:33 +00:00
|
|
|
run('simple2.pdf', '-t -a')
|
2020-05-23 16:04:34 +00:00
|
|
|
|
|
|
|
def test_jo(self):
|
|
|
|
run('jo.pdf', '-t -a')
|
|
|
|
|
|
|
|
def test_simple3(self):
|
|
|
|
"""dumppdf.py simple3.pdf raises a warning because it has no xref"""
|
|
|
|
with warnings.catch_warnings(record=True) as ws:
|
|
|
|
run('simple3.pdf', '-t -a')
|
|
|
|
assert any(w.category == PDFNoValidXRefWarning for w in ws)
|
2019-10-26 16:42:33 +00:00
|
|
|
|
2014-09-03 11:17:41 +00:00
|
|
|
def test_2(self):
|
2019-10-26 16:42:33 +00:00
|
|
|
run('nonfree/dmca.pdf', '-t -a')
|
|
|
|
|
2014-09-03 11:17:41 +00:00
|
|
|
def test_3(self):
|
2019-10-26 16:42:33 +00:00
|
|
|
run('nonfree/f1040nr.pdf')
|
2014-09-03 11:17:41 +00:00
|
|
|
|
|
|
|
def test_4(self):
|
2019-10-26 16:42:33 +00:00
|
|
|
run('nonfree/i1040nr.pdf')
|
|
|
|
|
2014-09-03 11:17:41 +00:00
|
|
|
def test_5(self):
|
2019-10-26 16:42:33 +00:00
|
|
|
run('nonfree/kampo.pdf', '-t -a')
|
2014-09-03 11:17:41 +00:00
|
|
|
|
2019-10-26 16:42:33 +00:00
|
|
|
def test_6(self):
|
|
|
|
run('nonfree/naacl06-shinyama.pdf', '-t -a')
|