From 75a77ec71ba5e5b10cb421070141e2e08dcd6a60 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Wed, 26 Apr 2023 11:06:48 -0500 Subject: [PATCH 1/2] Only print actually tested QT APIs when erroring --- lib/matplotlib/backends/qt_compat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/qt_compat.py b/lib/matplotlib/backends/qt_compat.py index 28650dc9ff83..e76ff67e1cef 100644 --- a/lib/matplotlib/backends/qt_compat.py +++ b/lib/matplotlib/backends/qt_compat.py @@ -133,7 +133,8 @@ def _isdeleted(obj): else: raise ImportError( "Failed to import any of the following Qt binding modules: {}" - .format(", ".join(_ETS.values()))) + .format(", ".join([QT_API for _, QT_API in _candidates])) + ) else: # We should not get there. raise AssertionError(f"Unexpected QT_API: {QT_API}") _version_info = tuple(QtCore.QLibraryInfo.version().segments()) From b64444c177d143d7b5935489737f52b75c3c8297 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Wed, 26 Apr 2023 19:00:48 -0500 Subject: [PATCH 2/2] Explicitly test for missing qt bindings --- .../tests/test_backends_interactive.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/matplotlib/tests/test_backends_interactive.py b/lib/matplotlib/tests/test_backends_interactive.py index ade636433144..a8cbc8885daf 100644 --- a/lib/matplotlib/tests/test_backends_interactive.py +++ b/lib/matplotlib/tests/test_backends_interactive.py @@ -343,6 +343,26 @@ def test_qt5backends_uses_qt5(): _run_helper(_implcore, timeout=_test_timeout) +def _impl_missing(): + import sys + # Simulate uninstalled + sys.modules["PyQt6"] = None + sys.modules["PyQt5"] = None + sys.modules["PySide2"] = None + sys.modules["PySide6"] = None + + import matplotlib.pyplot as plt + with pytest.raises(ImportError, match="Failed to import any of the following Qt"): + plt.switch_backend("qtagg") + # Specifically ensure that Pyside6/Pyqt6 are not in the error message for qt5agg + with pytest.raises(ImportError, match="^(?:(?!(PySide6|PyQt6)).)*$"): + plt.switch_backend("qt5agg") + + +def test_qt_missing(): + _run_helper(_impl_missing, timeout=_test_timeout) + + def _impl_test_cross_Qt_imports(): import sys import importlib pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy