8000 Merge pull request #7918 from QuLogic/pytest-s-modules · matplotlib/matplotlib@bb4d920 · GitHub
[go: up one dir, main page]

Skip to content

Commit bb4d920

Browse files
authored
Merge pull request #7918 from QuLogic/pytest-s-modules
MAINT Convert test_s* files to pytest and flake8 them
2 parents e9d0892 + 72807ab commit bb4d920

File tree

10 files changed

+72
-117
lines changed

10 files changed

+72
-117
lines changed

lib/matplotlib/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,14 +1497,6 @@ def _jupyter_nbextension_paths():
14971497
'matplotlib.tests.test_pickle',
14981498
'matplotlib.tests.test_png',
14991499
'matplotlib.tests.test_quiver',
1500-
'matplotlib.tests.test_sankey',
1501-
'matplotlib.tests.test_scale',
1502-
'matplotlib.tests.test_simplification',
1503-
'matplotlib.tests.test_skew',
1504-
'matplotlib.tests.test_spines',
1505-
'matplotlib.tests.test_streamplot',
1506-
'matplotlib.tests.test_style',
1507-
'matplotlib.tests.test_subplots',
15081500
'matplotlib.tests.test_text',
15091501
'matplotlib.tests.test_texmanager',
15101502
'matplotlib.tests.test_type1font',

lib/matplotlib/tests/test_coding_standards.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ def test_pep8_conformance_installed_files():
207207
'tests/test_lines.py',
208208
'tests/test_mathtext.py',
209209
'tests/test_rcparams.py',
210-
'tests/test_simplification.py',
211-
'tests/test_streamplot.py',
212-
'tests/test_subplots.py',
213210
'tests/test_tightlayout.py',
214211
'tests/test_triangulation.py',
215212
'backends/backend_agg.py',

lib/matplotlib/tests/test_sankey.py

Lines changed: 0 additions & 7 deletions
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
from matplotlib.sankey import Sankey
75
from matplotlib.testing.decorators import cleanup
86

@@ -12,8 +10,3 @@ def test_sankey():
1210
# lets just create a sankey instance and check the code runs
1311
sankey = Sankey()
1412
sankey.add()
15-
16-
17-
if __name__ == '__main__':
18-
import nose
19-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_scale.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,3 @@ def test_log_scatter():
4646

4747
buf = io.BytesIO()
4848
fig.savefig(buf, format='svg')
49-
50-
51-
if __name__ == '__main__':
52-
import nose
53-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33

4-
import six
4+
import io
55

66
import numpy as np
7-
import matplotlib
8-
from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
7+
import pytest
8+
9+
from matplotlib.testing.decorators import image_comparison, cleanup
910
import matplotlib.pyplot as plt
1011

11-
from matplotlib import patches, path, transforms
12+
from matplotlib import patches, transforms
13+
from matplotlib.path import Path
1214

13-
from nose.tools import raises
14-
import io
15-
16-
nan = np.nan
17-
Path = path.Path
1815

1916
# NOTE: All of these tests assume that path.simplify is set to True
2017
# (the default)
@@ -24,39 +21,38 @@ def test_clipping():
2421
t = np.arange(0.0, 2.0, 0.01)
2522
s = np.sin(2*np.pi*t)
2623

27-
fig = plt.figure()
28-
ax = fig.add_subplot(111)
24+
fig, ax = plt.subplots()
2925
ax.plot(t, s, linewidth=1.0)
3026
ax.set_ylim((-0.20, -0.28))
3127

28+
3229
@image_comparison(baseline_images=['overflow'], remove_text=True)
3330
def test_overflow():
34-
x = np.array([1.0,2.0,3.0,2.0e5])
31+
x = np.array([1.0, 2.0, 3.0, 2.0e5])
3532
y = np.arange(len(x))
3633

37-
fig = plt.figure()
38-
ax = fig.add_subplot(111)
39-
ax.plot(x,y)
40-
ax.set_xlim(xmin=2,xmax=6)
34+
fig, ax = plt.subplots()
35+
ax.plot(x, y)
36+
ax.set_xlim(xmin=2, xmax=6)
37+
4138

