Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport PR #28473 on branch v3.9.x (Do not lowercase module:// backends) #28482

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

Merged
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
12 changes: 9 additions & 3 deletions lib/matplotlib/backends/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def __init__(self):
}

def _backend_module_name(self, backend):
if backend.startswith("module://"):
return backend[9:]

# Return name of module containing the specified backend.
# Does not check if the backend is valid, use is_valid_backend for that.
backend = backend.lower()
Expand Down Expand Up @@ -224,7 +227,8 @@ def is_valid_backend(self, backend):
bool
True if backend is valid, False otherwise.
"""
backend = backend.lower()
if not backend.startswith("module://"):
backend = backend.lower()

# For backward compatibility, convert ipympl and matplotlib-inline long
# module:// names to their shortened forms.
Expand Down Expand Up @@ -342,7 +346,8 @@ def resolve_backend(self, backend):
The GUI framework, which will be None for a backend that is non-interactive.
"""
if isinstance(backend, str):
backend = backend.lower()
if not backend.startswith("module://"):
backend = backend.lower()
else: # Might be _auto_backend_sentinel or None
# Use whatever is already running...
from matplotlib import get_backend
Expand Down Expand Up @@ -395,7 +400,8 @@ def resolve_gui_or_backend(self, gui_or_backend):
framework : str or None
The GUI framework, which will be None for a backend that is non-interactive.
"""
gui_or_backend = gui_or_backend.lower()
if not gui_or_backend.startswith("module://"):
gui_or_backend = gui_or_backend.lower()

# First check if it is a gui loop name.
backend = self.backend_for_gui_framework(gui_or_backend)
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_backend_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ def test_is_valid_backend(backend, is_valid):
assert backend_registry.is_valid_backend(backend) == is_valid


@pytest.mark.parametrize("backend, normalized", [
("agg", "matplotlib.backends.backend_agg"),
("QtAgg", "matplotlib.backends.backend_qtagg"),
("module://Anything", "Anything"),
])
def test_backend_normalization(backend, normalized):
assert backend_registry._backend_module_name(backend) == normalized


def test_deprecated_rcsetup_attributes():
match = "was deprecated in Matplotlib 3.9"
with pytest.warns(mpl.MatplotlibDeprecationWarning, match=match):
Expand Down
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_backend_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ def test_show_old_global_api(monkeypatch):
mpl.use("module://mpl_test_backend")
plt.show()
mock_show.assert_called_with()


def test_load_case_sensitive(monkeypatch):
mpl_test_backend = SimpleNamespace(**vars(backend_template))
mock_show = MagicMock()
monkeypatch.setattr(
mpl_test_backend.FigureManagerTemplate, "pyplot_show", mock_show)
monkeypatch.setitem(sys.modules, "mpl_Test_Backend", mpl_test_backend)
mpl.use("module://mpl_Test_Backend")
plt.show()
mock_show.assert_called_with()
Loading