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 8fa66a6

Browse filesBrowse files
committed
Fix tests
1 parent ba00a41 commit 8fa66a6
Copy full SHA for 8fa66a6

File tree

1 file changed

+41
-26
lines changed
Filter options

1 file changed

+41
-26
lines changed

‎lib/matplotlib/tests/test_text.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_text.py
+41-26Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ def test_contains():
175175

176176
# draw the text. This is important, as the contains method can only work
177177
# when a renderer exists.
178-
plt.draw()
178+
plt.ion()
179+
try:
180+
plt.draw()
181+
finally:
182+
plt.ioff()
179183

180184
for x, y in zip(xs.flat, ys.flat):
181185
mevent.x, mevent.y = plt.gca().transAxes.transform_point([x, y])
@@ -235,35 +239,40 @@ def test_axes_titles():
235239

236240
@cleanup
237241
def test_set_position():
238-
fig, ax = plt.subplots()
242+
plt.ion()
243+
244+
try:
245+
fig, ax = plt.subplots()
239246

240-
# test set_position
241-
ann = ax.annotate(
242-
'test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
243-
plt.draw()
247+
# test set_position
248+
ann = ax.annotate(
249+
'test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
250+
plt.draw()
244251

245-
init_pos = ann.get_window_extent(fig.canvas.renderer)
246-
shift_val = 15
247-
ann.set_position((shift_val, shift_val))
248-
plt.draw()
249-
post_pos = ann.get_window_extent(fig.canvas.renderer)
252+
init_pos = ann.get_window_extent(fig.canvas.renderer)
253+
shift_val = 15
254+
ann.set_position((shift_val, shift_val))
255+
plt.draw()
256+
post_pos = ann.get_window_extent(fig.canvas.renderer)
250257

251-
for a, b in zip(init_pos.min, post_pos.min):
252-
assert a + shift_val == b
258+
for a, b in zip(init_pos.min, post_pos.min):
259+
assert a + shift_val == b
253260

254-
# test xyann
255-
ann = ax.annotate(
256-
'test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
257-
plt.draw()
261+
# test xyann
262+
ann = ax.annotate(
263+
'test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
264+
plt.draw()
258265

259-
init_pos = ann.get_window_extent(fig.canvas.renderer)
260-
shift_val = 15
261-
ann.xyann = (shift_val, shift_val)
262-
plt.draw()
263-
post_pos = ann.get_window_extent(fig.canvas.renderer)
266+
init_pos = ann.get_window_extent(fig.canvas.renderer)
267+
shift_val = 15
268+
ann.xyann = (shift_val, shift_val)
269+
plt.draw()
270+
post_pos = ann.get_window_extent(fig.canvas.renderer)
264271

265-
for a, b in zip(init_pos.min, post_pos.min):
266-
assert a + shift_val == b
272+
for a, b in zip(init_pos.min, post_pos.min):
273+
assert a + shift_val == b
274+
finally:
275+
plt.ioff()
267276

268277

269278
def test_get_rotation_string():
@@ -373,8 +382,14 @@ def test_annotation_negative_fig_coords():
373382

374383
@cleanup
375384
def test_text_stale():
385+
# A version of draw_all that draws even when interactive is off
386+
def draw_all_when_not_interactive():
387+
for f_mgr in plt._pylab_helpers.Gcf.get_all_fig_managers():
388+
if f_mgr.canvas.figure.stale:
389+
f_mgr.canvas.draw()
390+
376391
fig, (ax1, ax2) = plt.subplots(1, 2)
377-
plt.draw_all()
392+
draw_all_when_not_interactive()
378393
assert not ax1.stale
379394
assert not ax2.stale
380395
assert not fig.stale
@@ -389,7 +404,7 @@ def test_text_stale():
389404
assert ann1.stale
390405
assert fig.stale
391406

392-
plt.draw_all()
407+
draw_all_when_not_interactive()
393408
assert not ax1.stale
394409
assert not ax2.stale
395410
assert not fig.stale

0 commit comments

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