8000 Generalize test for multiple backends. · matplotlib/matplotlib@cb89b01 · GitHub
[go: up one dir, main page]

Skip to content

Commit cb89b01

Browse files
committed
Generalize test for multiple backends.
1 parent 8d7ccb0 commit cb89b01

File tree

2 files changed

+50
-34
lines changed

2 files changed

+50
-34
lines changed

lib/matplotlib/tests/test_backend_tk.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44
import platform
55
import subprocess
66
import sys
7-
import tempfile
8-
import warnings
9-
10-
from PIL import Image
117

128
import pytest
139

14-
import matplotlib
1510
from matplotlib import _c_internal_utils
16-
from matplotlib.backend_tools import ToolToggleBase
1711
from matplotlib.testing import subprocess_run_helper
18-
import matplotlib.pyplot as plt
1912

2013

2114
_test_timeout = 60 # A reasonably safe value for slower architectures.
@@ -185,32 +178,6 @@ def test_never_update():
185178
# checks them.
186179

187180

188-
@pytest.mark.backend('TkAgg', skip_on_importerror=True)
189-
@_isolated_tk_test(success_count=0)
190-
def test_toolbar_button_la_mode_icon():
191-
# test that icon in LA mode can be used for buttons
192-
# see GH#25164
193-
# tweaking toolbar raises an UserWarning
194-
with warnings.catch_warnings():
195-
warnings.simplefilter("ignore", UserWarning)
196-
matplotlib.rcParams["toolbar"] = "toolmanager"
197-
198-
# create an icon in LA mode
199-
with tempfile.TemporaryDirectory() as tempdir:
200-
img = Image.new("LA", (26, 26))
201-
tmp_img_path = os.path.join(tempdir, "test_la_icon.png")
202-
img.save(tmp_img_path)
203-
204-
class CustomTool(ToolToggleBase):
205-
image = tmp_img_path
206-
207-
fig = plt.figure()
208-
toolmanager = fig.canvas.manager.toolmanager
209-
toolbar = fig.canvas.manager.toolbar
210-
toolmanager.add_tool("test", CustomTool)
211-
toolbar.add_tool("test", "group")
212-
213-
214181
@_isolated_tk_test(success_count=2)
215182
def test_missing_back_button():
216183
import matplotlib.pyplot as plt

lib/matplotlib/tests/test_backend_tools.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
import os
2+
import subprocess
3+
import tempfile
4+
from PIL import Image
5+
16
import pytest
27

3-
from matplotlib.backend_tools import ToolHelpBase
8+
import matplotlib
9+
from matplotlib.backend_tools import ToolHelpBase, ToolToggleBase
10+
import matplotlib.pyplot as plt
11+
from matplotlib.testing import subproces 8000 s_run_helper
12+
from .test_backends_interactive import (
13+
_get_testable_interactive_backends, _test_timeout,
14+
)
415

516

617
@pytest.mark.parametrize('rc_shortcut,expected', [
@@ -18,3 +29,41 @@
1829
])
1930
def test_format_shortcut(rc_shortcut, expected):
2031
assert ToolHelpBase.format_shortcut(rc_shortcut) == expected
32+
33+
34+
def _test_toolbar_button_la_mode_icon_inside_subprocess():
35+
matplotlib.rcParams["toolbar"] = "toolmanager"
36+
# create an icon in LA mode
37+
with tempfile.TemporaryDirectory() as tempdir:
38+
img = Image.new("LA", (26, 26))
39+
tmp_img_path = os.path.join(tempdir, "test_la_icon.png")
40+
img.save(tmp_img_path)
41+
42+
class CustomTool(ToolToggleBase):
43+
image = tmp_img_path
44+
description = "" # gtk3 backend does not allow None
45+
46+
fig = plt.figure()
47+
toolmanager = fig.canvas.manager.toolmanager
48+
toolbar = fig.canvas.manager.toolbar
49+
toolmanager.add_tool("test", CustomTool)
50+
toolbar.add_tool("test", "group")
51+
52+
53+
@pytest.mark.parametrize(
54+
"env",
55+
_get_testable_interactive_backends(),
56+
)
57+
def test_toolbar_button_la_mode_icon(env):
58+
# test that icon in LA mode can be used for buttons
59+
# see GH#25164
60+
try:
61+
# run inside subprocess for a self-contained environment
62+
proc = subprocess_run_helper(
63+
_test_toolbar_button_la_mode_icon_inside_subprocess,
64+
timeout=_test_timeout,
65+
extra_env=env,
66+
)
67+
except subprocess.CalledProcessError as err:
68+
pytest.fail(
69+
f"subprocess failed to test intended behavior: {err.stderr}")

0 commit comments

Comments
 (0)
0