@@ -107,7 +107,8 @@ def _test_interactive_impl():
107
107
import io
108
108
import json
109
109
import sys
110
- from unittest import TestCase
110
+
111
+ import pytest
111
112
112
113
import matplotlib as mpl
113
114
from matplotlib import pyplot as plt
@@ -119,8 +120,6 @@ def _test_interactive_impl():
119
120
120
121
mpl .rcParams .update (json .loads (sys .argv [1 ]))
121
122
backend = plt .rcParams ["backend" ].lower ()
122
- assert_equal = TestCase ().assertEqual
123
- assert_raises = TestCase ().assertRaises
124
123
125
124
if backend .endswith ("agg" ) and not backend .startswith (("gtk" , "web" )):
126
125
# Force interactive framework setup.
@@ -135,25 +134,25 @@ def _test_interactive_impl():
135
134
# uses no interactive framework).
136
135
137
136
if backend != "tkagg" :
138
- with assert_raises (ImportError ):
137
+ with pytest . raises (ImportError ):
139
138
mpl .use ("tkagg" , force = True )
140
139
141
140
def check_alt_backend (alt_backend ):
142
141
mpl .use (alt_backend , force = True )
143
142
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 } " )
147
145
148
146
if importlib .util .find_spec ("cairocffi" ):
149
147
check_alt_backend (backend [:- 3 ] + "cairo" )
150
148
check_alt_backend ("svg" )
151
149
mpl .use (backend , force = True )
152
150
153
151
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"
157
156
158
157
if mpl .rcParams ["toolbar" ] == "toolmanager" :
159
158
# test toolbar button icon LA mode see GH issue 25174
@@ -164,8 +163,6 @@ def check_alt_backend(alt_backend):
164
163
_test_toolbar_button_la_mode_icon (fig )
165
164
166
165
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 )
169
166
170
167
timer = fig .canvas .new_timer (1. ) # Test that floats are cast to int.
171
168
timer .add_callback (KeyEvent ("key_press_event" , fig .canvas , "q" )._process )
@@ -176,6 +173,10 @@ def check_alt_backend(alt_backend):
176
173
result = io .BytesIO ()
177
174
fig .savefig (result , format = 'png' )
178
175
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
+
179
180
plt .show ()
180
181
181
182
# Ensure that the window is really closed.
@@ -189,7 +190,7 @@ def check_alt_backend(alt_backend):
189
190
if not backend .startswith ('qt5' ) and sys .platform == 'darwin' :
190
191
# FIXME: This should be enabled everywhere once Qt5 is fixed on macOS
191
192
# to not resize incorrectly.
192
- assert_equal ( result .getvalue (), result_after .getvalue () )
193
+ assert result .getvalue () == result_after .getvalue ()
193
194
194
195
195
196
@pytest .mark .parametrize ("env" , _get_testable_interactive_backends ())
@@ -241,7 +242,7 @@ def _test_thread_impl():
241
242
future .result () # Joins the thread; rethrows any exception.
242
243
plt .close () # backend is responsible for flushing any events here
243
244
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
245
246
fig .canvas .flush_events ()
246
247
247
248
0 commit comments