more verbose testing, checking for g4 compression

This commit is contained in:
wiredfool 2013-03-13 10:59:06 -07:00
parent 35ce34a5fa
commit 03dcb5c557

View File

@ -63,24 +63,21 @@ def _assert_noerr(im):
"""Helper tests that assert basic sanity about the g4 tiff reading""" """Helper tests that assert basic sanity about the g4 tiff reading"""
#1 bit #1 bit
assert_equal(im.mode, "1") assert_equal(im.mode, "1")
# Does the data actually load # Does the data actually load
assert_no_exception(lambda: im.load()) assert_no_exception(lambda: im.load())
assert_no_exception(lambda: im.getdata()) assert_no_exception(lambda: im.getdata())
try:
assert_equal(im._compression, 'group4')
except:
print "No _compression"
print (dir(im))
# can we write it back out, in a different form. # can we write it back out, in a different form.
out = tempfile("temp.png") out = tempfile("temp.png")
assert_no_exception(lambda: im.save(out)) assert_no_exception(lambda: im.save(out))
def _compare_images(img, ref):
"""Compares the image to the reference, using 1000 sampled points"""
imgdata = img.getdata()
refdata = ref.getdata()
assert_equal(len(imgdata), len(refdata))
randitems = random.sample(range(len(imgdata)), 1000)
assert_equal([imgdata[i] for i in randitems],
[refdata[i] for i in randitems])
def test_g4_tiff(): def test_g4_tiff():
"""Test the ordinary file path load path""" """Test the ordinary file path load path"""
@ -95,7 +92,7 @@ def test_g4_large():
im = Image.open(file) im = Image.open(file)
_assert_noerr(im) _assert_noerr(im)
def test_g4_tiff_string(): def test_g4_tiff_file():
"""Testing the string load path""" """Testing the string load path"""
file = "Tests/images/lena_g4_500.tif" file = "Tests/images/lena_g4_500.tif"
@ -118,7 +115,7 @@ def test_g4_tiff_stringio():
assert_equal(im.size, (500,500)) assert_equal(im.size, (500,500))
_assert_noerr(im) _assert_noerr(im)
def xtest_g4_tiff_fail(): # UNDONE fails badly, unknown reason def test_g4_tiff_fail(): # UNDONE fails badly, unknown reason
"""The 128x128 lena image fails for some reason. Investigating""" """The 128x128 lena image fails for some reason. Investigating"""
Image.DEBUG = True Image.DEBUG = True
@ -138,14 +135,21 @@ def test_g4_eq_png():
def test_g4_write(): def test_g4_write():
"""Checking to see that the saved image is the same as what we wrote""" """Checking to see that the saved image is the same as what we wrote"""
Image.DEBUG = True
file = "Tests/images/lena_g4_500.tif" file = "Tests/images/lena_g4_500.tif"
orig = Image.open(file) orig = Image.open(file)
out = "temp.tif" out = "temp.tif"
rot = orig.transpose(Image.ROTATE_90) rot = orig.transpose(Image.ROTATE_90)
assert_equal(rot.size,(500,500))
rot.save(out) rot.save(out)
reread = Image.open(out) reread = Image.open(out)
assert_equal(reread.size,(500,500))
_assert_noerr(reread)
assert_image_equal(reread, rot) assert_image_equal(reread, rot)
assert_false(orig.tobytes() == reread.tobytes()) assert_false(orig.tobytes() == reread.tobytes())
Image.DEBUG = False