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

Skip to content

Backport PR #28205 on branch v3.9.x (TST: Fix tests with older versions of ipython) #28206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
- os: ubuntu-20.04
python-version: 3.9
# One CI run tests ipython/matplotlib-inline before backend mapping moved to mpl
extra-requirements: '-r requirements/testing/extra.txt "ipython<8.24" "matplotlib-inline<0.1.7"'
extra-requirements: '-r requirements/testing/extra.txt "ipython==7.19" "matplotlib-inline<0.1.7"'
CFLAGS: "-fno-lto" # Ensure that disabling LTO works.
# https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954
# https://www.riverbankcomputing.com/pipermail/pyqt/2023-November/045606.html
Expand Down
20 changes: 8 additions & 12 deletions lib/matplotlib/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,7 @@ def _has_tex_package(package):
return False


def ipython_in_subprocess(
requested_backend_or_gui_framework,
expected_backend_old_ipython, # IPython < 8.24
expected_backend_new_ipython, # IPython >= 8.24
):
def ipython_in_subprocess(requested_backend_or_gui_framework, all_expected_backends):
import pytest
IPython = pytest.importorskip("IPython")

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

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

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

assert proc.stdout.strip() == f"Out[1]: '{expected_backend}'"
assert proc.stdout.strip().endswith(f"'{expected_backend}'")
3 changes: 1 addition & 2 deletions lib/matplotlib/testing/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ def _check_for_pgf(texsystem: str) -> bool: ...
def _has_tex_package(package: str) -> bool: ...
def ipython_in_subprocess(
requested_backend_or_gui_framework: str,
expected_backend_old_ipython: str,
expected_backend_new_ipython: str,
all_expected_backends: dict[tuple[int, int], str],
) -> None: ...
2 changes: 2 additions & 0 deletions lib/matplotlib/tests/test_backend_inline.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from pathlib import Path
from tempfile import TemporaryDirectory
import sys

import pytest

Expand All @@ -12,6 +13,7 @@
pytest.importorskip('matplotlib_inline')


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

Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/tests/test_backend_macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
assert mpl.rcParams["savefig.directory"] == f"{tmp_path}/test"


@pytest.mark.backend('macosx')

Check warning on line 49 in lib/matplotlib/tests/test_backend_macosx.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/tests/test_backend_macosx.py#L49

Added line #L49 was not covered by tests
def test_ipython():
from matplotlib.testing import ipython_in_subprocess
ipython_in_subprocess("osx", "MacOSX", "macosx")
ipython_in_subprocess("osx", {(8, 24): "macosx", (7, 0): "MacOSX"})

Check warning on line 52 in lib/matplotlib/tests/test_backend_macosx.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/tests/test_backend_macosx.py#L52

Added line #L52 was not covered by tests
3 changes: 2 additions & 1 deletion lib/matplotlib/tests/test_backend_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def custom_handler(signum, frame):
signal.signal(signal.SIGINT, original_handler)


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