Skip to content

fixes issue #2556 #2558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 27, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added test_quiver module
tests memory leaks reported in issue #2556
  • Loading branch information
tacaswell committed Jan 14, 2014
commit c312ccac6ae9e09e2c12f05ec27059d688c48a45
1 change: 1 addition & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@ def tk_window_focus():
'matplotlib.tests.test_patheffects',
'matplotlib.tests.test_pickle',
'matplotlib.tests.test_png',
'matplotlib.tests.test_quiver',
'matplotlib.tests.test_rcparams',
'matplotlib.tests.test_scale',
'matplotlib.tests.test_simplification',
Expand Down
54 changes: 54 additions & 0 deletions lib/matplotlib/tests/test_quiver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from __future__ import print_function
import os
import tempfile
import numpy as np
import sys
from matplotlib import pyplot as plt
from matplotlib.testing.decorators import cleanup


WRITER_OUTPUT = dict(ffmpeg='mp4', ffmpeg_file='mp4',
mencoder='mp4', mencoder_file='mp4',
avconv='mp4', avconv_file='mp4',
imagemagick='gif', imagemagick_file='gif')


@cleanup
def test_quiver_memory_leak():
fig, ax = plt.subplots()

X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .04),
np.arange(0, 2 * np.pi, .04))
U = np.cos(X)
V = np.sin(Y)

Q = ax.quiver(U, V)
ttX = Q.X
Q.remove()

del Q

assert sys.getrefcount(ttX) == 2


@cleanup
def test_quiver_key_memory_leak():
fig, ax = plt.subplots()

X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .04),
np.arange(0, 2 * np.pi, .04))
U = np.cos(X)
V = np.sin(Y)

Q = ax.quiver(U, V)

qk = ax.quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$',
labelpos='W',
fontproperties={'weight': 'bold'})
assert sys.getrefcount(qk) == 3
qk.remove()
assert sys.getrefcount(qk) == 2

if __name__ == '__main__':
import nose
nose.runmodule()