8000 TST: Remove assert_equal calls. · matplotlib/matplotlib@8083562 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8083562

Browse files
committed
TST: Remove assert_equal calls.
Some are only used on a single line, some just compare to True, etc., but mostly unnecessary compared to plain assert.
1 parent a8e63ce commit 8083562

File tree

6 files changed

+54
-60
lines changed

6 files changed

+54
-60
lines changed

lib/matplotlib/tests/test_colors.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import numpy as np
1010
import pytest
1111

12-
from numpy.testing import assert_equal
1312
from numpy.testing.utils import assert_array_equal, assert_array_almost_equal
1413

1514
from matplotlib import cycler
@@ -160,25 +159,25 @@ def test_PowerNorm():
160159
expected = [0, 0, 1/16, 1/4, 1]
161160
pnorm = mcolors.PowerNorm(2, vmin=0, vmax=8)
162161
assert_array_almost_equal(pnorm(a), expected)
163-
assert_equal(pnorm(a[0]), expected[0])
164-
assert_equal(pnorm(a[2]), expected[2])
162+
assert pnorm(a[0]) == expected[0]
163+
assert pnorm(a[2]) == expected[2]
165164
assert_array_almost_equal(a[1:], pnorm.inverse(pnorm(a))[1:])
166165

167166
# Clip = True
168167
a = np.array([-0.5, 0, 1, 8, 16], dtype=float)
169168
expected = [0, 0, 0, 1, 1]
170169
pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=True)
171170
assert_array_almost_equal(pnorm(a), expected)
172-
assert_equal(pnorm(a[0]), expected[0])
173-
assert_equal(pnorm(a[-1]), expected[-1])
171+
assert pnorm(a[0]) == expected[0]
172+
assert pnorm(a[-1]) == expected[-1]
174173

175174
# Clip = True at call time
176175
a = np.array([-0.5, 0, 1, 8, 16], dtype=float)
177176
expected = [0, 0, 0, 1, 1]
178177
pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=False)
179178
assert_array_almost_equal(pnorm(a, clip=True), expected)
180-
assert_equal(pnorm(a[0], clip=True), expected[0])
181-
assert_equal(pnorm(a[-1], clip=True), expected[-1])
179+
assert pnorm(a[0], clip=True) == expected[0]
180+
assert pnorm(a[-1], clip=True) == expected[-1]
182181

183182

184183
def test_Normalize():
@@ -652,14 +651,14 @@ def test_conversions():
652651
mcolors.to_rgba_array([".2", ".5", ".8"]),
653652
np.vstack([mcolors.to_rgba(c) for c in [".2", ".5", ".8"]]))
654653
# alpha is properly set.
655-
assert_equal(mcolors.to_rgba((1, 1, 1), .5), (1, 1, 1, .5))
656-
assert_equal(mcolors.to_rgba(".1", .5), (.1, .1, .1, .5))
654+
assert mcolors.to_rgba((1, 1, 1), .5) 9E88 == (1, 1, 1, .5)
655+
assert mcolors.to_rgba(".1", .5) == (.1, .1, .1, .5)
657656
# builtin round differs between py2 and py3.
658-
assert_equal(mcolors.to_hex((.7, .7, .7)), "#b2b2b2")
657+
assert mcolors.to_hex((.7, .7, .7)) == "#b2b2b2"
659658
# hex roundtrip.
660659
hex_color = "#1234abcd"
661-
assert_equal(mcolors.to_hex(mcolors.to_rgba(hex_color), keep_alpha=True),
662-
hex_color)
660+
assert mcolors.to_hex(mcolors.to_rgba(hex_color), keep_alpha=True) == \
661+
hex_color
663662

664663

665664
def test_grey_gray():

lib/matplotlib/tests/test_compare_images.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import shutil
99
import warnings
1010

11-
from numpy.testing import assert_equal, assert_almost_equal
11+
from numpy.testing import assert_almost_equal
1212
import pytest
1313

1414
from matplotlib.testing.compare import compare_images
@@ -41,7 +41,7 @@ def image_comparison_expect_rms(im1, im2, tol, expect_rms):
4141
results = compare_images(im1, im2, tol=tol, in_decorator=True)
4242

4343
if expect_rms is None:
44-
assert_equal(None, results)
44+
assert results is None
4545
else:
4646
assert results is not None
4747
assert_almost_equal(expect_rms, results['rms'], decimal=4)

lib/matplotlib/tests/test_dates.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
except ImportError:
1818
import mock
1919

20-
from numpy.testing import assert_equal
21-
2220
from matplotlib.testing.decorators import image_comparison
2321
import matplotlib.pyplot as plt
2422
import matplotlib.dates as mdates
@@ -184,16 +182,16 @@ def test_strftime_fields(dt):
184182
minute=dt.minute,
185183
second=dt.second,
186184
microsecond=dt.microsecond))
187-
assert_equal(formatter.strftime(dt), formatted_date_str)
185+
assert formatter.strftime(dt) == formatted_date_str
188186

