|
1 | 1 | from __future__ import (absolute_import, division, print_function,
|
2 | 2 | unicode_literals)
|
3 | 3 |
|
4 |
| -import six |
5 |
| - |
6 | 4 | import io
|
7 |
| -import os |
8 |
| - |
9 |
| -from distutils.version import LooseVersion as V |
| 5 | +from distutils.version import LooseVersion |
10 | 6 |
|
11 | 7 | import numpy as np
|
12 | 8 | from numpy.testing import assert_array_almost_equal
|
13 |
| - |
14 |
| -from nose.tools import assert_raises |
| 9 | +import pytest |
15 | 10 |
|
16 | 11 | from matplotlib.image import imread
|
17 | 12 | from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
|
18 | 13 | from matplotlib.figure import Figure
|
19 | 14 | from matplotlib.testing import skip
|
20 |
| -from matplotlib.testing.decorators import ( |
21 |
| - cleanup, image_comparison, knownfailureif) |
| 15 | +from matplotlib.testing.decorators import cleanup, image_comparison |
22 | 16 | from matplotlib import pyplot as plt
|
23 | 17 | from matplotlib import collections
|
24 | 18 | from matplotlib import path
|
@@ -73,71 +67,6 @@ def test_large_single_path_collection():
|
73 | 67 | plt.savefig(buff)
|
74 | 68 |
|
75 | 69 |
|
76 |
| -def report_memory(i): |
77 |
| - pid = os.getpid() |
78 |
| - a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines() |
79 |
| - print(i, ' ', a2[1], end=' ') |
80 |
| - return int(a2[1].split()[0]) |
81 |
| - |
82 |
| -# This test is disabled -- it uses old API. -ADS 2009-09-07 |
83 |
| -## def test_memleak(): |
84 |
| -## """Test agg backend for memory leaks.""" |
85 |
| -## from matplotlib.ft2font import FT2Font |
86 |
| -## from numpy.random import rand |
87 |
| -## from matplotlib.backend_bases import GraphicsContextBase |
88 |
| -## from matplotlib.backends._backend_agg import RendererAgg |
89 |
| - |
90 |
| -## fontname = '/usr/local/share/matplotlib/Vera.ttf' |
91 |
| - |
92 |
| -## N = 200 |
93 |
| -## for i in range( N ): |
94 |
| -## gc = GraphicsContextBase() |
95 |
| -## gc.set_clip_rectangle( [20, 20, 20, 20] ) |
96 |
| -## o = RendererAgg( 400, 400, 72 ) |
97 |
| - |
98 |
| -## for j in range( 50 ): |
99 |
| -## xs = [ 400*int(rand()) for k in range(8) ] |
100 |
| -## ys = [ 400*int(rand()) for k in range(8) ] |
101 |
| -## rgb = (1, 0, 0) |
102 |
| -## pnts = zip( xs, ys ) |
103 |
| -## o.draw_polygon( gc, rgb, pnts ) |
104 |
| -## o.draw_polygon( gc, None, pnts ) |
105 |
| - |
106 |
| -## for j in range( 50 ): |
107 |
| -## x = [ 400*int(rand()) for k in range(4) ] |
108 |
| -## y = [ 400*int(rand()) for k in range(4) ] |
109 |
| -## o.draw_lines( gc, x, y ) |
110 |
| - |
111 |
| -## for j in range( 50 ): |
112 |
| -## args = [ 400*int(rand()) for k in range(4) ] |
113 |
| -## rgb = (1, 0, 0) |
114 |
| -## o.draw_rectangle( gc, rgb, *args ) |
115 |
| - |
116 |
| -## if 1: # add text |
117 |
| -## font = FT2Font( fontname ) |
118 |
| -## font.clear() |
119 |
| -## font.set_text( 'hi mom', 60 ) |
120 |
| -## font.set_size( 12, 72 ) |
121 |
| -## o.draw_text_image( font.get_image(), 30, 40, gc ) |
122 |
| - |
123 |
| -## fname = "agg_memleak_%05d.png" |
124 |
| -## o.write_png( fname % i ) |
125 |
| -## val = report_memory( i ) |
126 |
| -## if i==1: start = val |
127 |
| - |
128 |
| -## end = val |
129 |
| -## avgMem = (end - start) / float(N) |
130 |
| -## print 'Average memory consumed per loop: %1.4f\n' % (avgMem) |
131 |
| - |
132 |
| -## #TODO: Verify the expected mem usage and approximate tolerance that |
133 |
| -## # should be used |
134 |
| -## #self.checkClose( 0.32, avgMem, absTol = 0.1 ) |
135 |
| - |
136 |
| -## # w/o text and w/o write_png: Average memory consumed per loop: 0.02 |
137 |
| -## # w/o text and w/ write_png : Average memory consumed per loop: 0.3400 |
138 |
| -## # w/ text and w/ write_png : Average memory consumed per loop: 0.32 |
139 |
| - |
140 |
| - |
141 | 70 | @cleanup
|
142 | 71 | def test_marker_with_nan():
|
143 | 72 | # This creates a marker with nans in it, which was segfaulting the
|
@@ -251,7 +180,7 @@ def process_image(self, padded_src, dpi):
|
251 | 180 | t2 = self.offset_filter.process_image(t1, dpi)
|
252 | 181 | return t2
|
253 | 182 |
|
254 |
| - if V(np.__version__) < V('1.7.0'): |
| 183 | + if LooseVersion(np.__version__) < LooseVersion('1.7.0'): |
255 | 184 | skip('Disabled on Numpy < 1.7.0')
|
256 | 185 |
|
257 | 186 | fig = plt.figure()
|
@@ -297,9 +226,5 @@ def process_image(self, padded_src, dpi):
|
297 | 226 | def test_too_large_image():
|
298 | 227 | fig = plt.figure(figsize=(300, 1000))
|
299 | 228 | buff = io.BytesIO()
|
300 |
| - assert_raises(ValueError, fig.savefig, buff) |
301 |
| - |
302 |
| - |
303 |
| -if __name__ == "__main__": |
304 |
| - import nose |
305 |
| - nose.runmodule(argv=['-s', '--with-doctest'], exit=False) |
| 229 | + with pytest.raises(ValueError): |
| 230 | + fig.savefig(buff) |
0 commit comments