Skip to content

Commit 579f415

Browse files
committed
New tests support old and new ipython
1 parent acf737c commit 579f415

File tree

7 files changed

+30
-11
lines changed

7 files changed

+30
-11
lines changed

lib/matplotlib/testing/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,16 @@ def _has_tex_package(package):
181181
return False
182182

183183

184-
def ipython_in_subprocess(requested_backend_or_gui_framework, expected_backend):
185-
pytest.importorskip("IPython")
184+
def ipython_in_subprocess(
185+
requested_backend_or_gui_framework,
186+
expected_backend_old_ipython, # IPython < 8.24
187+
expected_backend_new_ipython, # IPython >= 8.24
188+
):
189+
IPython = pytest.importorskip("IPython")
190+
if IPython.version_info[:2] >= (8, 24):
191+
expected_backend = expected_backend_new_ipython
192+
else:
193+
expected_backend = expected_backend_old_ipython
186194

187195
code = ("import matplotlib as mpl, matplotlib.pyplot as plt;"
188196
"fig, ax=plt.subplots(); ax.plot([1, 3, 2]); mpl.get_backend()")
@@ -196,5 +204,5 @@ def ipython_in_subprocess(requested_backend_or_gui_framework, expected_backend):
196204
check=True,
197205
capture_output=True,
198206
)
199-
207+
200208
assert proc.stdout.strip() == f"Out[1]: '{expected_backend}'"

lib/matplotlib/testing/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@ 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: str,
52+
expected_backend_old_ipython: str,
53+
expected_backend_new_ipython: str,
5354
) -> None: ...

lib/matplotlib/tests/test_backend_inline.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ def test_ipynb():
3030
errors = [output for cell in nb.cells for output in cell.get("outputs", [])
3131
if output.output_type == "error"]
3232
assert not errors
33-
33+
34+
import IPython
35+
if IPython.version_info[:2] >= (8, 24):
36+
expected_backend = "inline"
37+
else:
38+
expected_backend = "module://matplotlib_inline.backend_inline"
3439
backend_outputs = nb.cells[2]["outputs"]
35-
assert backend_outputs[0]["data"]["text/plain"] == "'inline'"
40+
assert backend_outputs[0]["data"]["text/plain"] == f"'{expected_backend}'"
3641

3742
image = nb.cells[1]["outputs"][1]["data"]
3843
assert image["text/plain"] == "<Figure size 300x200 with 1 Axes>"

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")
51+
ipython_in_subprocess("osx", "MacOSX", "macosx")

lib/matplotlib/tests/test_backend_nbagg.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ def test_ipynb():
3030
errors = [output for cell in nb.cells for output in cell.get("outputs", [])
3131
if output.output_type == "error"]
3232
assert not errors
33-
33+
34+
import IPython
35+
if IPython.version_info[:2] >= (8, 24):
36+
expected_backend = "notebook"
37+
else:
38+
expected_backend = "nbAgg"
3439
backend_outputs = nb.cells[2]["outputs"]
35-
assert backend_outputs[0]["data"]["text/plain"] == "'notebook'"
40+
assert backend_outputs[0]["data"]["text/plain"] == f"'{expected_backend}'"

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")
381+
ipython_in_subprocess("qt", "QtAgg", "qtagg")

lib/matplotlib/tests/test_backend_tk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,4 @@ def test_figure(master):
265265

266266
def test_ipython():
267267
from matplotlib.testing import ipython_in_subprocess
268-
ipython_in_subprocess("tk", "tkagg")
268+
ipython_in_subprocess("tk", "TkAgg", "tkagg")

0 commit comments

Comments
 (0)