Skip to content

Commit e9d0892

Browse files
authored
Merge pull request #7916 from QuLogic/pytest-ab
MAINT: Convert test_[ab]* files to pytest.
2 parents c93142f + 5c19e89 commit e9d0892

File tree

7 files changed

+34
-147
lines changed

7 files changed

+34
-147
lines changed

lib/matplotlib/__init__.py

-5
Original file line numberDiff line numberDiff line change
@@ -1474,18 +1474,13 @@ def _jupyter_nbextension_paths():
14741474

14751475

14761476
default_test_modules = [
1477-
'matplotlib.tests.test_agg',
1478-
'matplotlib.tests.test_arrow_patches',
1479-
'matplotlib.tests.test_artist',
14801477
'matplotlib.tests.test_backend_bases',
14811478
'matplotlib.tests.test_backend_pdf',
14821479
'matplotlib.tests.test_backend_pgf',
14831480
'matplotlib.tests.test_backend_ps',
14841481
'matplotlib.tests.test_backend_qt4',
14851482
'matplotlib.tests.test_backend_qt5',
14861483
'matplotlib.tests.test_backend_svg',
1487-
'matplotlib.tests.test_basic',
1488-
'matplotlib.tests.test_bbox_tight',
14891484
'matplotlib.tests.test_coding_standards',
14901485
'matplotlib.tests.test_dviread',
14911486
'matplotlib.tests.test_figure',

lib/matplotlib/tests/test_agg.py

+6-81
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33

4-
import six
5-
64
import io
7-
import os
8-
9-
from distutils.version import LooseVersion as V
5+
from distutils.version import LooseVersion
106

117
import numpy as np
128
from numpy.testing import assert_array_almost_equal
13-
14-
from nose.tools import assert_raises
9+
import pytest
1510

1611
from matplotlib.image import imread
1712
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
1813
from matplotlib.figure import Figure
1914
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
2216
from matplotlib import pyplot as plt
2317
from matplotlib import collections
2418
from matplotlib import path
@@ -73,71 +67,6 @@ def test_large_single_path_collection():
7367
plt.savefig(buff)
7468

7569

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-
14170
@cleanup
14271
def test_marker_with_nan():
14372
# This creates a marker with nans in it, which was segfaulting the
@@ -251,7 +180,7 @@ def process_image(self, padded_src, dpi):
251180
t2 = self.offset_filter.process_image(t1, dpi)
252181
return t2
253182

254-
if V(np.__version__) < V('1.7.0'):
183+
if LooseVersion(np.__version__) < LooseVersion('1.7.0'):
255184
skip('Disabled on Numpy < 1.7.0')
256185

257186
fig = plt.figure()
@@ -297,9 +226,5 @@ def process_image(self, padded_src, dpi):
297226
def test_too_large_image():
298227
fig = plt.figure(figsize=(300, 1000))
299228
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)

lib/matplotlib/tests/test_arrow_patches.py

-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33

4-
import six
5-
64
import matplotlib.pyplot as plt
75
from matplotlib.testing.decorators import image_comparison
86
import matplotlib.patches as mpatches
@@ -121,8 +119,3 @@ def test_fancyarrow_dash():
121119
color='k')
122120
ax.add_patch(e)
123121
ax.add_patch(e2)
124-
125-
126-
if __name__ == '__main__':
127-
import nose
128-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_artist.py

+18-26
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
3-
import warnings
4-
import six
53

64
import io
5+
import warnings
76
from itertools import chain
7+
88
import numpy as np
99

1010
import matplotlib.pyplot as plt
@@ -14,11 +14,8 @@
1414
import matplotlib.transforms as mtrans
1515
import matplotlib.collections as mcollections
1616
import matplotlib.artist as martist
17-
import matplotlib as mpl
1817
from matplotlib.testing.decorators import image_comparison, cleanup
1918

20-
from nose.tools import (assert_true, assert_false)
21-
2219

2320
@cleanup
2421
def test_patch_transform_of_none():
@@ -72,7 +69,7 @@ def test_collection_transform_of_none():
7269
ax.set_xlim([1, 3])
7370
ax.set_ylim([1, 3])
7471

75-
#draw an ellipse over data coord (2,2) by specifying device coords
72+
# draw an ellipse over data coord (2,2) by specifying device coords
7673
xy_data = (2, 2)
7774
xy_pix = ax.transData.transform_point(xy_data)
7875

@@ -184,28 +181,28 @@ def test_remove():
184181
im = ax.imshow(np.arange(36).reshape(6, 6))
185182
ln, = ax.plot(range(5))
186183

187-
assert_true(fig.stale)
188-
assert_true(ax.stale)
184+
assert fig.stale
185+
assert ax.stale
189186

190187
fig.canvas.draw()
191-
assert_false(fig.stale)
192-
assert_false(ax.stale)
193-
assert_false(ln.stale)
188+
assert not fig.stale
189+
assert not ax.stale
190+
assert not ln.stale
194191

195-
assert_true(im in ax.mouseover_set)
196-
assert_true(ln not in ax.mouseover_set)
197-
assert_true(im.axes is ax)
192+
assert im in ax.mouseover_set
193+
assert ln not in ax.mouseover_set
194+
assert im.axes is ax
198195

199196
im.remove()
200197
ln.remove()
201198

202199
for art in [im, ln]:
203-
assert_true(art.axes is None)
204-
assert_true(art.figure is None)
200+
assert art.axes is None
201+
assert art.figure is None
205202

