pdfminer.six/tests/test_tools_dumppdf.py

52 lines
1.4 KiB
Python
Raw Normal View History

from shutil import rmtree
from tempfile import NamedTemporaryFile, mkdtemp
from helpers import absolute_sample_path
from tools import dumppdf
2014-09-03 11:17:41 +00:00
def run(filename, options=None):
absolute_path = absolute_sample_path(filename)
with NamedTemporaryFile() as output_file:
if options:
Enforce pep8 coding-style (#345) * Code Refractor: Use code-style enforcement #312 * Add flake8 to travis-ci * Remove python 2 3 comment on six library. 891 errors > 870 errors. * Remove class and functions comments that consist of just the name. 870 errors > 855 errors. * Fix flake8 errors in pdftypes.py. 855 errors > 833 errors. * Moving flake8 testing from .travis.yml to tox.ini to ensure local testing before commiting * Cleanup pdfinterp.py and add documentation from PDF Reference * Cleanup pdfpage.py * Cleanup pdffont.py * Clean psparser.py * Cleanup high_level.py * Cleanup layout.py * Cleanup pdfparser.py * Cleanup pdfcolor.py * Cleanup rijndael.py * Cleanup converter.py * Rename klass to cls if it is the class variable, to be more consistent with standard practice * Cleanup cmap.py * Cleanup pdfdevice.py * flake8 ignore fontmetrics.py * Cleanup test_pdfminer_psparser.py * Fix flake8 in pdfdocument.py; 339 errors to go * Fix flake8 utils.py; 326 errors togo * pep8 correction for few files in /tools/ 328 > 160 to go (#342) * pep8 correction for few files in /tools/ 328 > 160 to go * pep8 correction: 160 > 5 to go * Fix ascii85.py errors * Fix error in getting index from target that does not exists * Remove commented print lines * Fix flake8 error in pdfinterp.py * Fix python2 specific error by removing argument from print statement * Ignore invalid python2 syntax * Update contributing.md * Added changelog * Remove unused import Co-authored-by: Fakabbir Amin <f4amin@gmail.com>
2019-12-29 20:20:20 +00:00
s = 'dumppdf -o %s %s %s' % (output_file.name,
options, absolute_path)
else:
s = 'dumppdf -o %s %s' % (output_file.name, absolute_path)
dumppdf.main(s.split(' ')[1:])
2014-09-03 11:17:41 +00:00
2014-09-04 07:36:19 +00:00
class TestDumpPDF():
2014-09-03 11:17:41 +00:00
def test_1(self):
run('jo.pdf', '-t -a')
run('simple1.pdf', '-t -a')
run('simple2.pdf', '-t -a')
run('simple3.pdf', '-t -a')
2014-09-03 11:17:41 +00:00
def test_2(self):
run('nonfree/dmca.pdf', '-t -a')
2014-09-03 11:17:41 +00:00
def test_3(self):
run('nonfree/f1040nr.pdf')
2014-09-03 11:17:41 +00:00
def test_4(self):
run('nonfree/i1040nr.pdf')
2014-09-03 11:17:41 +00:00
def test_5(self):
run('nonfree/kampo.pdf', '-t -a')
2014-09-03 11:17:41 +00:00
def test_6(self):
run('nonfree/naacl06-shinyama.pdf', '-t -a')
def test_embedded_font_filename(self):
"""If UF font file name does not exist, then F should be used
Related issue: https://github.com/pdfminer/pdfminer.six/issues/152
"""
output_dir = mkdtemp()
try:
run('contrib/issue-00152-embedded-pdf.pdf',
'--extract-embedded %s' % output_dir)
finally:
rmtree(output_dir)