Fix some Landscape.io errors and warnings

This commit is contained in:
Hugo 2014-10-01 16:50:33 +03:00
parent 485ce69702
commit ae7b765b53
7 changed files with 47 additions and 57 deletions

View File

@ -184,7 +184,6 @@ class PngInfo:
tkey = tkey.encode("utf-8", "strict")
if zip:
import zlib
self.add(b"iTXt", key + b"\0\x01\0" + lang + b"\0" + tkey + b"\0" +
zlib.compress(value))
else:
@ -206,7 +205,6 @@ class PngInfo:
key = key.encode('latin-1', 'strict')
if zip:
import zlib
self.add(b"zTXt", key + b"\0\0" + zlib.compress(value))
else:
self.add(b"tEXt", key + b"\0" + value)
@ -359,7 +357,6 @@ class PngStream(ChunkStream):
if comp_method != 0:
raise SyntaxError("Unknown compression method %s in zTXt chunk" %
comp_method)
import zlib
try:
v = zlib.decompress(v[1:])
except zlib.error:
@ -390,7 +387,6 @@ class PngStream(ChunkStream):
return s
if cf != 0:
if cm == 0:
import zlib
try:
v = zlib.decompress(v)
except zlib.error:

View File

@ -175,10 +175,10 @@ def fromstring(data):
return Image.open(BytesIO(data))
def tostring(im, format, **options):
def tostring(im, string_format, **options):
from io import BytesIO
out = BytesIO()
im.save(out, format, **options)
im.save(out, string_format, **options)
return out.getvalue()
@ -207,7 +207,6 @@ def command_succeeds(cmd):
Runs the command, which must be a list of strings. Returns True if the
command succeeds, or False if an OSError was raised by subprocess.Popen.
"""
import os
import subprocess
with open(os.devnull, 'w') as f:
try:

View File

@ -73,7 +73,7 @@ class TestFileEps(PillowTestCase):
image1_scale1_compare = Image.open(file1_compare).convert("RGB")
image1_scale1_compare.load()
self.assert_image_similar(img, image1_scale1_compare, 5)
def test_render_scale1(self):
# We need png support for these render test
codecs = dir(Image.core)
@ -164,11 +164,10 @@ class TestFileEps(PillowTestCase):
return
t = StringIO.StringIO(test_string)
self._test_readline(t, ending)
def _test_readline_io(self, test_string, ending):
import io
if str is bytes:
t = io.StringIO(unicode(test_string))
t = io.StringIO(unicode(test_string))
else:
t = io.StringIO(test_string)
self._test_readline(t, ending)
@ -195,35 +194,35 @@ class TestFileEps(PillowTestCase):
with open(f,'rb') as r:
t = EpsImagePlugin.PSFile(r)
self._test_readline(t, ending)
def test_readline(self):
# check all the freaking line endings possible from the spec
#test_string = u'something\r\nelse\n\rbaz\rbif\n'
line_endings = ['\r\n', '\n']
not_working_endings = ['\n\r', '\r']
not_working_endings = ['\n\r', '\r']
strings = ['something', 'else', 'baz', 'bif']
for ending in line_endings:
s = ending.join(strings)
# Native python versions will pass these endings.
# Native Python versions will pass these endings.
#self._test_readline_stringio(s, ending)
#self._test_readline_io(s, ending)
#self._test_readline_file_universal(s, ending)
self._test_readline_file_psfile(s, ending)
for ending in not_working_endings:
# these only work with the PSFile, while they're in spec,
# they're not likely to be used
s = ending.join(strings)
# Native python versions may fail on these endings.
# Native Python versions may fail on these endings.
#self._test_readline_stringio(s, ending)
#self._test_readline_io(s, ending)
#self._test_readline_file_universal(s, ending)
self._test_readline_file_psfile(s, ending)
if __name__ == '__main__':
unittest.main()

View File

@ -7,36 +7,36 @@ class TestFileTiff(PillowTestCase):
def test_sanity(self):
file = self.tempfile("temp.tif")
filename = self.tempfile("temp.tif")
hopper("RGB").save(file)
hopper("RGB").save(filename)
im = Image.open(file)
im = Image.open(filename)
im.load()
self.assertEqual(im.mode, "RGB")
self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "TIFF")
hopper("1").save(file)
im = Image.open(file)
hopper("1").save(filename)
im = Image.open(filename)
hopper("L").save(file)
im = Image.open(file)
hopper("L").save(filename)
im = Image.open(filename)
hopper("P").save(file)
im = Image.open(file)
hopper("P").save(filename)
im = Image.open(filename)
hopper("RGB").save(file)
im = Image.open(file)
hopper("RGB").save(filename)
im = Image.open(filename)
hopper("I").save(file)
im = Image.open(file)
hopper("I").save(filename)
im = Image.open(filename)
def test_mac_tiff(self):
# Read RGBa images from Mac OS X [@PIL136]
file = "Tests/images/pil136.tiff"
im = Image.open(file)
filename = "Tests/images/pil136.tiff"
im = Image.open(filename)
self.assertEqual(im.mode, "RGBA")
self.assertEqual(im.size, (55, 43))
@ -50,8 +50,8 @@ class TestFileTiff(PillowTestCase):
if "jpeg_decoder" not in codecs:
self.skipTest("jpeg support not available")
file = "Tests/images/pil168.tif"
im = Image.open(file)
filename = "Tests/images/pil168.tif"
im = Image.open(filename)
self.assertEqual(im.mode, "RGB")
self.assertEqual(im.size, (256, 256))
@ -66,8 +66,8 @@ class TestFileTiff(PillowTestCase):
def test_xyres_tiff(self):
from PIL.TiffImagePlugin import X_RESOLUTION, Y_RESOLUTION
file = "Tests/images/pil168.tif"
im = Image.open(file)
filename = "Tests/images/pil168.tif"
im = Image.open(filename)
assert isinstance(im.tag.tags[X_RESOLUTION][0], tuple)
assert isinstance(im.tag.tags[Y_RESOLUTION][0], tuple)
# Try to read a file where X,Y_RESOLUTION are ints
@ -169,8 +169,8 @@ class TestFileTiff(PillowTestCase):
def test___str__(self):
# Arrange
file = "Tests/images/pil136.tiff"
im = Image.open(file)
filename = "Tests/images/pil136.tiff"
im = Image.open(filename)
# Act
ret = str(im.ifd)
@ -186,8 +186,8 @@ class TestFileTiff(PillowTestCase):
def test__delitem__(self):
# Arrange
file = "Tests/images/pil136.tiff"
im = Image.open(file)
filename = "Tests/images/pil136.tiff"
im = Image.open(filename)
len_before = len(im.ifd.as_dict())
# Act
@ -199,7 +199,6 @@ class TestFileTiff(PillowTestCase):
def test_load_byte(self):
# Arrange
from PIL import TiffImagePlugin
ifd = TiffImagePlugin.ImageFileDirectory()
data = b"abc"
@ -211,7 +210,6 @@ class TestFileTiff(PillowTestCase):
def test_load_string(self):
# Arrange
from PIL import TiffImagePlugin
ifd = TiffImagePlugin.ImageFileDirectory()
data = b"abc\0"
@ -223,7 +221,6 @@ class TestFileTiff(PillowTestCase):
def test_load_float(self):
# Arrange
from PIL import TiffImagePlugin
ifd = TiffImagePlugin.ImageFileDirectory()
data = b"abcdabcd"
@ -235,7 +232,6 @@ class TestFileTiff(PillowTestCase):
def test_load_double(self):
# Arrange
from PIL import TiffImagePlugin
ifd = TiffImagePlugin.ImageFileDirectory()
data = b"abcdefghabcdefgh"
@ -247,8 +243,8 @@ class TestFileTiff(PillowTestCase):
def test_seek(self):
# Arrange
file = "Tests/images/pil136.tiff"
im = Image.open(file)
filename = "Tests/images/pil136.tiff"
im = Image.open(filename)
# Act
im.seek(-1)
@ -258,8 +254,8 @@ class TestFileTiff(PillowTestCase):
def test_seek_eof(self):
# Arrange
file = "Tests/images/pil136.tiff"
im = Image.open(file)
filename = "Tests/images/pil136.tiff"
im = Image.open(filename)
self.assertEqual(im.tell(), 0)
# Act / Assert

View File

@ -4,7 +4,7 @@ from PIL import Image
try:
from PIL import _webp
except:
except ImportError:
# Skip in setUp()
pass
@ -14,7 +14,7 @@ class TestFileWebp(PillowTestCase):
def setUp(self):
try:
from PIL import _webp
except:
except ImportError:
self.skipTest('WebP support not installed')
def test_version(self):

View File

@ -4,7 +4,7 @@ from PIL import Image
try:
from PIL import _webp
except:
except ImportError:
pass
# Skip in setUp()
@ -14,7 +14,7 @@ class TestFileWebpAlpha(PillowTestCase):
def setUp(self):
try:
from PIL import _webp
except:
except ImportError:
self.skipTest('WebP support not installed')
if _webp.WebPDecoderBuggyAlpha(self):
@ -80,8 +80,8 @@ class TestFileWebpAlpha(PillowTestCase):
self.assertEqual(image.mode, "RGBA")
self.assertEqual(image.size, (10, 10))
self.assertEqual(image.format, "WEBP")
image.load
image.getdata
image.load()
image.getdata()
self.assert_image_similar(image, pil_image, 1.0)

View File

@ -63,7 +63,7 @@ class MorphTests(PillowTestCase):
'corner', 'dilation4', 'dilation8',
'erosion4', 'erosion8', 'edge'):
lb = ImageMorph.LutBuilder(op_name=op)
lut = lb.build_lut(self)
lut = lb.build_lut()
with open('Tests/images/%s.lut' % op, 'wb') as f:
f.write(lut)