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

Skip to content

Commit c312cca

Browse files
committed
added test_quiver module
tests memory leaks reported in issue #2556
1 parent 5e69629 commit c312cca

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

lib/matplotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,7 @@ def tk_window_focus():
12551255
'matplotlib.tests.test_patheffects',
12561256
'matplotlib.tests.test_pickle',
12571257
'matplotlib.tests.test_png',
1258+
'matplotlib.tests.test_quiver',
12581259
'matplotlib.tests.test_rcparams',
12591260
'matplotlib.tests.test_scale',
12601261
'matplotlib.tests.test_simplification',

lib/matplotlib/tests/test_quiver.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from __future__ import print_function
2+
import os
3+
import tempfile
4+
import numpy as np
5+
import sys
6+
from matplotlib import pyplot as plt
7+
from matplotlib.testing.decorators import cleanup
8+
9+
10+
WRITER_OUTPUT = dict(ffmpeg='mp4', ffmpeg_file='mp4',
11+
mencoder='mp4', mencoder_file='mp4',
12+
avconv='mp4', avconv_file='mp4',
13+
imagemagick='gif', imagemagick_file='gif')
14+
15+
16+
@cleanup
17+
def test_quiver_memory_leak():
18+
fig, ax = plt.subplots()
19+
20+
X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .04),
21+
np.arange(0, 2 * np.pi, .04))
22+
U = np.cos(X)
23+
V = np.sin(Y)
24+
25+
Q = ax.quiver(U, V)
26+
ttX = Q.X
27+
Q.remove()
28+
29+
del Q
30+
31+
assert sys.getrefcount(ttX) == 2
32+
33+
34+
@cleanup
35+
def test_quiver_key_memory_leak():
36+
fig, ax = plt.subplots()
37+
38+
X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .04),
39+
np.arange(0, 2 * np.pi, .04))
40+
U = np.cos(X)
41+
V = np.sin(Y)
42+
43+
Q = ax.quiver(U, V)
44+
45+
qk = ax.quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$',
46+
labelpos='W',
47+
fontproperties={'weight': 'bold'})
48+
assert sys.getrefcount(qk) == 3
49+
qk.remove()
50+
assert sys.getrefcount(qk) == 2
51+
52+
if __name__ == '__main__':
53+
import nose
54+
nose.runmodule()

0 commit comments

Comments
 (0)