189187
try:
190188
# Test strftime("%x") with the current locale.
191189
import locale # Might not exist on some platforms, such as Windows
192190
locale_formatter = mdates.DateFormatter("%x")
193191
locale_d_fmt = locale.nl_langinfo(locale.D_FMT)
194192
expanded_formatter = mdates.DateFormatter(locale_d_fmt)
195-
assert_equal(locale_formatter.strftime(dt),
196-
expanded_formatter.strftime(dt))
193+
assert locale_formatter.strftime(dt) == \
194+
expanded_formatter.strftime(dt)
197195
except (ImportError, AttributeError):
198196
pass
199197

@@ -211,8 +209,7 @@ def test_date_formatter_callable():
211209

212210
formatter = mdates.AutoDateFormatter(locator)
213211
formatter.scaled[-10] = callable_formatting_function
214-
assert_equal(formatter([datetime.datetime(2014, 12, 25)]),
215-
['25-12//2014'])
212+
assert formatter([datetime.datetime(2014, 12, 25)]) == ['25-12//2014']
216213

217214

218215
def test_drange():
@@ -225,12 +222,12 @@ def test_drange():
225222
delta = datetime.timedelta(hours=1)
226223
# We expect 24 values in drange(start, end, delta), because drange returns
227224
# dates from an half open interval [start, end)
228-
assert_equal(24, len(mdates.drange(start, end, delta)))
225+
assert len(mdates.drange(start, end, delta)) == 24
229226

230227
# if end is a little bit later, we expect the range to contain one element
231228
# more
232229
end = end + datetime.timedelta(microseconds=1)
233-
assert_equal(25, len(mdates.drange(start, end, delta)))
230+
assert len(mdates.drange(start, end, delta)) == 25
234231

235232
# reset end
236233
end = datetime.datetime(2011, 1, 2, tzinfo=mdates.UTC)
@@ -239,8 +236,8 @@ def test_drange():
239236
# 4 hours = 1/6 day, this is an "dangerous" float
240237
delta = datetime.timedelta(hours=4)
241238
daterange = mdates.drange(start, end, delta)
242-
assert_equal(6, len(daterange))
243-
assert_equal(mdates.num2date(daterange[-1]), end - delta)
239+
assert len(daterange) == 6
240+
assert mdates.num2date(daterange[-1]) == (end - delta)
244241

245242

246243
def test_empty_date_with_year_formatter():
@@ -331,8 +328,7 @@ def _create_auto_date_locator(date1, date2):
331328
for t_delta, expected in results:
332329
d2 = d1 + t_delta
333330
locator = _create_auto_date_locator(d1, d2)
334-
assert_equal(list(map(str, mdates.num2date(locator()))),
335-
expected)
331+
assert list(map(str, mdates.num2date(locator()))) == expected
336332

337333

