Allow EPS tests that do not require Ghostscript

This commit is contained in:
Andrew Murray 2018-12-30 20:50:09 +11:00
parent 332f634460
commit 0c0f769351

View File

@ -3,6 +3,8 @@ from helper import unittest, PillowTestCase, hopper
from PIL import Image, EpsImagePlugin from PIL import Image, EpsImagePlugin
import io import io
HAS_GHOSTSCRIPT = EpsImagePlugin.has_ghostscript()
# Our two EPS test files (they are identical except for their bounding boxes) # Our two EPS test files (they are identical except for their bounding boxes)
file1 = "Tests/images/zero_bb.eps" file1 = "Tests/images/zero_bb.eps"
file2 = "Tests/images/non_zero_bb.eps" file2 = "Tests/images/non_zero_bb.eps"
@ -20,10 +22,7 @@ file3 = "Tests/images/binary_preview_map.eps"
class TestFileEps(PillowTestCase): class TestFileEps(PillowTestCase):
def setUp(self): @unittest.skipUnless(HAS_GHOSTSCRIPT, "Ghostscript not available")
if not EpsImagePlugin.has_ghostscript():
self.skipTest("Ghostscript not available")
def test_sanity(self): def test_sanity(self):
# Regular scale # Regular scale
image1 = Image.open(file1) image1 = Image.open(file1)
@ -57,6 +56,7 @@ class TestFileEps(PillowTestCase):
self.assertRaises(SyntaxError, self.assertRaises(SyntaxError,
EpsImagePlugin.EpsImageFile, invalid_file) EpsImagePlugin.EpsImageFile, invalid_file)
@unittest.skipUnless(HAS_GHOSTSCRIPT, "Ghostscript not available")
def test_cmyk(self): def test_cmyk(self):
cmyk_image = Image.open("Tests/images/pil_sample_cmyk.eps") cmyk_image = Image.open("Tests/images/pil_sample_cmyk.eps")
@ -71,6 +71,7 @@ class TestFileEps(PillowTestCase):
target = Image.open('Tests/images/pil_sample_rgb.jpg') target = Image.open('Tests/images/pil_sample_rgb.jpg')
self.assert_image_similar(cmyk_image, target, 10) self.assert_image_similar(cmyk_image, target, 10)
@unittest.skipUnless(HAS_GHOSTSCRIPT, "Ghostscript not available")
def test_showpage(self): def test_showpage(self):
# See https://github.com/python-pillow/Pillow/issues/2615 # See https://github.com/python-pillow/Pillow/issues/2615
plot_image = Image.open("Tests/images/reqd_showpage.eps") plot_image = Image.open("Tests/images/reqd_showpage.eps")
@ -81,18 +82,21 @@ class TestFileEps(PillowTestCase):
# fonts could be slightly different # fonts could be slightly different
self.assert_image_similar(plot_image, target, 6) self.assert_image_similar(plot_image, target, 6)
@unittest.skipUnless(HAS_GHOSTSCRIPT, "Ghostscript not available")
def test_file_object(self): def test_file_object(self):
# issue 479 # issue 479
image1 = Image.open(file1) image1 = Image.open(file1)
with open(self.tempfile('temp_file.eps'), 'wb') as fh: with open(self.tempfile('temp_file.eps'), 'wb') as fh:
image1.save(fh, 'EPS') image1.save(fh, 'EPS')
@unittest.skipUnless(HAS_GHOSTSCRIPT, "Ghostscript not available")
def test_iobase_object(self): def test_iobase_object(self):
# issue 479 # issue 479
image1 = Image.open(file1) image1 = Image.open(file1)
with io.open(self.tempfile('temp_iobase.eps'), 'wb') as fh: with io.open(self.tempfile('temp_iobase.eps'), 'wb') as fh:
image1.save(fh, 'EPS') image1.save(fh, 'EPS')
@unittest.skipUnless(HAS_GHOSTSCRIPT, "Ghostscript not available")
def test_bytesio_object(self): def test_bytesio_object(self):
with open(file1, 'rb') as f: with open(file1, 'rb') as f:
img_bytes = io.BytesIO(f.read()) img_bytes = io.BytesIO(f.read())
@ -109,6 +113,7 @@ class TestFileEps(PillowTestCase):
tmpfile = self.tempfile('temp.eps') tmpfile = self.tempfile('temp.eps')
self.assertRaises(ValueError, im.save, tmpfile) self.assertRaises(ValueError, im.save, tmpfile)
@unittest.skipUnless(HAS_GHOSTSCRIPT, "Ghostscript not available")
def test_render_scale1(self): def test_render_scale1(self):
# We need png support for these render test # We need png support for these render test
codecs = dir(Image.core) codecs = dir(Image.core)
@ -129,6 +134,7 @@ class TestFileEps(PillowTestCase):
image2_scale1_compare.load() image2_scale1_compare.load()
self.assert_image_similar(image2_scale1, image2_scale1_compare, 10) self.assert_image_similar(image2_scale1, image2_scale1_compare, 10)
@unittest.skipUnless(HAS_GHOSTSCRIPT, "Ghostscript not available")
def test_render_scale2(self): def test_render_scale2(self):
# We need png support for these render test # We need png support for these render test
codecs = dir(Image.core) codecs = dir(Image.core)
@ -149,6 +155,7 @@ class TestFileEps(PillowTestCase):
image2_scale2_compare.load() image2_scale2_compare.load()
self.assert_image_similar(image2_scale2, image2_scale2_compare, 10) self.assert_image_similar(image2_scale2, image2_scale2_compare, 10)
@unittest.skipUnless(HAS_GHOSTSCRIPT, "Ghostscript not available")
def test_resize(self): def test_resize(self):
# Arrange # Arrange
image1 = Image.open(file1) image1 = Image.open(file1)
@ -166,6 +173,7 @@ class TestFileEps(PillowTestCase):
self.assertEqual(image2.size, new_size) self.assertEqual(image2.size, new_size)
self.assertEqual(image3.size, new_size) self.assertEqual(image3.size, new_size)
@unittest.skipUnless(HAS_GHOSTSCRIPT, "Ghostscript not available")
def test_thumbnail(self): def test_thumbnail(self):
# Issue #619 # Issue #619
# Arrange # Arrange
@ -233,6 +241,7 @@ class TestFileEps(PillowTestCase):
img = Image.open(filename) img = Image.open(filename)
self.assertEqual(img.mode, "RGB") self.assertEqual(img.mode, "RGB")
@unittest.skipUnless(HAS_GHOSTSCRIPT, "Ghostscript not available")
def test_emptyline(self): def test_emptyline(self):
# Test file includes an empty line in the header data # Test file includes an empty line in the header data
emptyline_file = "Tests/images/zero_bb_emptyline.eps" emptyline_file = "Tests/images/zero_bb_emptyline.eps"