This commit is contained in:
hugovk 2014-05-08 11:43:04 +03:00
parent 73eafbb55f
commit 134295bfd4

View File

@ -1,25 +1,25 @@
from tester import * from tester import *
from PIL import Image, EpsImagePlugin from PIL import Image, EpsImagePlugin
import sys
import io import io
if not EpsImagePlugin.has_ghostscript(): if not EpsImagePlugin.has_ghostscript():
skip() skip()
#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"
#Due to palletization, we'll need to convert these to RGB after load # Due to palletization, we'll need to convert these to RGB after load
file1_compare = "Tests/images/zero_bb.png" file1_compare = "Tests/images/zero_bb.png"
file1_compare_scale2 = "Tests/images/zero_bb_scale2.png" file1_compare_scale2 = "Tests/images/zero_bb_scale2.png"
file2_compare = "Tests/images/non_zero_bb.png" file2_compare = "Tests/images/non_zero_bb.png"
file2_compare_scale2 = "Tests/images/non_zero_bb_scale2.png" file2_compare_scale2 = "Tests/images/non_zero_bb_scale2.png"
def test_sanity(): def test_sanity():
#Regular scale # Regular scale
image1 = Image.open(file1) image1 = Image.open(file1)
image1.load() image1.load()
assert_equal(image1.mode, "RGB") assert_equal(image1.mode, "RGB")
@ -32,7 +32,7 @@ def test_sanity():
assert_equal(image2.size, (360, 252)) assert_equal(image2.size, (360, 252))
assert_equal(image2.format, "EPS") assert_equal(image2.format, "EPS")
#Double scale # Double scale
image1_scale2 = Image.open(file1) image1_scale2 = Image.open(file1)
image1_scale2.load(scale=2) image1_scale2.load(scale=2)
assert_equal(image1_scale2.mode, "RGB") assert_equal(image1_scale2.mode, "RGB")
@ -45,54 +45,76 @@ def test_sanity():
assert_equal(image2_scale2.size, (720, 504)) assert_equal(image2_scale2.size, (720, 504))
assert_equal(image2_scale2.format, "EPS") assert_equal(image2_scale2.format, "EPS")
def test_file_object(): def test_file_object():
#issue 479 # issue 479
image1 = Image.open(file1) image1 = Image.open(file1)
with open(tempfile('temp_file.eps'), 'wb') as fh: with open(tempfile('temp_file.eps'), 'wb') as fh:
image1.save(fh, 'EPS') image1.save(fh, 'EPS')
def test_iobase_object(): def test_iobase_object():
#issue 479 # issue 479
image1 = Image.open(file1) image1 = Image.open(file1)
with io.open(tempfile('temp_iobase.eps'), 'wb') as fh: with io.open(tempfile('temp_iobase.eps'), 'wb') as fh:
image1.save(fh, 'EPS') image1.save(fh, 'EPS')
def test_render_scale1(): def test_render_scale1():
#We need png support for these render test # We need png support for these render test
codecs = dir(Image.core) codecs = dir(Image.core)
if "zip_encoder" not in codecs or "zip_decoder" not in codecs: if "zip_encoder" not in codecs or "zip_decoder" not in codecs:
skip("zip/deflate support not available") skip("zip/deflate support not available")
#Zero bounding box # Zero bounding box
image1_scale1 = Image.open(file1) image1_scale1 = Image.open(file1)
image1_scale1.load() image1_scale1.load()
image1_scale1_compare = Image.open(file1_compare).convert("RGB") image1_scale1_compare = Image.open(file1_compare).convert("RGB")
image1_scale1_compare.load() image1_scale1_compare.load()
assert_image_similar(image1_scale1, image1_scale1_compare, 5) assert_image_similar(image1_scale1, image1_scale1_compare, 5)
#Non-Zero bounding box # Non-Zero bounding box
image2_scale1 = Image.open(file2) image2_scale1 = Image.open(file2)
image2_scale1.load() image2_scale1.load()
image2_scale1_compare = Image.open(file2_compare).convert("RGB") image2_scale1_compare = Image.open(file2_compare).convert("RGB")
image2_scale1_compare.load() image2_scale1_compare.load()
assert_image_similar(image2_scale1, image2_scale1_compare, 10) assert_image_similar(image2_scale1, image2_scale1_compare, 10)
def test_render_scale2(): def test_render_scale2():
#We need png support for these render test # We need png support for these render test
codecs = dir(Image.core) codecs = dir(Image.core)
if "zip_encoder" not in codecs or "zip_decoder" not in codecs: if "zip_encoder" not in codecs or "zip_decoder" not in codecs:
skip("zip/deflate support not available") skip("zip/deflate support not available")
#Zero bounding box # Zero bounding box
image1_scale2 = Image.open(file1) image1_scale2 = Image.open(file1)
image1_scale2.load(scale=2) image1_scale2.load(scale=2)
image1_scale2_compare = Image.open(file1_compare_scale2).convert("RGB") image1_scale2_compare = Image.open(file1_compare_scale2).convert("RGB")
image1_scale2_compare.load() image1_scale2_compare.load()
assert_image_similar(image1_scale2, image1_scale2_compare, 5) assert_image_similar(image1_scale2, image1_scale2_compare, 5)
#Non-Zero bounding box # Non-Zero bounding box
image2_scale2 = Image.open(file2) image2_scale2 = Image.open(file2)
image2_scale2.load(scale=2) image2_scale2.load(scale=2)
image2_scale2_compare = Image.open(file2_compare_scale2).convert("RGB") image2_scale2_compare = Image.open(file2_compare_scale2).convert("RGB")
image2_scale2_compare.load() image2_scale2_compare.load()
assert_image_similar(image2_scale2, image2_scale2_compare, 10) assert_image_similar(image2_scale2, image2_scale2_compare, 10)
def test_resize():
# Arrange
image1 = Image.open(file1)
image2 = Image.open(file2)
new_size = (100, 100)
# Act
image1 = image1.resize(new_size)
image2 = image1.resize(new_size)
# Assert
assert_equal(image1.size, new_size)
assert_equal(image2.size, new_size)
# End of file