Merge pull request #3415 from python-pillow/fix-webp-loading-from-blob

Quick fix: revert #3341 due to regression
This commit is contained in:
Alexander Karpinsky 2018-10-18 11:38:29 +03:00 committed by GitHub
commit b8e7f646f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 18 deletions

View File

@ -9,14 +9,7 @@ except ImportError:
HAVE_WEBP = False
class TestFileWebp(PillowTestCase):
def setUp(self):
if not HAVE_WEBP:
return
self.rgb_mode = "RGB"
class TestUnsupportedWebp(PillowTestCase):
def test_unsupported(self):
if HAVE_WEBP:
WebPImagePlugin.SUPPORTED = False
@ -28,12 +21,18 @@ class TestFileWebp(PillowTestCase):
if HAVE_WEBP:
WebPImagePlugin.SUPPORTED = True
@unittest.skipIf(not HAVE_WEBP, "WebP support not installed")
@unittest.skipIf(not HAVE_WEBP, "WebP support not installed")
class TestFileWebp(PillowTestCase):
def setUp(self):
self.rgb_mode = "RGB"
def test_version(self):
_webp.WebPDecoderVersion()
_webp.WebPDecoderBuggyAlpha()
@unittest.skipIf(not HAVE_WEBP, "WebP support not installed")
def test_read_rgb(self):
"""
Can we read a RGB mode WebP file without error?
@ -53,7 +52,6 @@ class TestFileWebp(PillowTestCase):
self.assert_image_similar_tofile(
image, 'Tests/images/hopper_webp_bits.ppm', 1.0)
@unittest.skipIf(not HAVE_WEBP, "WebP support not installed")
def test_write_rgb(self):
"""
Can we write a RGB mode file to webp without error.
@ -83,7 +81,6 @@ class TestFileWebp(PillowTestCase):
target = hopper(self.rgb_mode)
self.assert_image_similar(image, target, 12.0)
@unittest.skipIf(not HAVE_WEBP, "WebP support not installed")
def test_write_unsupported_mode_L(self):
"""
Saving a black-and-white file to WebP format should work, and be
@ -104,7 +101,6 @@ class TestFileWebp(PillowTestCase):
self.assert_image_similar(image, target, 10.0)
@unittest.skipIf(not HAVE_WEBP, "WebP support not installed")
def test_write_unsupported_mode_P(self):
"""
Saving a palette-based file to WebP format should work, and be
@ -125,7 +121,6 @@ class TestFileWebp(PillowTestCase):
self.assert_image_similar(image, target, 50.0)
@unittest.skipIf(not HAVE_WEBP, "WebP support not installed")
def test_WebPEncode_with_invalid_args(self):
"""
Calling encoder functions with no arguments should result in an error.
@ -135,7 +130,6 @@ class TestFileWebp(PillowTestCase):
self.assertRaises(TypeError, _webp.WebPAnimEncoder)
self.assertRaises(TypeError, _webp.WebPEncode)
@unittest.skipIf(not HAVE_WEBP, "WebP support not installed")
def test_WebPDecode_with_invalid_args(self):
"""
Calling decoder functions with no arguments should result in an error.
@ -145,7 +139,7 @@ class TestFileWebp(PillowTestCase):
self.assertRaises(TypeError, _webp.WebPAnimDecoder)
self.assertRaises(TypeError, _webp.WebPDecode)
@unittest.skipIf(not HAVE_WEBP, "WebP support not installed")
@unittest.skip("Currently is not working")
def test_no_resource_warning(self):
file_path = "Tests/images/hopper.webp"
image = Image.open(file_path)
@ -153,6 +147,12 @@ class TestFileWebp(PillowTestCase):
temp_file = self.tempfile("temp.webp")
self.assert_warning(None, image.save, temp_file)
def test_file_pointer_could_be_reused(self):
file_path = "Tests/images/hopper.webp"
with open(file_path, 'rb') as blob:
Image.open(blob).load()
Image.open(blob).load()
if __name__ == '__main__':
unittest.main()

View File

@ -163,8 +163,6 @@ class WebPImageFile(ImageFile.ImageFile):
self.__loaded = self.__logical_frame
# Set tile
if self.fp:
self.fp.close()
self.fp = BytesIO(data)
self.tile = [("raw", (0, 0) + self.size, 0, self.rawmode)]