mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 09:14:27 +03:00
More explicit error message when saving to a file with invalid extension (#2399)
* more explicit error message when saving to a file with invalid extension + test
This commit is contained in:
parent
b5f6732501
commit
8fb44a2bee
|
@ -1715,7 +1715,10 @@ class Image(object):
|
|||
if not format:
|
||||
if ext not in EXTENSION:
|
||||
init()
|
||||
format = EXTENSION[ext]
|
||||
try:
|
||||
format = EXTENSION[ext]
|
||||
except KeyError:
|
||||
raise ValueError('unknown file extension: {}'.format(ext))
|
||||
|
||||
if format.upper() not in SAVE:
|
||||
init()
|
||||
|
|
|
@ -87,6 +87,11 @@ class TestImage(PillowTestCase):
|
|||
reloaded = Image.open(fp)
|
||||
self.assert_image_similar(im, reloaded, 20)
|
||||
|
||||
def test_unknown_extension(self):
|
||||
im = hopper()
|
||||
temp_file = self.tempfile("temp.unknown")
|
||||
self.assertRaises(ValueError, lambda: im.save(temp_file))
|
||||
|
||||
def test_internals(self):
|
||||
|
||||
im = Image.new("L", (100, 100))
|
||||
|
|
Loading…
Reference in New Issue
Block a user