4239
@image_comparison(baseline_images=['clipping_diamond'], remove_text=True)
4340
def test_diamond():
4441
x = np.array([0.0, 1.0, 0.0, -1.0, 0.0])
4542
y = np.array([1.0, 0.0, -1.0, 0.0, 1.0])
4643

47-
fig = plt.figure()
48-
ax = fig.add_subplot(111)
44+
fig, ax = plt.subplots()
4945
ax.plot(x, y)
5046
ax.set_xlim(xmin=-0.6, xmax=0.6)
5147
ax.set_ylim(ymin=-0.6, ymax=0.6)
5248

49+
5350
@cleanup
5451
def test_noise():
5552
np.random.seed(0)
5653
x = np.random.uniform(size=(5000,)) * 50
5754

58-
fig = plt.figure()
59-
ax = fig.add_subplot(111)
55+
fig, ax = plt.subplots()
6056
p1 = ax.plot(x, solid_joinstyle='round', linewidth=2.0)
6157

6258
path = p1[0].get_path()
@@ -66,13 +62,14 @@ def test_noise():
6662

6763
assert len(simplified) == 3884
6864

65+
6966
@cleanup
7067
def test_sine_plus_noise():
7168
np.random.seed(0)
72-
x = np.sin(np.linspace(0, np.pi * 2.0, 1000)) + np.random.uniform(size=(1000,)) * 0.01
69+
x = (np.sin(np.linspace(0, np.pi * 2.0, 1000)) +
70+
np.random.uniform(size=(1000,)) * 0.01)
7371

74-
fig = plt.figure()
75-
ax = fig.add_subplot(111)
72+
fig, ax = plt.subplots()
7673
p1 = ax.plot(x, solid_joinstyle='round', linewidth=2.0)
7774

7875
path = p1[0].get_path()
@@ -82,32 +79,34 @@ def test_sine_plus_noise():
8279

8380
assert len(simplified) == 876
8481

82+
8583
@image_comparison(baseline_images=['simplify_curve'], remove_text=True)
8684
def test_simplify_curve():
8785
pp1 = patches.PathPatch(
88-
Path([(0, 0), (1, 0), (1, 1), (nan, 1), (0, 0), (2, 0), (2, 2), (0, 0)],
89-
[Path.MOVETO, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CLOSEPOLY]),
86+
Path([(0, 0), (1, 0), (1, 1), (np.nan, 1), (0, 0), (2, 0), (2, 2),
87+
(0, 0)],
88+
[Path.MOVETO, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3,
89+
Path.CURVE3, Path.CURVE3, Path.CLOSEPOLY]),
9090
fc="none")
9191

92-
fig = plt.figure()
93-
ax = fig.add_subplot(111)
92+
fig, ax = plt.subplots()
9493
ax.add_patch(pp1)
9594
ax.set_xlim((0, 2))
9695
ax.set_ylim((0, 2))
9796

97+
9898
@image_comparison(baseline_images=['hatch_simplify'], remove_text=True)
9999
def test_hatch():
100-
fig = plt.figure()
101-
ax = fig.add_subplot(111)
100+
fig, ax = plt.subplots()
102101
ax.add_patch(plt.Rectangle((0, 0), 1, 1, fill=False, hatch="/"))
103102
ax.set_xlim((0.45, 0.55))
104103
ax.set_ylim((0.45, 0.55))
105104

105+
106106
@image_comparison(baseline_images=['fft_peaks'], remove_text=True)
107107
def test_fft_peaks():
108-
fig = plt.figure()
108+
fig, ax = plt.subplots()
109109
t = np.arange(65536)
110-
ax = fig.add_subplot(111)
111110
p1 = ax.plot(abs(np.fft.fft(np.sin(2*np.pi*.01*t)*np.blackman(len(t)))))
112111

113112
path = p1[0].get_path()
@@ -117,6 +116,7 @@ def test_fft_peaks():
117116

118117
assert len(simplified) == 20
119118

