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

Skip to content

Commit 0e07493

Browse files
committed
TST: Fix tests with older versions of ipython
I only went back as far as 7.0.0, as due to #16263, we probably don't want to be supporting all the way back to IPython 1.
1 parent 3ee509d commit 0e07493

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
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" "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

Lines changed: 7 additions & 11 deletions
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()")

lib/matplotlib/testing/__init__.pyi

Lines changed: 1 addition & 2 deletions
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_macosx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ def new_choose_save_file(title, directory, filename):
4848

4949
def test_ipython():
5050
from matplotlib.testing import ipython_in_subprocess
51-
ipython_in_subprocess("osx", "MacOSX", "macosx")
51+
ipython_in_subprocess("osx", {(8, 24): "macosx", (7, 0): "MacOSX"})

lib/matplotlib/tests/test_backend_qt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,4 @@ def custom_handler(signum, frame):
378378

379379
def test_ipython():
380380
from matplotlib.testing import ipython_in_subprocess
381-
ipython_in_subprocess("qt", "QtAgg", "qtagg")
381+
ipython_in_subprocess("qt", {(8, 24): "qtagg", (8, 15): "QtAgg", (7, 0): "Qt5Agg"})

0 commit comments

Comments
 (0)