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

Commit 647b005

Browse filesBrowse files
authored
Merge pull request #29150 from QuLogic/macosx-subprocess
TST: Run macosx backends in a subprocess
2 parents 183b04f + c97d30d commit 647b005
Copy full SHA for 647b005

File tree

Expand file treeCollapse file tree

1 file changed

+32
-13
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+32
-13
lines changed
+32-13Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import os
2+
from pathlib import Path
23

34
import pytest
45
from unittest import mock
56

67
import matplotlib as mpl
78
import matplotlib.pyplot as plt
8-
try:
9-
from matplotlib.backends import _macosx
10-
except ImportError:
11-
pytest.skip("These are mac only tests", allow_module_level=True)
9+
from matplotlib.testing import subprocess_run_helper
1210

1311

14-
@pytest.mark.backend('macosx')
15-
def test_cached_renderer():
12+
_test_timeout = 60
13+
14+
15+
def _test_cached_renderer():
1616
# Make sure that figures have an associated renderer after
1717
# a fig.canvas.draw() call
1818
fig = plt.figure(1)
@@ -24,8 +24,14 @@ def test_cached_renderer():
2424
assert fig.canvas.get_renderer()._renderer is not None
2525

2626

27-
@pytest.mark.backend('macosx')
28-
def test_savefig_rcparam(monkeypatch, tmp_path):
27+
@pytest.mark.backend('macosx', skip_on_importerror=True)
28+
def test_cached_renderer():
29+
subprocess_run_helper(_test_cached_renderer, timeout=_test_timeout,
30+
extra_env={"MPLBACKEND": "macosx"})
31+
32+
33+
def _test_savefig_rcparam():
34+
tmp_path = Path(os.environ["TEST_SAVEFIG_PATH"])
2935

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

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

4956

50-
@pytest.mark.backend('macosx')
57+
@pytest.mark.backend('macosx', skip_on_importerror=True)
58+
def test_savefig_rcparam(tmp_path):
59+
subprocess_run_helper(
60+
_test_savefig_rcparam, timeout=_test_timeout,
61+
extra_env={"MPLBACKEND": "macosx", "TEST_SAVEFIG_PATH": tmp_path})
62+
63+
64+
@pytest.mark.backend('macosx', skip_on_importerror=True)
5165
def test_ipython():
5266
from matplotlib.testing import ipython_in_subprocess
5367
ipython_in_subprocess("osx", {(8, 24): "macosx", (7, 0): "MacOSX"})
5468

5569

56-
@pytest.mark.backend('macosx')
57-
def test_save_figure_return():
70+
def _test_save_figure_return():
5871
fig, ax = plt.subplots()
5972
ax.imshow([[1]])
6073
prop = "matplotlib.backends._macosx.choose_save_file"
@@ -65,3 +78,9 @@ def test_save_figure_return():
6578
with mock.patch(prop, return_value=None):
6679
fname = fig.canvas.manager.toolbar.save_figure()
6780
assert fname is None
81+
82+
83+
@pytest.mark.backend('macosx', skip_on_importerror=True)
84+
def test_save_figure_return():
85+
subprocess_run_helper(_test_save_figure_return, timeout=_test_timeout,
86+
extra_env={"MPLBACKEND": "macosx"})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.