338334
@image_comparison(baseline_images=['date_inverted_limit'],
@@ -368,7 +364,7 @@ def _test_date2num_dst(date_range, tz_convert):
368364
expected_ordinalf = [735322.0 + (i * interval_days) for i in range(N)]
369365
actual_ordinalf = list(mdates.date2num(dt_bxl))
370366

371-
assert_equal(actual_ordinalf, expected_ordinalf)
367+
assert actual_ordinalf == expected_ordinalf
372368

373369

374370
def test_date2num_dst():

lib/matplotlib/tests/test_figure.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33

4-
from numpy.testing import assert_equal
54
from matplotlib import rcParams
65
from matplotlib.testing.decorators import image_comparison
76
from matplotlib.axes import Axes
@@ -24,14 +23,14 @@ def test_figure_label():
2423
plt.figure(0)
2524
plt.figure(1)
2625
plt.figure(3)
27-
assert_equal(plt.get_fignums(), [0, 1, 3, 4, 5])
28-
assert_equal(plt.get_figlabels(), ['', 'today', '', 'tomorrow', ''])
26+
assert plt.get_fignums() == [0, 1, 3, 4, 5]
27+
assert plt.get_figlabels() == ['', 'today', '', 'tomorrow', '']
2928
plt.close(10)
3029
plt.close()
3130
plt.close(5)
3231
plt.close('tomorrow')
33-
assert_equal(plt.get_fignums(), [0, 1])
34-
assert_equal(plt.get_figlabels(), ['', 'today'])
32+
assert plt.get_fignums() == [0, 1]
33+
assert plt.get_figlabels() == ['', 'today']
3534

3635

3736
def test_fignum_exists():
@@ -40,31 +39,33 @@ def test_fignum_exists():
4039
plt.figure(2)
4140
plt.figure('three')
4241
plt.figure()
43-
assert_equal(plt.fignum_exists('one'), True)
44-
assert_equal(plt.fignum_exists(2), True)
45-
assert_equal(plt.fignum_exists('three'), True)
46-
assert_equal(plt.fignum_exists(4), True)
42+
assert plt.fignum_exists('one')
43+
assert plt.fignum_exists(2)
44+
assert plt.fignum_exists('three')
45+
assert plt.fignum_exists(4)
4746
plt.close('one')
4847
plt.close(4)
49-
assert_equal(plt.fignum_exists('one'), False)
50-
assert_equal(plt.fignum_exists(4), False)
48+
assert not plt.fignum_exists('one')
49+
assert not plt.fignum_exists(4)
5150

5251

5352
def test_clf_keyword():
5453
# test if existing figure is cleared with figure() and subplots()
54+
text1 = 'A fancy plot'
55+
text2 = 'Really fancy!'
56+
5557
fig0 = plt.figure(num=1)
56-
fig0.suptitle("A fancy plot")
57-
assert_equal([t.get_text() for t in fig0.texts], ["A fancy plot"])
58+
fig0.suptitle(text1)
59+
assert [t.get_text() for t in fig0.texts] == [text1]
5860

5961
fig1 = plt.figure(num=1, clear=False)
60-
fig1.text(0.5, 0.5, "Really fancy!")
62+
fig1.text(0.5, 0.5, text2)
6163
assert fig0 is fig1
62-
assert_equal([t.get_text() for t in fig1.texts],
63-
["A fancy plot", 'Really fancy!'])
64+
assert [t.get_text() for t in fig1.texts] == [text1, text2]
6465

6566
fig2, ax2 = plt.subplots(2, 1, num=1, clear=True)
6667
assert fig0 is fig2
67-
assert_equal([t.get_text() for t in fig2.texts], [])
68+
assert [t.get_text() for t in fig2.texts] == []
6869

6970

7071
@image_comparison(baseline_images=['figure_today'])
@@ -116,7 +117,7 @@ def test_gca():
116117
assert fig.gca(polar=True) is not ax3
117118
assert len(w) == 1
118119
assert fig.gca(polar=True) is not ax2
119-
assert_equal(fig.gca().get_geometry(), (1, 1, 1))
120+
assert fig.gca().get_geometry() == (1, 1, 1)
120121

121122
fig.sca(ax1)
122123
assert fig.gca(projection='rectilinear') is ax1
@@ -135,8 +136,8 @@ def test_suptitle_fontproperties():
135136
fig, ax = plt.subplots()
136137
fps = FontProperties(size='large', weight='bold')
137138
txt = fig.suptitle('fontprops title', fontproperties=fps)
138-
assert_equal(txt.get_fontsize(), fps.get_size_in_points())
139-
assert_equal(txt.get_weight(), fps.get_weight())
139+
assert txt.get_fontsize() == fps.get_size_in_points()
140+
assert txt.get_weight() == fps.get_weight()
140141

141142

142143
@image_comparison(baseline_images=['alpha_background'],
@@ -202,21 +203,21 @@ def test_set_fig_size():
202203

203204
# check figwidth
204205
fig.set_figwidth(5)
205-
assert_equal(fig.get_figwidth(), 5)
206+
assert fig.get_figwidth() == 5
206207

207208
# check figheight
208209
fig.set_figheight(1)
209-
assert_equal(fig.get_figheight(), 1)
210+
assert fig.get_figheight() == 1
210211

211212
# check using set_size_inches
212213
fig.set_size_inches(2, 4)
213-
assert_equal(fig.get_figwidth(), 2)
214-
assert_equal(fig.get_figheight(), 4)
214+
assert fig.get_figwidth() == 2
215+
assert fig.get_figheight() == 4
215216

216217
# check using tuple to first argument
217218
fig.set_size_inches((1, 3))
218-
assert_equal(fig.get_figwidth(), 1)
219-
assert_equal(fig.get_figheight(), 3)
219+
assert fig.get_figwidth() == 1
220+
assert fig.get_figheight() == 3
220221

221222

222223
def test_axes_remove():
@@ -225,7 +226,7 @@ def test_axes_remove():
225226
for ax in axes.ravel()[:-1]:
226227
assert ax in fig.axes
227228
assert axes[-1, -1] not in fig.axes
228-
assert_equal(len(fig.axes), 3)
229+
assert len(fig.axes) == 3
229230

230231

231232
def test_figaspect():

lib/matplotlib/tests/test_gridspec.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import matplotlib.gridspec as gridspec
2-
from numpy.testing import assert_equal
32
import pytest
43

54

65
def test_equal():
76
gs = gridspec.GridSpec(2, 1)
8-
assert_equal(gs[0, 0], gs[0, 0])
9-
assert_equal(gs[:, 0], gs[:, 0])
7+
assert gs[0, 0] == gs[0, 0]
8+
assert gs[:, 0] == gs[:, 0]
109

1110

1211
def test_width_ratios():

lib/matplotlib/tests/test_legend.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from unittest import mock
77
except ImportError:
88
import mock
9-
from numpy.testing import assert_equal
109
import numpy as np
1110

1211
from matplotlib.testing.decorators import image_comparison
@@ -177,7 +176,7 @@ def test_legend_remove():
177176
lines = ax.plot(range(10))
178177
leg = fig.legend(lines, "test")
179178
leg.remove()
180-
assert_equal(fig.legends, [])
179+
assert fig.legends == []
181180
leg = ax.legend("test")
182181
leg.remove()
183182
assert ax.get_legend() is None

0 commit comments

Comments
 (0)
0