119+
120120
@cleanup
121121
def test_start_with_moveto():
122122
# Should be entirely clipped away to a single MOVETO
@@ -153,33 +153,33 @@ def test_start_with_moveto():
153153
verts = np.fromstring(decodebytes(data), dtype='<i4')
154154
verts = verts.reshape((len(verts) // 2, 2))
155155
path = Path(verts)
156-
segs = path.iter_segments(transforms.IdentityTransform(), clip=(0.0, 0.0, 100.0, 100.0))
156+
segs = path.iter_segments(transforms.IdentityTransform(),
157+
clip=(0.0, 0.0, 100.0, 100.0))
157158
segs = list(segs)
158159
assert len(segs) == 1
159160
assert segs[0][1] == Path.MOVETO
160161

162+
161163
@cleanup
162-
@raises(OverflowError)
163164
def test_throw_rendering_complexity_exceeded():
164165
plt.rcParams['path.simplify'] = False
165166
xx = np.arange(200000)
166167
yy = np.random.rand(200000)
167168
yy[1000] = np.nan
168-
fig = plt.figure()
169-
ax = fig.add_subplot(111)
169+
170+
fig, ax = plt.subplots()
170171
ax.plot(xx, yy)
171-
try:
172+
with pytest.raises(OverflowError):
172173
fig.savefig(io.BytesIO())
173-
finally:
174-
plt.rcParams['path.simplify'] = True
174+
175175

176176
@image_comparison(baseline_images=['clipper_edge'], remove_text=True)
177177
def test_clipper():
178178
dat = (0, 1, 0, 2, 0, 3, 0, 4, 0, 5)
179179
fig = plt.figure(figsize=(2, 1))
180-
fig.subplots_adjust(left = 0, bottom = 0, wspace = 0, hspace = 0)
180+
fig.subplots_adjust(left=0, bottom=0, wspace=0, hspace=0)
181181

182-
ax = fig.add_axes((0, 0, 1.0, 1.0), ylim = (0, 5), autoscale_on = False)
182+
ax = fig.add_axes((0, 0, 1.0, 1.0), ylim=(0, 5), autoscale_on=False)
183183
ax.plot(dat)
184184
ax.xaxis.set_major_locator(plt.MultipleLocator(1))
185185
ax.yaxis.set_major_locator(plt.MultipleLocator(1))
@@ -188,44 +188,39 @@ def test_clipper():
188188

189189
ax.set_xlim(5, 9)
190190

191+
191192
@image_comparison(baseline_images=['para_equal_perp'], remove_text=True)
192193
def test_para_equal_perp():
193194
x = np.array([0, 1, 2, 1, 0, -1, 0, 1] + [1] * 128)
194195
y = np.array([1, 1, 2, 1, 0, -1, 0, 0] + [0] * 128)
195196

196-
fig = plt.figure()
197-
ax = fig.add_subplot(111)
197+
fig, ax = plt.subplots()
198198
ax.plot(x + 1, y + 1)
199199
ax.plot(x + 1, y + 1, 'ro')
200200

201+
201202
@image_comparison(baseline_images=['clipping_with_nans'])
202203
def test_clipping_with_nans():
203204
x = np.linspace(0, 3.14 * 2, 3000)
204205
y = np.sin(x)
205206
x[::100] = np.nan
206207

207-
fig = plt.figure()
208-
ax = fig.add_subplot(111)
208+
fig, ax = plt.subplots()
209209
ax.plot(x, y)
210210
ax.set_ylim(-0.25, 0.25)
211211

212212

213213
def test_clipping_full():
214-
p = path.Path([[1e30, 1e30]] * 5)
214+
p = Path([[1e30, 1e30]] * 5)
215215
simplified = list(p.iter_segments(clip=[0, 0, 100, 100]))
216216
assert simplified == []
217217

218-
p = path.Path([[50, 40], [75, 65]], [1, 2])
218+
p = Path([[50, 40], [75, 65]], [1, 2])
219219
simplified = list(p.iter_segments(clip=[0, 0, 100, 100]))
220220
assert ([(list(x), y) for x, y in simplified] ==
221221
[([50, 40], 1), ([75, 65], 2)])
222222

223-
p = path.Path([[50, 40]], [1])
223+
p = Path([[50, 40]], [1])
224224
simplified = list(p.iter_segments(clip=[0, 0, 100, 100]))
225225
assert ([(list(x), y) for x, y in simplified] ==
226226
[([50, 40], 1)])
227-
228-
229-
if __name__=='__main__':
230-
import nose
231-
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

lib/matplotlib/tests/test_skew.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,3 @@ def test_skew_rectange():
210210
alpha=0.5, facecolor='coral'))
211211

