Skip to content

Commit

Permalink
adding python-libtiff
Browse files Browse the repository at this point in the history
paramaterize tests
  • Loading branch information
AddisonSchiller committed Nov 16, 2017
1 parent 114c492 commit 36c3465
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 37 deletions.
4 changes: 3 additions & 1 deletion mfr/extensions/pdf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@

EXPORT_TYPE = config.get('EXPORT_TYPE', 'pdf')
EXPORT_MAXIMUM_SIZE = config.get('EXPORT_MAXIMUM_SIZE', '1200x1200')
EXPORT_EXCLUSIONS = config.get('EXPORT_EXCLUSIONS', ['.pdf', ])

# supports multiple files in the form of a space separated string
EXPORT_EXCLUSIONS = config.get('EXPORT_EXCLUSIONS', '.pdf').split(' ')
EXPORT_MAX_PAGES = int(config.get('EXPORT_MAX_PAGES', 40))
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pydocx==0.7.0
# Image
Pillow==2.8.2
psd-tools==1.4
# This should enhance Pillows ability to work with tif files, but it may not do anything
libtiff==0.4.1

# IPython
ipython==5.2.2
Expand Down
43 changes: 7 additions & 36 deletions tests/extensions/pdf/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,13 @@ class TestPdfExporter:
`report-lab`. Instead we will manually open them and just check the signature.
'''

def test_single_page_tiff(self, directory):
source_file_path = os.path.join(BASE, 'files', 'test.tif')
output_file_path = os.path.join(directory, 'test.{}'.format(settings.EXPORT_TYPE))
format = '{}.{}'.format(settings.EXPORT_MAXIMUM_SIZE, settings.EXPORT_TYPE)
exporter = PdfExporter(source_file_path=source_file_path, ext='.tif',
output_file_path=output_file_path, format=format)

assert not os.path.exists(output_file_path)

exporter.export()

assert os.path.exists(output_file_path)
# Open file to check that the exported PDF contains the proper signature
with open(output_file_path, 'rb') as file:
# the first 4 bytes contain the signature
assert binascii.hexlify(file.read(4)) == PDF_SIG

def test_multi_page_tiff(self, directory):
source_file_path = os.path.join(BASE, 'files', 'test_multipage.tif')
output_file_path = os.path.join(directory, 'test.{}'.format(settings.EXPORT_TYPE))
format = '{}.{}'.format(settings.EXPORT_MAXIMUM_SIZE, settings.EXPORT_TYPE)
exporter = PdfExporter(source_file_path=source_file_path, ext='.tif',
output_file_path=output_file_path, format=format)

assert not os.path.exists(output_file_path)

exporter.export()

assert os.path.exists(output_file_path)
# Open file to check that the exported PDF contains the proper signature
with open(output_file_path, 'rb') as file:
# the first 4 bytes contain the signature
assert binascii.hexlify(file.read(4)) == PDF_SIG

def test_ratio_tiff(self, directory):
source_file_path = os.path.join(BASE, 'files', 'test_ratio.tif')
@pytest.mark.parametrize("file_name", [
('test.tif'),
('test_multipage.tif'),
('test_ratio.tif'),
])
def test_single_page_tiff(self, directory, file_name):
source_file_path = os.path.join(BASE, 'files', file_name)
output_file_path = os.path.join(directory, 'test.{}'.format(settings.EXPORT_TYPE))
format = '{}.{}'.format(settings.EXPORT_MAXIMUM_SIZE, settings.EXPORT_TYPE)
exporter = PdfExporter(source_file_path=source_file_path, ext='.tif',
Expand Down

0 comments on commit 36c3465

Please sign in to comment.