Skip to content

Commit d50bca8

Browse files
authored
Merge pull request #26060 from oscargus/guitest
Mnt: GUI tests
2 parents d2e9603 + 6a5d6c8 commit d50bca8

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ class FigureManagerWebAgg(backend_bases.FigureManagerBase):
427427
# This must be None to not break ipympl
428428
_toolbar2_class = None
429429
ToolbarCls = NavigationToolbar2WebAgg
430+
_window_title = "Matplotlib"
430431

431432
def __init__(self, canvas, num):
432433
self.web_sockets = set()
@@ -444,6 +445,10 @@ def resize(self, w, h, forward=True):
444445

445446
def set_window_title(self, title):
446447
self._send_event('figure_label', label=title)
448+
self._window_title = title
449+
450+
def get_window_title(self):
451+
return self._window_title
447452

448453
# The following methods are specific to FigureManagerWebAgg
449454

lib/matplotlib/tests/test_backend_tk.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ def target():
158158
thread.join()
159159

160160

161-
@pytest.mark.backend('TkAgg', skip_on_importerror=True)
162161
@pytest.mark.flaky(reruns=3)
163162
@_isolated_tk_test(success_count=0)
164163
def test_never_update():
@@ -199,7 +198,6 @@ class Toolbar(NavigationToolbar2Tk):
199198
print("success")
200199

201200

202-
@pytest.mark.backend('TkAgg', skip_on_importerror=True)
203201
@_isolated_tk_test(success_count=1)
204202
def test_canvas_focus():
205203
import tkinter as tk

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def _test_interactive_impl():
107107
import io
108108
import json
109109
import sys
110-
from unittest import TestCase
110+
111+
import pytest
111112

112113
import matplotlib as mpl
113114
from matplotlib import pyplot as plt
@@ -119,8 +120,6 @@ def _test_interactive_impl():
119120

120121
mpl.rcParams.update(json.loads(sys.argv[1]))
121122
backend = plt.rcParams["backend"].lower()
122-
assert_equal = TestCase().assertEqual
123-
assert_raises = TestCase().assertRaises
124123

125124
if backend.endswith("agg") and not backend.startswith(("gtk", "web")):
126125
# Force interactive framework setup.
@@ -135,25 +134,24 @@ def _test_interactive_impl():
135134
# uses no interactive framework).
136135

137136
if backend != "tkagg":
138-
with assert_raises(ImportError):
137+
with pytest.raises(ImportError):
139138
mpl.use("tkagg", force=True)
140139

141140
def check_alt_backend(alt_backend):
142141
mpl.use(alt_backend, force=True)
143142
fig = plt.figure()
144-
assert_equal(
145-
type(fig.canvas).__module__,
146-
f"matplotlib.backends.backend_{alt_backend}")
143+
assert (type(fig.canvas).__module__ ==
144+
f"matplotlib.backends.backend_{alt_backend}")
147145

148146
if importlib.util.find_spec("cairocffi"):
149147
check_alt_backend(backend[:-3] + "cairo")
150148
check_alt_backend("svg")
151149
mpl.use(backend, force=True)
152150

153151
fig, ax = plt.subplots()
154-
assert_equal(
155-
type(fig.canvas).__module__,
156-
f"matplotlib.backends.backend_{backend}")
152+
assert type(fig.canvas).__module__ == f"matplotlib.backends.backend_{backend}"
153+
154+
assert fig.canvas.manager.get_window_title() == "Figure 1"
157155

158156
if mpl.rcParams["toolbar"] == "toolmanager":
159157
# test toolbar button icon LA mode see GH issue 25174
@@ -189,7 +187,7 @@ def check_alt_backend(alt_backend):
189187
if not backend.startswith('qt5') and sys.platform == 'darwin':
190188
# FIXME: This should be enabled everywhere once Qt5 is fixed on macOS
191189
# to not resize incorrectly.
192-
assert_equal(result.getvalue(), result_after.getvalue())
190+
assert result.getvalue() == result_after.getvalue()
193191

194192

195193
@pytest.mark.parametrize("env", _get_testable_interactive_backends())
@@ -241,7 +239,7 @@ def _test_thread_impl():
241239
future.result() # Joins the thread; rethrows any exception.
242240
plt.close() # backend is responsible for flushing any events here
243241
if plt.rcParams["backend"].startswith("WX"):
244-
# TODO: debug why WX needs this only on py3.8
242+
# TODO: debug why WX needs this only on py >= 3.8
245243
fig.canvas.flush_events()
246244

247245

0 commit comments

Comments
 (0)