Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d4088a8

Browse files
committed
Random test cleanups
Mostly suggestions by a code checker and readability improvements.
1 parent 34f99a9 commit d4088a8

File tree

6 files changed

+82
-87
lines changed

6 files changed

+82
-87
lines changed

lib/matplotlib/tests/test_afm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_font_manager_weight_normalization():
107107
def test_bad_afm(afm_data):
108108
fh = BytesIO(afm_data)
109109
with pytest.raises(RuntimeError):
110-
header = afm._parse_header(fh)
110+
afm._parse_header(fh)
111111

112112

113113
@pytest.mark.parametrize(
@@ -132,6 +132,6 @@ def test_bad_afm(afm_data):
132132
def test_malformed_header(afm_data, caplog):
133133
fh = BytesIO(afm_data)
134134
with caplog.at_level(logging.ERROR):
135-
header = afm._parse_header(fh)
135+
afm._parse_header(fh)
136136

137137
assert len(caplog.records) == 1

lib/matplotlib/tests/test_agg.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,30 +161,30 @@ def process_image(self, padded_src, dpi):
161161
fig, ax = plt.subplots()
162162

163163
# draw lines
164-
l1, = ax.plot([0.1, 0.5, 0.9], [0.1, 0.9, 0.5], "bo-",
165-
mec="b", mfc="w", lw=5, mew=3, ms=10, label="Line 1")
166-
l2, = ax.plot([0.1, 0.5, 0.9], [0.5, 0.2, 0.7], "ro-",
167-
mec="r", mfc="w", lw=5, mew=3, ms=10, label="Line 1")
164+
line1, = ax.plot([0.1, 0.5, 0.9], [0.1, 0.9, 0.5], "bo-",
165+
mec="b", mfc="w", lw=5, mew=3, ms=10, label="Line 1")
166+
line2, = ax.plot([0.1, 0.5, 0.9], [0.5, 0.2, 0.7], "ro-",
167+
mec="r", mfc="w", lw=5, mew=3, ms=10, label="Line 1")
168168

169169
gauss = DropShadowFilter(4)
170170

171-
for l in [l1, l2]:
171+
for line in [line1, line2]:
172172

173173
# draw shadows with same lines with slight offset.
174-
xx = l.get_xdata()
175-
yy = l.get_ydata()
174+
xx = line.get_xdata()
175+
yy = line.get_ydata()
176176
shadow, = ax.plot(xx, yy)
177-
shadow.update_from(l)
177+
shadow.update_from(line)
178178

179179
# offset transform
180-
ot = mtransforms.offset_copy(l.get_transform(), ax.figure,
180+
ot = mtransforms.offset_copy(line.get_transform(), ax.figure,
181181
x=4.0, y=-6.0, units='points')
182182

183183
shadow.set_transform(ot)
184184

185185
# adjust zorder of the shadow lines so that it is drawn below the
186186
# original lines
187-
shadow.set_zorder(l.get_zorder() - 0.5)
187+
shadow.set_zorder(line.get_zorder() - 0.5)
188188
shadow.set_agg_filter(gauss)
189189
shadow.set_rasterized(True) # to support mixed-mode renderers
190190

lib/matplotlib/tests/test_axes.py

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,15 +2961,14 @@ def test_boxplot_mod_artist_after_plotting():
29612961
def test_vert_violinplot_baseline():
29622962
# First 9 digits of frac(sqrt(2))
29632963
np.random.seed(414213562)
2964-
data = [np.random.normal(size=100) for i in range(4)]
2964+
data = [np.random.normal(size=100) for _ in range(4)]
29652965
ax = plt.axes()
29662966
ax.violinplot(data, positions=range(4), showmeans=0, showextrema=0,
29672967
showmedians=0)
29682968

29692969
# Reuse testcase from above for a labeled data test
29702970
data = {"d": data}
29712971
fig, ax = plt.subplots()
2972-
ax = plt.axes()
29732972
ax.violinplot("d", positions=range(4), showmeans=0, showextrema=0,
29742973
showmedians=0, data=data)
29752974

@@ -2979,7 +2978,7 @@ def test_vert_violinplot_showmeans():
29792978
ax = plt.axes()
29802979
# First 9 digits of frac(sqrt(3))
29812980
np.random.seed(732050807)
2982-
data = [np.random.normal(size=100) for i in range(4)]
2981+
data = [np.random.normal(size=100) for _ in range(4)]
29832982
ax.violinplot(data, positions=range(4), showmeans=1, showextrema=0,
29842983
showmedians=0)
29852984

@@ -2989,7 +2988,7 @@ def test_vert_violinplot_showextrema():
29892988
ax = plt.axes()
29902989
# First 9 digits of frac(sqrt(5))
29912990
np.random.seed(236067977)
2992-
data = [np.random.normal(size=100) for i in range(4)]
2991+
data = [np.random.normal(size=100) for _ in range(4)]
29932992
ax.violinplot(data, positions=range(4), showmeans=0, showextrema=1,
29942993
showmedians=0)
29952994

@@ -2999,7 +2998,7 @@ def test_vert_violinplot_showmedians():
29992998
ax = plt.axes()
30002999
# First 9 digits of frac(sqrt(7))
30013000
np.random.seed(645751311)
3002-
data = [np.random.normal(size=100) for i in range(4)]
3001+
data = [np.random.normal(size=100) for _ in range(4)]
30033002
ax.violinplot(data, positions=range(4), showmeans=0, showextrema=0,
30043003
showmedians=1)
30053004

@@ -3009,7 +3008,7 @@ def test_vert_violinplot_showall():
30093008
ax = plt.axes()
30103009
# First 9 digits of frac(sqrt(11))
30113010
np.random.seed(316624790)
3012-
data = [np.random.normal(size=100) for i in range(4)]
3011+
data = [np.random.normal(size=100) for _ in range(4)]
30133012
ax.violinplot(data, positions=range(4), showmeans=1, showextrema=1,
30143013
showmedians=1,
30153014
quantiles=[[0.1, 0.9], [0.2, 0.8], [0.3, 0.7], [0.4, 0.6]])
@@ -3020,7 +3019,7 @@ def test_vert_violinplot_custompoints_10():
30203019
ax = plt.axes()
30213020
# First 9 digits of frac(sqrt(13))
30223021
np.random.seed(605551275)
3023-
data = [np.random.normal(size=100) for i in range(4)]
3022+
data = [np.random.normal(size=100) for _ in range(4)]
30243023
ax.violinplot(data, positions=range(4), showmeans=0, showextrema=0,
30253024
showmedians=0, points=10)
30263025

@@ -3030,7 +3029,7 @@ def test_vert_violinplot_custompoints_200():
30303029
ax = plt.axes()
30313030
# First 9 digits of frac(sqrt(17))
30323031
np.random.seed(123105625)
3033-
data = [np.random.normal(size=100) for i in range(4)]
3032+
data = [np.random.normal(size=100) for _ in range(4)]
30343033
ax.violinplot(data, positions=range(4), showmeans=0, showextrema=0,
30353034
showmedians=0, points=200)
30363035

@@ -3040,7 +3039,7 @@ def test_horiz_violinplot_baseline():
30403039
ax = plt.axes()
30413040
# First 9 digits of frac(sqrt(19))
30423041
np.random.seed(358898943)
3043-
data = [np.random.normal(size=100) for i in range(4)]
3042+
data = [np.random.normal(size=100) for _ in range(4)]
30443043
ax.violinplot(data, positions=range(4), vert=False, showmeans=0,
30453044
showextrema=0, showmedians=0)
30463045

@@ -3050,7 +3049,7 @@ def test_horiz_violinplot_showmedians():
30503049
ax = plt.axes()
30513050
# First 9 digits of frac(sqrt(23))
30523051
np.random.seed(795831523)
3053-
data = [np.random.normal(size=100) for i in range(4)]
3052+
data = [np.random.normal(size=100) for _ in range(4)]
30543053
ax.violinplot(data, positions=range(4), vert=False, showmeans=0,
30553054
showextrema=0, showmedians=1)
30563055

@@ -3060,7 +3059,7 @@ def test_horiz_violinplot_showmeans():
30603059
ax = plt.axes()
30613060
# First 9 digits of frac(sqrt(29))
30623061
np.random.seed(385164807)
3063-
data = [np.random.normal(size=100) for i in range(4)]
3062+
data = [np.random.normal(size=100) for _ in range(4)]
30643063
ax.violinplot(data, positions=range(4), vert=False, showmeans=1,
30653064
showextrema=0, showmedians=0)
30663065

@@ -3070,7 +3069,7 @@ def test_horiz_violinplot_showextrema():
30703069
ax = plt.axes()
30713070
# First 9 digits of frac(sqrt(31))
30723071
np.random.seed(567764362)
3073-
data = [np.random.normal(size=100) for i in range(4)]
3072+
data = [np.random.normal(size=100) for _ in range(4)]
30743073
ax.violinplot(data, positions=range(4), vert=False, showmeans=0,
30753074
showextrema=1, showmedians=0)
30763075

@@ -3080,7 +3079,7 @@ def test_horiz_violinplot_showall():
30803079
ax = plt.axes()
30813080
# First 9 digits of frac(sqrt(37))
30823081
np.random.seed(82762530)
3083-
data = [np.random.normal(size=100) for i in range(4)]
3082+
data = [np.random.normal(size=100) for _ in range(4)]
30843083
ax.violinplot(data, positions=range(4), vert=False, showmeans=1,
30853084
showextrema=1, showmedians=1,
30863085
quantiles=[[0.1, 0.9], [0.2, 0.8], [0.3, 0.7], [0.4, 0.6]])
@@ -3091,7 +3090,7 @@ def test_horiz_violinplot_custompoints_10():
30913090
ax = plt.axes()
30923091
# First 9 digits of frac(sqrt(41))
30933092
np.random.seed(403124237)
3094-
data = [np.random.normal(size=100) for i in range(4)]
3093+
data = [np.random.normal(size=100) for _ in range(4)]
30953094
ax.violinplot(data, positions=range(4), vert=False, showmeans=0,
30963095
showextrema=0, showmedians=0, points=10)
30973096

@@ -3101,7 +3100,7 @@ def test_horiz_violinplot_custompoints_200():
31013100
ax = plt.axes()
31023101
# First 9 digits of frac(sqrt(43))
31033102
np.random.seed(557438524)
3104-
data = [np.random.normal(size=100) for i in range(4)]
3103+
data = [np.random.normal(size=100) for _ in range(4)]
31053104
ax.violinplot(data, positions=range(4), vert=False, showmeans=0,
31063105
showextrema=0, showmedians=0, points=200)
31073106

@@ -3110,7 +3109,7 @@ def test_violinplot_bad_positions():
31103109
ax = plt.axes()
31113110
# First 9 digits of frac(sqrt(47))
31123111
np.random.seed(855654600)
3113-
data = [np.random.normal(size=100) for i in range(4)]
3112+
data = [np.random.normal(size=100) for _ in range(4)]
31143113
with pytest.raises(ValueError):
31153114
ax.violinplot(data, positions=range(5))
31163115

@@ -3119,7 +3118,7 @@ def test_violinplot_bad_widths():
31193118
ax = plt.axes()
31203119
# First 9 digits of frac(sqrt(53))
31213120
np.random.seed(280109889)
3122-
data = [np.random.normal(size=100) for i in range(4)]
3121+
data = [np.random.normal(size=100) for _ in range(4)]
31233122
with pytest.raises(ValueError):
31243123
ax.violinplot(data, positions=range(4), widths=[1, 2, 3])
31253124

@@ -3718,16 +3717,16 @@ def test_hist_emptydata():
37183717
def test_hist_labels():
37193718
# test singleton labels OK
37203719
fig, ax = plt.subplots()
3721-
l = ax.hist([0, 1], label=0)
3722-
assert l[2][0].get_label() == '0'
3723-
l = ax.hist([0, 1], label=[0])
3724-
assert l[2][0].get_label() == '0'
3725-
l = ax.hist([0, 1], label=None)
3726-
assert l[2][0].get_label() == '_nolegend_'
3727-
l = ax.hist([0, 1], label='0')
3728-
assert l[2][0].get_label() == '0'
3729-
l = ax.hist([0, 1], label='00')
3730-
assert l[2][0].get_label() == '00'
3720+
_, _, bars = ax.hist([0, 1], label=0)
3721+
assert bars[0].get_label() == '0'
3722+
_, _, bars = ax.hist([0, 1], label=[0])
3723+
assert bars[0].get_label() == '0'
3724+
_, _, bars = ax.hist([0, 1], label=None)
3725+
assert bars[0].get_label() == '_nolegend_'
3726+
_, _, bars = ax.hist([0, 1], label='0')
3727+
assert bars[0].get_label() == '0'
3728+
_, _, bars = ax.hist([0, 1], label='00')
3729+
assert bars[0].get_label() == '00'
37313730

37323731

37333732
@image_comparison(['transparent_markers'], remove_text=True)
@@ -3908,7 +3907,7 @@ def test_eventplot_defaults():
39083907
])
39093908
def test_eventplot_colors(colors):
39103909
"""Test the *colors* parameter of eventplot. Inspired by issue #8193."""
3911-
data = [[i] for i in range(4)] # 4 successive events of different nature
3910+
data = [[0], [1], [2], [3]] # 4 successive events of different nature
39123911

