8000 Cleanup test_s* files for PEP8. · matplotlib/matplotlib@72807ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 72807ab

Browse files
committed
Cleanup test_s* files for PEP8.
1 parent 9738c65 commit 72807ab

File tree

6 files changed

+50
-56
lines changed

6 files changed

+50
-56
lines changed

lib/matplotlib/tests/test_coding_standards.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@ def test_pep8_conformance_installed_files():
209209
'tests/test_lines.py',
210210
'tests/test_mathtext.py',
211211
'tests/test_rcparams.py',
212-
'tests/test_simplification.py',
213-
'tests/test_streamplot.py',
214-
'tests/test_subplots.py',
215212
'tests/test_tightlayout.py',
216213
'tests/test_triangulation.py',
217214
'backends/backend_agg.py',

lib/matplotlib/tests/test_sankey.py

Lines changed: 0 additions & 2 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

Lines changed: 45 additions & 43 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
9-
import matplotlib.pyplot as plt
7+
import pytest
108

11-
from matplotlib import patches, path, transforms
9+
from matplotlib.testing.decorators import image_comparison, cleanup
10+
import matplotlib.pyplot as plt
1211

13-
import pytest
14-
import io
12+
from matplotlib import patches, transforms
13+
from matplotlib.path import Path
1514

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,19 +153,21 @@ 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
162164
def test_throw_rendering_complexity_exceeded():
163165
plt.rcParams['path.simplify'] = False
164166
xx = np.arange(200000)
165167
yy = np.random.rand(200000)
166168
yy[1000] = np.nan
167-
fig = plt.figure()
168-
ax = fig.add_subplot(111)
169+
170+
fig, ax = plt.subplots()
169171
ax.plot(xx, yy)
170172
with pytest.raises(OverflowError):
171173
fig.savefig(io.BytesIO())
@@ -175,9 +177,9 @@ def test_throw_rendering_complexity_exceeded():
175177
def test_clipper():
176178
dat = (0, 1, 0, 2, 0, 3, 0, 4, 0, 5)
177179
fig = plt.figure(figsize=(2, 1))
178-
fig.subplots_adjust(left = 0, bottom = 0, wspace = 0, hspace = 0)
180+
fig.subplots_adjust(left=0, bottom=0, wspace=0, hspace=0)
179181

180-
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)
181183
ax.plot(dat)
182184
ax.xaxis.set_major_locator(plt.MultipleLocator(1))
183185
ax.yaxis.set_major_locator(plt.MultipleLocator(1))
@@ -186,39 +188,39 @@ def test_clipper():
186188

187189
ax.set_xlim(5, 9)
188190

191+
189192
@image_comparison(baseline_images=['para_equal_perp'], remove_text=True)
190193
def test_para_equal_perp():
191194
x = np.array([0, 1, 2, 1, 0, -1, 0, 1] + [1] * 128)
192195
y = np.array([1, 1, 2, 1, 0, -1, 0, 0] + [0] * 128)
193196

194-
fig = plt.figure()
195-
ax = fig.add_subplot(111)
197+
fig, ax = plt.subplots()
196198
ax.plot(x + 1, y + 1)
197199
ax.plot(x + 1, y + 1, 'ro')
198200

201+
199202
@image_comparison(baseline_images=['clipping_with_nans'])
200203
def test_clipping_with_nans():
201204
x = np.linspace(0, 3.14 * 2, 3000)
202205
y = np.sin(x)
203206
x[::100] = np.nan
204207

205-
fig = plt.figure()
206-
ax = fig.add_subplot(111)
208+
fig, ax = plt.subplots()
207209
ax.plot(x, y)
208210
ax.set_ylim(-0.25, 0.25)
209211

210212

211213
def test_clipping_full():
212-
p = path.Path([[1e30, 1e30]] * 5)
214+
p = Path([[1e30, 1e30]] * 5)
213215
simplified = list(p.iter_segments(clip=[0, 0, 100, 100]))
214216
assert simplified == []
215217

216-
p = path.Path([[50, 40], [75, 65]], [1, 2])
218+
p = Path([[50, 40], [75, 65]], [1, 2])
217219
simplified = list(p.iter_segments(clip=[0, 0, 100, 100]))
218220
assert ([(list(x), y) for x, y in simplified] ==
219221
[([50, 40], 1), ([75, 65], 2)])
220222

221-
p = path.Path([[50, 40]], [1])
223+
p = Path([[50, 40]], [1])
222224
simplified = list(p.iter_segments(clip=[0, 0, 100, 100]))
223225
assert ([(list(x), y) for x, y in simplified] ==
224226
[([50, 40], 1)])

lib/matplotlib/tests/test_spines.py

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

44
import numpy as np
5-
import six
65

7-
import matplotlib
86
import matplotlib.pyplot as plt
9-
import matplotlib.transforms as mtransforms
107
from matplotlib.testing.decorators import image_comparison, cleanup
118

129

lib/matplotlib/tests/test_streamplot.py

Lines changed: 2 additions & 2 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()

lib/matplotlib/tests/test_subplots.py

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

44
import warnings
5-
import six
6-
from six.moves import xrange
75

86
import numpy
97
import matplotlib.pyplot as plt
@@ -30,7 +28,9 @@ def check_shared(axs, x_shared, y_shared):
3028

3129

3230
def check_visible(axs, x_visible, y_visible):
33-
tostr = lambda v: "invisible" if v else "visible"
31+
def tostr(v):
32+
return "invisible" if v else "visible"
33+
3434
for (ax, vx, vy) in zip(axs, x_visible, y_visible):
3535
for l in ax.get_xticklabels() + [ax.get_xaxis().offsetText]:
3636
assert l.get_visible() == vx, \

0 commit comments

Comments
 (0)
0