Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose registered file extensions in Image #2343

Merged
merged 4 commits into from
Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2512,6 +2512,16 @@ def register_extension(id, extension):
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.

Expand Down
29 changes: 29 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,35 @@ def test_alpha_composite(self):
img_colors = sorted(img.getcolors())
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):
# Arrange
size = (512, 512)
Expand Down