|
16 | 16 | from matplotlib import _c_internal_utils
|
17 | 17 | from matplotlib.testing import subprocess_run_helper as _run_helper
|
18 | 18 |
|
| 19 | + |
19 | 20 | # Minimal smoke-testing of the backends for which the dependencies are
|
20 | 21 | # PyPI-installable on CI. They are not available for all tested Python
|
21 | 22 | # versions so we don't fail on missing backends.
|
@@ -307,6 +308,50 @@ def test_qt5backends_uses_qt5():
|
307 | 308 | _run_helper(__name__, _implcore, timeout=_test_timeout)
|
308 | 309 |
|
309 | 310 |
|
| 311 | +def _impl_test_cross_Qt_imports(): |
| 312 | + import sys |
| 313 | + import importlib |
| 314 | + import pytest |
| 315 | + |
| 316 | + _, host_binding, mpl_binding = sys.argv |
| 317 | + # import the mpl binding. This will force us to use that binding |
| 318 | + importlib.import_module(f'{mpl_binding}.QtCore') |
| 319 | + mpl_binding_qwidgets = importlib.import_module(f'{mpl_binding}.QtWidgets') |
| 320 | + import matplotlib.backends.backend_qt |
| 321 | + host_qwidgets = importlib.import_module(f'{host_binding}.QtWidgets') |
| 322 | + |
| 323 | + host_app = host_qwidgets.QApplication(["mpl testing"]) |
| 324 | + with pytest.warns(UserWarning, match="Mixing Qt major"): |
| 325 | + matplotlib.backends.backend_qt._create_qApp() |
| 326 | + |
| 327 | + |
| 328 | +def test_cross_Qt_imports(): |
| 329 | + qt5_bindings = [ |
| 330 | + dep for dep in ['PyQt5', 'PySide2'] |
| 331 | + if importlib.util.find_spec(dep) is not None |
| 332 | + ] |
| 333 | + qt6_bindings = [ |
| 334 | + dep for dep in ['PyQt6', 'PySide6'] |
| 335 | + if importlib.util.find_spec(dep) is not None |
| 336 | + ] |
| 337 | + if len(qt5_bindings) == 0 or len(qt6_bindings) == 0: |
| 338 | + pytest.skip('need both QT6 and QT5 bindings') |
| 339 | + |
| 340 | + for qt5 in qt5_bindings: |
| 341 | + for qt6 in qt6_bindings: |
| 342 | + for pair in ([qt5, qt6], [qt6, qt5]): |
| 343 | + try: |
| 344 | + _run_helper(__name__, _impl_test_cross_Qt_imports, |
| 345 | + *pair, |
| 346 | + timeout=_test_timeout) |
| 347 | + except subprocess.CalledProcessError as ex: |
| 348 | + # if segfauldt, carry on. We do try to warn the user they |
| 349 | + # are doing something that we do not expect to work |
| 350 | + if ex.returncode == -11: |
| 351 | + continue |
| 352 | + raise |
| 353 | + |
| 354 | + |
310 | 355 | @pytest.mark.skipif('TF_BUILD' in os.environ,
|
311 | 356 | reason="this test fails an azure for unknown reasons")
|
312 | 357 | @pytest.mark.skipif(os.name == "nt", reason="Cannot send SIGINT on Windows.")
|
|
0 commit comments