mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-10 00:20:57 +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 not format:
|
||||||
if ext not in EXTENSION:
|
if ext not in EXTENSION:
|
||||||
init()
|
init()
|
||||||
|
try:
|
||||||
format = EXTENSION[ext]
|
format = EXTENSION[ext]
|
||||||
|
except KeyError:
|
||||||
|
raise ValueError('unknown file extension: {}'.format(ext))
|
||||||
|
|
||||||
if format.upper() not in SAVE:
|
if format.upper() not in SAVE:
|
||||||
init()
|
init()
|
||||||
|
|
|
@ -87,6 +87,11 @@ class TestImage(PillowTestCase):
|
||||||
reloaded = Image.open(fp)
|
reloaded = Image.open(fp)
|
||||||
self.assert_image_similar(im, reloaded, 20)
|
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):
|
def test_internals(self):
|
||||||
|
|
||||||
im = Image.new("L", (100, 100))
|
im = Image.new("L", (100, 100))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user