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