Skip to content

Commit 8604f67

Browse files
authored
Merge pull request #28206 from meeseeksmachine/auto-backport-of-pr-28205-on-v3.9.x
Backport PR #28205 on branch v3.9.x (TST: Fix tests with older versions of ipython)
2 parents 4db5ac9 + 196c8db commit 8604f67

File tree

6 files changed

+16
-17
lines changed

6 files changed

+16
-17
lines changed

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
- os: ubuntu-20.04
6161
python-version: 3.9
6262
# One CI run tests ipython/matplotlib-inline before backend mapping moved to mpl
63-
extra-requirements: '-r requirements/testing/extra.txt "ipython<8.24" "matplotlib-inline<0.1.7"'
63+
extra-requirements: '-r requirements/testing/extra.txt "ipython==7.19" "matplotlib-inline<0.1.7"'
6464
CFLAGS: "-fno-lto" # Ensure that disabling LTO works.
6565
# https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954
6666
# https://www.riverbankcomputing.com/pipermail/pyqt/2023-November/045606.html

lib/matplotlib/testing/__init__.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,7 @@ def _has_tex_package(package):
179179
return False
180180

181181

182-
def ipython_in_subprocess(
183-
requested_backend_or_gui_framework,
184-
expected_backend_old_ipython, # IPython < 8.24
185-
expected_backend_new_ipython, # IPython >= 8.24
186-
):
182+
def ipython_in_subprocess(requested_backend_or_gui_framework, all_expected_backends):
187183
import pytest
188184
IPython = pytest.importorskip("IPython")
189185

@@ -194,12 +190,12 @@ def ipython_in_subprocess(
194190
requested_backend_or_gui_framework == "osx"):
195191
pytest.skip("Bug using macosx backend in IPython 8.24.0 fixed in 8.24.1")
196192

197-
if IPython.version_info[:2] >= (8, 24):
198-
expected_backend = expected_backend_new_ipython
199-
else:
200-
# This code can be removed when Python 3.12, the latest version supported by
201-
# IPython < 8.24, reaches end-of-life in late 2028.
202-
expected_backend = expected_backend_old_ipython
193+
# This code can be removed when Python 3.12, the latest version supported
194+
# by IPython < 8.24, reaches end-of-life in late 2028.
195+
for min_version, backend in all_expected_backends.items():
196+
if IPython.version_info[:2] >= min_version:
197+
expected_backend = backend
198+
break
203199

204200
code = ("import matplotlib as mpl, matplotlib.pyplot as plt;"
205201
"fig, ax=plt.subplots(); ax.plot([1, 3, 2]); mpl.get_backend()")
@@ -214,4 +210,4 @@ def ipython_in_subprocess(
214210
capture_output=True,
215211
)
216212

217-
assert proc.stdout.strip() == f"Out[1]: '{expected_backend}'"
213+
assert proc.stdout.strip().endswith(f"'{expected_backend}'")

lib/matplotlib/testing/__init__.pyi

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,5 @@ def _check_for_pgf(texsystem: str) -> bool: ...
4949
def _has_tex_package(package: str) -> bool: ...
5050
def ipython_in_subprocess(
5151
requested_backend_or_gui_framework: str,
52-
expected_backend_old_ipython: str,
53-
expected_backend_new_ipython: str,
52+
all_expected_backends: dict[tuple[int, int], str],
5453
) -> None: ...

lib/matplotlib/tests/test_backend_inline.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from pathlib import Path
33
from tempfile import TemporaryDirectory
4+
import sys
45

56
import pytest
67

@@ -12,6 +13,7 @@
1213
pytest.importorskip('matplotlib_inline')
1314

1415

16+
@pytest.mark.skipif(sys.version_info[:2] <= (3, 9), reason="Requires Python 3.10+")
1517
def test_ipynb():
1618
nb_path = Path(__file__).parent / 'test_inline_01.ipynb'
1719

lib/matplotlib/tests/test_backend_macosx.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def new_choose_save_file(title, directory, filename):
4646
assert mpl.rcParams["savefig.directory"] == f"{tmp_path}/test"
4747

4848

49+
@pytest.mark.backend('macosx')
4950
def test_ipython():
5051
from matplotlib.testing import ipython_in_subprocess
51-
ipython_in_subprocess("osx", "MacOSX", "macosx")
52+
ipython_in_subprocess("osx", {(8, 24): "macosx", (7, 0): "MacOSX"})

lib/matplotlib/tests/test_backend_qt.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ def custom_handler(signum, frame):
374374
signal.signal(signal.SIGINT, original_handler)
375375

376376

377+
@pytest.mark.backend('QtAgg', skip_on_importerror=True)
377378
def test_ipython():
378379
from matplotlib.testing import ipython_in_subprocess
379-
ipython_in_subprocess("qt", "QtAgg", "qtagg")
380+
ipython_in_subprocess("qt", {(8, 24): "qtagg", (8, 15): "QtAgg", (7, 0): "Qt5Agg"})

0 commit comments

Comments
 (0)