39133912
# Build the list of the expected colors
39143913
expected = [c if c is not None else 'C0' for c in colors]
@@ -4557,9 +4556,9 @@ def test_rcparam_grid_minor():
45574556
matplotlib.rcParams['axes.grid'] = True
45584557

45594558
values = (
4560-
(('both'), (True, True)),
4561-
(('major'), (True, False)),
4562-
(('minor'), (False, True))
4559+
('both', (True, True)),
4560+
('major', (True, False)),
4561+
('minor', (False, True))
45634562
)
45644563

45654564
for locator, result in values:
@@ -4576,7 +4575,6 @@ def test_vline_limit():
45764575
ax = fig.gca()
45774576
ax.axvline(0.5)
45784577
ax.plot([-0.1, 0, 0.2, 0.1])
4579-
(ymin, ymax) = ax.get_ylim()
45804578
assert_allclose(ax.get_ylim(), (-.1, .2))
45814579

45824580

@@ -4674,10 +4672,10 @@ def test_relim_visible_only():
46744672
ax.plot(x1, y1)
46754673
assert ax.get_xlim() == x1
46764674
assert ax.get_ylim() == y1
4677-
l = ax.plot(x2, y2)
4675+
line, = ax.plot(x2, y2)
46784676
assert ax.get_xlim() == x2
46794677
assert ax.get_ylim() == y2
4680-
l[0].set_visible(False)
4678+
line.set_visible(False)
46814679
assert ax.get_xlim() == x2
46824680
assert ax.get_ylim() == y2
46834681

