mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Merge pull request #984 from hugovk/landscape-fixes
Fixed duplicate imports, naming variables after builtins
This commit is contained in:
commit
8bb22793b3
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -166,7 +166,6 @@ class TestFileEps(PillowTestCase):
|
|||
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))
|
||||
else:
|
||||
|
@ -205,7 +204,7 @@ class TestFileEps(PillowTestCase):
|
|||
|
||||
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)
|
||||
|
@ -217,7 +216,7 @@ class TestFileEps(PillowTestCase):
|
|||
# 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)
|
||||
|
|
|
@ -27,13 +27,13 @@ class TestFileMsp(PillowTestCase):
|
|||
self.assertEqual(im.size, (128, 128))
|
||||
self.assert_image_similar(im, hopper("1"), 4)
|
||||
|
||||
def test_cannot_save_save_wrong_mode(self):
|
||||
def test_cannot_save_wrong_mode(self):
|
||||
# Arrange
|
||||
im = hopper()
|
||||
file = self.tempfile("temp.msp")
|
||||
filename = self.tempfile("temp.msp")
|
||||
|
||||
# Act/Assert
|
||||
self.assertRaises(IOError, lambda: im.save(file))
|
||||
self.assertRaises(IOError, lambda: im.save(filename))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -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
|
||||
|
@ -168,8 +168,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)
|
||||
|
@ -185,8 +185,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
|
||||
|
@ -242,8 +242,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)
|
||||
|
@ -253,8 +253,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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user