Skip to content

Commit

Permalink
Merge pull request #3415 from python-pillow/fix-webp-loading-from-blob
Browse files Browse the repository at this point in the history
Quick fix: revert #3341 due to regression
  • Loading branch information
homm authored Oct 18, 2018
2 parents 00f9e8b + e26696c commit b8e7f64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
32 changes: 16 additions & 16 deletions Tests/test_file_webp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@
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
Expand All @@ -28,12 +21,18 @@ def test_unsupported(self):
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?
Expand All @@ -53,7 +52,6 @@ def test_read_rgb(self):
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.
Expand Down Expand Up @@ -83,7 +81,6 @@ def test_write_rgb(self):
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
Expand All @@ -104,7 +101,6 @@ def test_write_unsupported_mode_L(self):

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
Expand All @@ -125,7 +121,6 @@ def test_write_unsupported_mode_P(self):

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.
Expand All @@ -135,7 +130,6 @@ def test_WebPEncode_with_invalid_args(self):
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.
Expand All @@ -145,14 +139,20 @@ def test_WebPDecode_with_invalid_args(self):
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)

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()
2 changes: 0 additions & 2 deletions src/PIL/WebPImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ def load(self):
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)]

Expand Down

0 comments on commit b8e7f64

Please sign in to comment.