Added test for disabled image plugin

This commit is contained in:
Charles Whittington 2024-02-12 20:48:31 -05:00
parent c69574b6f0
commit 869db41dfb
4 changed files with 12 additions and 0 deletions

View file

@ -120,6 +120,7 @@ class Image:
converters = []
for image_plugin in entry_points(group="toga.image_formats"):
print(image_plugin)
converter = importlib.import_module(f"{image_plugin.value}")
if converter.image_class is not None:
converters.append(converter)

View file

@ -4,6 +4,7 @@ import PIL.Image
import pytest
import toga
from toga_dummy.plugins import disabled_converter
from toga_dummy.plugins.image_converter import CustomImage, CustomImageSubclass
from toga_dummy.utils import assert_action_performed_with
@ -286,6 +287,11 @@ def test_as_format_custom_class(app, ImageClass):
assert custom_image.size == (144, 72)
def test_disabled_image_plugin(app):
"""Disabled image plugin shouldn't be available."""
assert disabled_converter not in toga.Image._converters()
# None is same as supplying nothing; also test a random unrecognized class
@pytest.mark.parametrize("arg", [None, toga.Button])
def test_as_format_invalid_input(app, arg):

View file

@ -63,3 +63,4 @@ dependencies = [
[project.entry-points."toga.image_formats"]
dummy = "toga_dummy.plugins.image_converter"
disabled = "toga_dummy.plugins.disabled_converter"

View file

@ -0,0 +1,4 @@
# With image_class set to None, this shouldn't be added to the list of available
# converters. This simulates what the PIL plugin does if PIL isn't installed.
image_class = None