212212
plt.subplots_adjust(wspace=0, left=0, right=1, bottom=0)
213-
214-
if __name__ == '__main__':
215-
import nose
216-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_spines.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
unicode_literals)
33

44
import numpy as np
5-
from nose.tools import assert_true, assert_less
6-
import six
75

8-
import matplotlib
96
import matplotlib.pyplot as plt
10-
import matplotlib.transforms as mtransforms
117
from matplotlib.testing.decorators import image_comparison, cleanup
128

139

@@ -71,11 +67,11 @@ def test_label_without_ticks():
7167
spine = ax.spines['left']
7268
spinebbox = spine.get_transform().transform_path(
7369
spine.get_path()).get_extents()
74-
assert_less(ax.yaxis.label.get_position()[0], spinebbox.xmin,
75-
"Y-Axis label not left of the spine")
70+
assert ax.yaxis.label.get_position()[0] < spinebbox.xmin, \
71+
"Y-Axis label not left of the spine"
7672

7773
spine = ax.spines['bottom']
7874
spinebbox = spine.get_transform().transform_path(
7975
spine.get_path()).get_extents()
80-
assert_less(ax.xaxis.label.get_position()[1], spinebbox.ymin,
81-
"X-Axis label not below the spine")
76+
assert ax.xaxis.label.get_position()[1] < spinebbox.ymin, \
77+
"X-Axis label not below the spine"

lib/matplotlib/tests/test_streamplot.py

Lines changed: 2 additions & 7 deletions
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 numpy as np
75
from numpy.testing import assert_array_almost_equal
86
import matplotlib.pyplot as plt
@@ -16,6 +14,7 @@ def velocity_field():
1614
V = 1 + X - Y**2
1715
return X, Y, U, V
1816

17+
1918
def swirl_velocity_field():
2019
x = np.linspace(-3., 3., 100)
2120
y = np.linspace(-3., 3., 100)
@@ -25,6 +24,7 @@ def swirl_velocity_field():
2524
V = np.sin(a) * (-Y) + np.cos(a) * X
2625
return x, y, U, V
2726

27+
2828
@image_comparison(baseline_images=['streamplot_startpoints'])
2929
def test_startpoints():
3030
X, Y, U, V = velocity_field()
@@ -95,8 +95,3 @@ def test_streamplot_limits():
9595
# datalim.
9696
assert_array_almost_equal(ax.dataLim.bounds, (20, 30, 15, 6),
9797
decimal=1)
98-
99-
100-
if __name__=='__main__':
101-
import nose
102-
nose.runmodule()

lib/matplotlib/tests/test_style.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
from collections import OrderedDict
99
from contextlib import contextmanager
1010

11-
from nose.tools import assert_raises
12-
from nose.plugins.attrib import attr
11+
import pytest
1312

1413
import matplotlib as mpl
1514
from matplotlib import style
@@ -70,7 +69,7 @@ def test_use():
7069
assert mpl.rcParams[PARAM] == VALUE
7170

7271

73-
@attr('network')
72+
@pytest.mark.network
7473
def test_use_url():
7574
with temp_style('test', DUMMY_SETTINGS):
7675
with style.context('https://gist.github.com/adrn/6590261/raw'):
@@ -140,10 +139,7 @@ def test_context_with_badparam():
140139
with style.context({PARAM: other_value}):
141140
assert mpl.rcParams[PARAM] == other_value
142141
x = style.context([d])
143-
assert_raises(KeyError, x.__enter__)
142+
with pytest.raises(KeyError):
143+
with x:
144+
pass
144145
assert mpl.rcParams[PARAM] == other_value
145-
146-
147-
if __name__ == '__main__':
148-
from numpy import testing
149-
testing.run_module_suite()

0 commit comments

Comments
 (0)
0