Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

TST: Run macosx backends in a subprocess #29150

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 1 commit into from
Nov 20, 2024
Merged
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
45 changes: 32 additions & 13 deletions 45 lib/matplotlib/tests/test_backend_macosx.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import os
from pathlib import Path

import pytest
from unittest import mock

import matplotlib as mpl
import matplotlib.pyplot as plt
try:
from matplotlib.backends import _macosx
except ImportError:
pytest.skip("These are mac only tests", allow_module_level=True)
from matplotlib.testing import subprocess_run_helper


@pytest.mark.backend('macosx')
def test_cached_renderer():
_test_timeout = 60


def _test_cached_renderer():
# Make sure that figures have an associated renderer after
# a fig.canvas.draw() call
fig = plt.figure(1)
Expand All @@ -24,8 +24,14 @@ def test_cached_renderer():
assert fig.canvas.get_renderer()._renderer is not None


@pytest.mark.backend('macosx')
def test_savefig_rcparam(monkeypatch, tmp_path):
@pytest.mark.backend('macosx', skip_on_importerror=True)
def test_cached_renderer():
subprocess_run_helper(_test_cached_renderer, timeout=_test_timeout,
extra_env={"MPLBACKEND": "macosx"})


def _test_savefig_rcparam():
tmp_path = Path(os.environ["TEST_SAVEFIG_PATH"])

def new_choose_save_file(title, directory, filename):
# Replacement function instead of opening a GUI window
Expand All @@ -34,9 +40,10 @@ def new_choose_save_file(title, directory, filename):
os.makedirs(f"{directory}/test")
return f"{directory}/test/{filename}"

monkeypatch.setattr(_macosx, "choose_save_file", new_choose_save_file)
fig = plt.figure()
with mpl.rc_context({"savefig.directory": tmp_path}):
with (mock.patch("matplotlib.backends._macosx.choose_save_file",
new_choose_save_file),
mpl.rc_context({"savefig.directory": tmp_path})):
fig.canvas.toolbar.save_figure()
# Check the saved location got created
save_file = f"{tmp_path}/test/{fig.canvas.get_default_filename()}"
Expand All @@ -47,14 +54,20 @@ def new_choose_save_file(title, directory, filename):
assert mpl.rcParams["savefig.directory"] == f"{tmp_path}/test"


@pytest.mark.backend('macosx')
@pytest.mark.backend('macosx', skip_on_importerror=True)
def test_savefig_rcparam(tmp_path):
subprocess_run_helper(
_test_savefig_rcparam, timeout=_test_timeout,
extra_env={"MPLBACKEND": "macosx", "TEST_SAVEFIG_PATH": tmp_path})


@pytest.mark.backend('macosx', skip_on_importerror=True)
def test_ipython():
from matplotlib.testing import ipython_in_subprocess
ipython_in_subprocess("osx", {(8, 24): "macosx", (7, 0): "MacOSX"})


@pytest.mark.backend('macosx')
def test_save_figure_return():
def _test_save_figure_return():
fig, ax = plt.subplots()
ax.imshow([[1]])
prop = "matplotlib.backends._macosx.choose_save_file"
Expand All @@ -65,3 +78,9 @@ def test_save_figure_return():
with mock.patch(prop, return_value=None):
fname = fig.canvas.manager.toolbar.save_figure()
assert fname is None


@pytest.mark.backend('macosx', skip_on_importerror=True)
def test_save_figure_return():
subprocess_run_helper(_test_save_figure_return, timeout=_test_timeout,
extra_env={"MPLBACKEND": "macosx"})
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.