@@ -5109,7 +5107,7 @@ def test_rc_spines():
51095107
'axes.spines.top': False,
51105108
'axes.spines.bottom': False}
51115109
with matplotlib.rc_context(rc_dict):
5112-
fig, ax = plt.subplots()
5110+
plt.subplots() # create a figure and axes with the spine properties
51135111

51145112

51155113
@image_comparison(['rc_grid.png'], savefig_kwarg={'dpi': 40})
@@ -5484,7 +5482,7 @@ def test_adjust_numtick_aspect():
54845482
@image_comparison(["auto_numticks.png"], style='default')
54855483
def test_auto_numticks():
54865484
# Make tiny, empty subplots, verify that there are only 3 ticks.
5487-
fig, axs = plt.subplots(4, 4)
5485+
plt.subplots(4, 4)
54885486

54895487

54905488
@image_comparison(["auto_numticks_log.png"], style='default')
@@ -6121,7 +6119,7 @@ class DummySubplot(matplotlib.axes.SubplotBase, Dummy):
61216119
assert DummySubplot is FactoryDummySubplot
61226120

61236121

6124-
def test_gettightbbox_ignoreNaN():
6122+
def test_gettightbbox_ignore_nan():
61256123
fig, ax = plt.subplots()
61266124
remove_ticks_and_titles(fig)
61276125
ax.text(np.NaN, 1, 'Boo')
@@ -6196,6 +6194,7 @@ def test_secondary_fail():
61966194
def test_secondary_resize():
61976195
fig, ax = plt.subplots(figsize=(10, 5))
61986196
ax.plot(np.arange(2, 11), np.arange(2, 11))
6197+
61996198
def invert(x):
62006199
with np.errstate(divide='ignore'):
62016200
return 1 / x
@@ -6209,6 +6208,7 @@ def invert(x):
62096208
def test_secondary_minorloc():
62106209
fig, ax = plt.subplots(figsize=(10, 5))
62116210
ax.plot(np.arange(2, 11), np.arange(2, 11))
6211+
62126212
def invert(x):
62136213
with np.errstate(divide='ignore'):
62146214
return 1 / x
@@ -6332,10 +6332,6 @@ def test_nodecorator():
63326332
bbaxis, bbspines, bbax, bbtb = color_boxes(fig, ax)
63336333

