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

View File

@ -175,10 +175,10 @@ def fromstring(data):
return Image.open(BytesIO(data)) return Image.open(BytesIO(data))
def tostring(im, format, **options): def tostring(im, string_format, **options):
from io import BytesIO from io import BytesIO
out = BytesIO() out = BytesIO()
im.save(out, format, **options) im.save(out, string_format, **options)
return out.getvalue() 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 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. command succeeds, or False if an OSError was raised by subprocess.Popen.
""" """
import os
import subprocess import subprocess
with open(os.devnull, 'w') as f: with open(os.devnull, 'w') as f:
try: try:

View File

@ -73,7 +73,7 @@ class TestFileEps(PillowTestCase):
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()
self.assert_image_similar(img, image1_scale1_compare, 5) self.assert_image_similar(img, image1_scale1_compare, 5)
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)
@ -164,11 +164,10 @@ class TestFileEps(PillowTestCase):
return return
t = StringIO.StringIO(test_string) t = StringIO.StringIO(test_string)
self._test_readline(t, ending) self._test_readline(t, ending)
def _test_readline_io(self, test_string, ending): def _test_readline_io(self, test_string, ending):
import io
if str is bytes: if str is bytes:
t = io.StringIO(unicode(test_string)) t = io.StringIO(unicode(test_string))
else: else:
t = io.StringIO(test_string) t = io.StringIO(test_string)
self._test_readline(t, ending) self._test_readline(t, ending)
@ -195,35 +194,35 @@ class TestFileEps(PillowTestCase):
with open(f,'rb') as r: with open(f,'rb') as r:
t = EpsImagePlugin.PSFile(r) t = EpsImagePlugin.PSFile(r)
self._test_readline(t, ending) self._test_readline(t, ending)
def test_readline(self): def test_readline(self):
# check all the freaking line endings possible from the spec # check all the freaking line endings possible from the spec
#test_string = u'something\r\nelse\n\rbaz\rbif\n' #test_string = u'something\r\nelse\n\rbaz\rbif\n'
line_endings = ['\r\n', '\n'] line_endings = ['\r\n', '\n']
not_working_endings = ['\n\r', '\r'] not_working_endings = ['\n\r', '\r']
strings = ['something', 'else', 'baz', 'bif'] strings = ['something', 'else', 'baz', 'bif']
for ending in line_endings: for ending in line_endings:
s = ending.join(strings) 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_stringio(s, ending)
#self._test_readline_io(s, ending) #self._test_readline_io(s, ending)
#self._test_readline_file_universal(s, ending) #self._test_readline_file_universal(s, ending)
self._test_readline_file_psfile(s, ending) self._test_readline_file_psfile(s, ending)
for ending in not_working_endings: for ending in not_working_endings:
# these only work with the PSFile, while they're in spec, # these only work with the PSFile, while they're in spec,
# they're not likely to be used # they're not likely to be used
s = ending.join(strings) 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_stringio(s, ending)
#self._test_readline_io(s, ending) #self._test_readline_io(s, ending)
#self._test_readline_file_universal(s, ending) #self._test_readline_file_universal(s, ending)
self._test_readline_file_psfile(s, ending) self._test_readline_file_psfile(s, ending)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

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

View File

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

View File

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

View File

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