mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 17:54:32 +03:00
Merge pull request #2343 from radarhere/registered_extensions
Expose registered file extensions in Image
This commit is contained in:
commit
f6dd290560
10
PIL/Image.py
10
PIL/Image.py
|
@ -2512,6 +2512,16 @@ def register_extension(id, extension):
|
||||||
EXTENSION[extension.lower()] = id.upper()
|
EXTENSION[extension.lower()] = id.upper()
|
||||||
|
|
||||||
|
|
||||||
|
def registered_extensions():
|
||||||
|
"""
|
||||||
|
Returns a dictionary containing all file extensions belonging
|
||||||
|
to registered plugins
|
||||||
|
"""
|
||||||
|
if not bool(EXTENSION):
|
||||||
|
init()
|
||||||
|
return EXTENSION
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Simple display support. User code may override this.
|
# Simple display support. User code may override this.
|
||||||
|
|
||||||
|
|
|
@ -196,6 +196,35 @@ class TestImage(PillowTestCase):
|
||||||
img_colors = sorted(img.getcolors())
|
img_colors = sorted(img.getcolors())
|
||||||
self.assertEqual(img_colors, expected_colors)
|
self.assertEqual(img_colors, expected_colors)
|
||||||
|
|
||||||
|
def test_registered_extensions_uninitialized(self):
|
||||||
|
# Arrange
|
||||||
|
Image._initialized = 0
|
||||||
|
extension = Image.EXTENSION
|
||||||
|
Image.EXTENSION = {}
|
||||||
|
|
||||||
|
# Act
|
||||||
|
Image.registered_extensions()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertEqual(Image._initialized, 2)
|
||||||
|
|
||||||
|
# Restore the original state and assert
|
||||||
|
Image.EXTENSION = extension
|
||||||
|
self.assertTrue(Image.EXTENSION)
|
||||||
|
|
||||||
|
def test_registered_extensions(self):
|
||||||
|
# Arrange
|
||||||
|
# Open an image to trigger plugin registration
|
||||||
|
Image.open('Tests/images/rgb.jpg')
|
||||||
|
|
||||||
|
# Act
|
||||||
|
extensions = Image.registered_extensions()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertTrue(bool(extensions))
|
||||||
|
for ext in ['.cur', '.icns', '.tif', '.tiff']:
|
||||||
|
self.assertIn(ext, extensions)
|
||||||
|
|
||||||
def test_effect_mandelbrot(self):
|
def test_effect_mandelbrot(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
size = (512, 512)
|
size = (512, 512)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user