63346334
# test the axis bboxes
6335-
target = [
6336-
None,
6337-
None
6338-
]
63396335
for nn, b in enumerate(bbaxis):
63406336
assert b is None
63416337

@@ -6373,7 +6369,7 @@ def test_displaced_spine():
63736369
[1068.8888, 119.9999, 11.111, 960.0]
63746370
]
63756371
for nn, b in enumerate(bbspines):
6376-
targetbb = mtransforms.Bbox.from_bounds(*target[nn])
6372+
mtransforms.Bbox.from_bounds(*target[nn])
63776373

63786374
target = [150.0, 119.99999999999997, 930.0, 960.0]
63796375
targetbb = mtransforms.Bbox.from_bounds(*target)

lib/matplotlib/tests/test_bbox_tight.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ def test_bbox_inches_tight():
1919
[78415, 81858, 150656, 193263, 69638],
2020
[139361, 331509, 343164, 781380, 52269]]
2121

22-
colLabels = rowLabels = [''] * 5
22+
col_labels = row_labels = [''] * 5
2323

2424
rows = len(data)
25-
ind = np.arange(len(colLabels)) + 0.3 # the x locations for the groups
26-
cellText = []
25+
ind = np.arange(len(col_labels)) + 0.3 # the x locations for the groups
26+
cell_text = []
2727
width = 0.4 # the width of the bars
28-
yoff = np.zeros(len(colLabels))
28+
yoff = np.zeros(len(col_labels))
2929
# the bottom values for stacked bar chart
3030
fig, ax = plt.subplots(1, 1)
3131
for row in range(rows):
3232
ax.bar(ind, data[row], width, bottom=yoff, align='edge', color='b')
3333
yoff = yoff + data[row]
34-
cellText.append([''])
34+
cell_text.append([''])
3535
plt.xticks([])
3636
plt.xlim(0, 5)
3737
plt.legend([''] * 5, loc=(1.2, 0.2))
3838
fig.legend([''] * 5, bbox_to_anchor=(0, 0.2), loc='lower left')
3939
# Add a table at the bottom of the axes
40-
cellText.reverse()
41-
plt.table(cellText=cellText, rowLabels=rowLabels, colLabels=colLabels,
40+
cell_text.reverse()
41+
plt.table(cellText=cell_text, rowLabels=row_labels, colLabels=col_labels,
4242
loc='bottom')
4343

4444

0 commit comments

Comments
 (0)