2014-09-05 13:36:24 +04:00
|
|
|
from helper import unittest, PillowTestCase, hopper
|
2015-09-29 15:51:52 +03:00
|
|
|
from PIL import Image
|
2014-06-10 13:10:47 +04:00
|
|
|
import os.path
|
2014-05-11 10:01:09 +04:00
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestFilePdf(PillowTestCase):
|
2014-05-11 18:16:13 +04:00
|
|
|
|
2015-09-29 15:51:52 +03:00
|
|
|
def helper_save_as_pdf(self, mode, save_all=False):
|
2014-06-10 13:10:47 +04:00
|
|
|
# Arrange
|
2014-09-05 13:36:24 +04:00
|
|
|
im = hopper(mode)
|
2014-06-10 13:10:47 +04:00
|
|
|
outfile = self.tempfile("temp_" + mode + ".pdf")
|
2014-05-12 15:30:03 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# Act
|
2015-09-29 15:51:52 +03:00
|
|
|
if save_all:
|
|
|
|
im.save(outfile, save_all=True)
|
|
|
|
else:
|
|
|
|
im.save(outfile)
|
2014-05-11 18:35:49 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# Assert
|
|
|
|
self.assertTrue(os.path.isfile(outfile))
|
|
|
|
self.assertGreater(os.path.getsize(outfile), 0)
|
2014-05-11 18:35:49 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_monochrome(self):
|
|
|
|
# Arrange
|
|
|
|
mode = "1"
|
2014-05-11 18:16:13 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# Act / Assert
|
|
|
|
self.helper_save_as_pdf(mode)
|
2014-05-11 18:16:13 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_greyscale(self):
|
|
|
|
# Arrange
|
|
|
|
mode = "L"
|
2014-05-11 18:16:13 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# Act / Assert
|
|
|
|
self.helper_save_as_pdf(mode)
|
2014-05-11 18:16:13 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_rgb(self):
|
|
|
|
# Arrange
|
|
|
|
mode = "RGB"
|
2014-05-11 18:16:13 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# Act / Assert
|
|
|
|
self.helper_save_as_pdf(mode)
|
2014-05-11 18:16:13 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_p_mode(self):
|
|
|
|
# Arrange
|
|
|
|
mode = "P"
|
2014-05-12 15:45:54 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# Act / Assert
|
|
|
|
self.helper_save_as_pdf(mode)
|
2014-05-11 18:16:13 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_cmyk_mode(self):
|
|
|
|
# Arrange
|
|
|
|
mode = "CMYK"
|
2014-05-11 18:16:13 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# Act / Assert
|
|
|
|
self.helper_save_as_pdf(mode)
|
2014-05-11 18:16:13 +04:00
|
|
|
|
2015-07-03 08:03:25 +03:00
|
|
|
def test_unsupported_mode(self):
|
|
|
|
im = hopper("LA")
|
|
|
|
outfile = self.tempfile("temp_LA.pdf")
|
|
|
|
|
|
|
|
self.assertRaises(ValueError, lambda: im.save(outfile))
|
|
|
|
|
2015-09-29 15:51:52 +03:00
|
|
|
def test_save_all(self):
|
|
|
|
# Single frame image
|
|
|
|
self.helper_save_as_pdf("RGB", save_all=True)
|
|
|
|
|
|
|
|
# Multiframe image
|
|
|
|
im = Image.open("Tests/images/dispose_bgnd.gif")
|
|
|
|
|
|
|
|
outfile = self.tempfile('temp.pdf')
|
|
|
|
im.save(outfile, save_all=True)
|
|
|
|
|
|
|
|
self.assertTrue(os.path.isfile(outfile))
|
|
|
|
self.assertGreater(os.path.getsize(outfile), 0)
|
|
|
|
|
2014-05-11 18:16:13 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
2014-05-11 18:16:13 +04:00
|
|
|
|
2014-05-11 10:01:09 +04:00
|
|
|
# End of file
|