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

Skip to content

Commit d738656

Browse files
committed
Test GUI
1 parent 19d93b7 commit d738656

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

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: 15 additions & 14 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,25 @@ 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+
if backend != "webagg":
155+
assert fig.canvas.manager.get_window_title() == "Figure 1"
157156

158157
if mpl.rcParams["toolbar"] == "toolmanager":
159158
# test toolbar button icon LA mode see GH issue 25174
@@ -164,8 +163,6 @@ def check_alt_backend(alt_backend):
164163
_test_toolbar_button_la_mode_icon(fig)
165164

166165
ax.plot([0, 1], [2, 3])
167-
if fig.canvas.toolbar: # i.e toolbar2.
168-
fig.canvas.toolbar.draw_rubberband(None, 1., 1, 2., 2)
169166

170167
timer = fig.canvas.new_timer(1.) # Test that floats are cast to int.
171168
timer.add_callback(KeyEvent("key_press_event", fig.canvas, "q")._process)
@@ -176,6 +173,10 @@ def check_alt_backend(alt_backend):
176173
result = io.BytesIO()
177174
fig.savefig(result, format='png')
178175

176+
if fig.canvas.toolbar: # i.e toolbar2.
177+
fig.canvas.toolbar.draw_rubberband(None, 1., 1, 2., 2)
178+
fig.canvas.toolbar.remove_rubberband()
179+
179180
plt.show()
180181

181182
# Ensure that the window is really closed.
@@ -189,7 +190,7 @@ def check_alt_backend(alt_backend):
189190
if not backend.startswith('qt5') and sys.platform == 'darwin':
190191
# FIXME: This should be enabled everywhere once Qt5 is fixed on macOS
191192
# to not resize incorrectly.
192-
assert_equal(result.getvalue(), result_after.getvalue())
193+
assert result.getvalue() == result_after.getvalue()
193194

194195

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

247248

0 commit comments

Comments
 (0)