206-
assert_true(im not in ax.mouseover_set)
207-
assert_true(fig.stale)
208-
assert_true(ax.stale)
203+
assert im not in ax.mouseover_set
204+
assert fig.stale
205+
assert ax.stale
209206

210207

211208
@image_comparison(baseline_images=["default_edges"], remove_text=True,
@@ -221,8 +218,8 @@ def test_default_edges():
221218
ax3.set_ylim((-1, 1))
222219
pp1 = mpatches.PathPatch(
223220
mpath.Path([(0, 0), (1, 0), (1, 1), (0, 0)],
224-
[mpath.Path.MOVETO, mpath.Path.CURVE3,
225-
mpath.Path.CURVE3, mpath.Path.CLOSEPOLY]),
221+
[mpath.Path.MOVETO, mpath.Path.CURVE3,
222+
mpath.Path.CURVE3, mpath.Path.CLOSEPOLY]),
226223
fc="none", transform=ax4.transData)
227224
ax4.add_patch(pp1)
228225

@@ -254,8 +251,3 @@ def test_setp():
254251
sio = io.StringIO()
255252
plt.setp(lines1, 'zorder', file=sio)
256253
assert sio.getvalue() == ' zorder: any number \n'
257-
258-
259-
if __name__ == '__main__':
260-
import nose
261-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_basic.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
import six
55
import sys
66

7-
import warnings
8-
9-
from nose.tools import assert_equal
10-
117
from ..testing.decorators import knownfailureif, skipif
128

139

@@ -19,13 +15,13 @@ def setup_module():
1915

2016

2117
def test_simple():
22-
assert_equal(1 + 1, 2)
18+
assert 1 + 1 == 2
2319

2420

2521
@knownfailureif(True)
2622
def test_simple_knownfail():
2723
# Test the known fail mechanism.
28-
assert_equal(1 + 1, 3)
24+
assert 1 + 1 == 3
2925

3026

3127
@skipif(True, reason="skipif decorator test with bool condition passed")
@@ -91,8 +87,3 @@ def test_override_builtins():
9187
overridden = True
9288

9389
assert not overridden
94-
95-
96-
if __name__ == '__main__':
97-
import nose
98-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_bbox_tight.py

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33

4-
import six
5-
from six.moves import xrange
6-
74
import numpy as np
85

9-
from matplotlib import rcParams
106
from matplotlib.testing.decorators import image_comparison
117
import matplotlib.pyplot as plt
128
import matplotlib.path as mpath
@@ -18,11 +14,11 @@
1814
savefig_kwarg=dict(bbox_inches='tight'))
1915
def test_bbox_inches_tight():
2016
#: Test that a figure saved using bbox_inches='tight' is clipped correctly
21-
data = [[ 66386, 174296, 75131, 577908, 32015],
22-
[ 58230, 381139, 78045, 99308, 160454],
23-
[ 89135, 80552, 152558, 497981, 603535],
24-
[ 78415, 81858, 150656, 193263, 69638],
25-
[139361, 331509, 343164, 781380, 52269]]
17+
data = [[66386, 174296, 75131, 577908, 32015],
18+
[58230, 381139, 78045, 99308, 160454],
19+
[89135, 80552, 152558, 497981, 603535],
20+
[78415, 81858, 150656, 193263, 69638],
21+
[139361, 331509, 343164, 781380, 52269]]
2622

2723
colLabels = rowLabels = [''] * 5
2824

@@ -33,7 +29,7 @@ def test_bbox_inches_tight():
3329
yoff = np.array([0.0] * len(colLabels))
3430
# the bottom values for stacked bar chart
3531
fig, ax = plt.subplots(1, 1)
36-
for row in xrange(rows):
32+
for row in range(rows):
3733
ax.bar(ind, data[row], width, bottom=yoff, color='b')
3834
yoff = yoff + data[row]
3935
cellText.append([''])
@@ -49,7 +45,7 @@ def test_bbox_inches_tight():
4945
@image_comparison(baseline_images=['bbox_inches_tight_suptile_legend'],
5046
remove_text=False, savefig_kwarg={'bbox_inches': 'tight'})
5147
def test_bbox_inches_tight_suptile_legend():
52-
plt.plot(list(xrange(10)), label='a straight line')
48+
plt.plot(np.arange(10), label='a straight line')
5349
plt.legend(bbox_to_anchor=(0.9, 1), loc=2, )
5450
plt.title('Axis title')
5551
plt.suptitle('Figure title')
@@ -70,7 +66,7 @@ def y_formatter(y, pos):
7066
def test_bbox_inches_tight_clipping():
7167
# tests bbox clipping on scatter points, and path clipping on a patch
7268
# to generate an appropriately tight bbox
73-
plt.scatter(list(xrange(10)), list(xrange(10)))
69+
plt.scatter(np.arange(10), np.arange(10))
7470
ax = plt.gca()
7571
ax.set_xlim([0, 5])
7672
ax.set_ylim([0, 5])
@@ -93,7 +89,3 @@ def test_bbox_inches_tight_raster():
9389
fig = plt.figure()
9490
ax = fig.add_subplot(111)
9591
ax.plot([1.0, 2.0], rasterized=True)
96-
97-
if __name__ == '__main__':
98-
import nose
99-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_coding_standards.py

-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ def test_pep8_conformance_installed_files():
203203
'testing/jpl_units/__init__.py',
204204
'tri/triinterpolate.py',
205205
'tests/test_axes.py',
206-
'tests/test_bbox_tight.py',
207206
'tests/test_image.py',
208207
'tests/test_lines.py',
209208
'tests/test_mathtext.py',

0 commit comments

Comments
 (0)