Skip to content

Commit f10a36b

Browse files
committed
pytest.raises(), not pytest.raise()
1 parent 4c39e53 commit f10a36b

File tree

6 files changed

+69
-69
lines changed

6 files changed

+69
-69
lines changed

lib/matplotlib/tests/test_cbook.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,10 @@ def test_to_midstep():
371371

372372

373373
def test_step_fails():
374-
pytest.raise(ValueError, cbook._step_validation(np.arange(12).reshape(3, 4), 'a'))
375-
pytest.raise(ValueError, cbook._step_validation(np.arange(12), 'a'))
376-
pytest.raise(ValueError, cbook._step_validation(np.arange(12)))
377-
pytest.raise(ValueError, cbook._step_validation(np.arange(12), np.arange(3)))
374+
pytest.raises(ValueError, cbook._step_validation(np.arange(12).reshape(3, 4), 'a'))
375+
pytest.raises(ValueError, cbook._step_validation(np.arange(12), 'a'))
376+
pytest.raises(ValueError, cbook._step_validation(np.arange(12)))
377+
pytest.raises(ValueError, cbook._step_validation(np.arange(12), np.arange(3)))
378378

379379

380380
def test_grouper():

lib/matplotlib/tests/test_colors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def test_cmap_and_norm_from_levels_and_colors2():
281281
'Wih extend={0!r} and data '
282282
'value={1!r}'.format(extend, d_val))
283283

284-
pytest.raise(ValueError, mcolors.from_levels_and_colors(levels, colors))
284+
pytest.raises(ValueError, mcolors.from_levels_and_colors(levels, colors))
285285

286286

287287
def test_rgb_hsv_round_trip():
@@ -311,8 +311,8 @@ def gray_from_float_rgb():
311311
def gray_from_float_rgba():
312312
return mcolors.colorConverter.to_rgba(0.4)
313313

314-
pytest.raise(ValueError, gray_from_float_rgb())
315-
pytest.raise(ValueError, gray_from_float_rgba())
314+
pytest.raises(ValueError, gray_from_float_rgb())
315+
pytest.raises(ValueError, gray_from_float_rgba())
316316

317317

318318
@image_comparison(baseline_images=['light_source_shading_topo'],

lib/matplotlib/tests/test_lines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test_valid_linestyles():
116116
"not supported with Python < 2.7")
117117

118118
line = mpl.lines.Line2D([], [])
119-
pytest.raise(ValueErrorline.set_linestyle('aardvark'))
119+
pytest.raises(ValueErrorline.set_linestyle('aardvark'))
120120

121121

122122
@image_comparison(baseline_images=['line_collection_dashes'], remove_text=True)

lib/matplotlib/tests/test_mlab.py

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -123,43 +123,43 @@ def calc_window_target(self, x, NFFT, noverlap=0):
123123

124124
def test_stride_windows_2D_ValueError(self):
125125
x = np.arange(10)[np.newaxis]
126-
pytest.raise(ValueError, mlab.stride_windows( x, 5))
126+
pytest.raises(ValueError, mlab.stride_windows( x, 5))
127127

128128
def test_stride_windows_0D_ValueError(self):
129129
x = np.array(0)
130-
pytest.raise(ValueError, mlab.stride_windows( x, 5))
130+
pytest.raises(ValueError, mlab.stride_windows( x, 5))
131131

132132
def test_stride_windows_noverlap_gt_n_ValueError(self):
133133
x = np.arange(10)
134-
pytest.raise(ValueError, mlab.stride_windows(x, 2, 3)
134+
pytest.raises(ValueError, mlab.stride_windows(x, 2, 3)
135135

136136
def test_stride_windows_noverlap_eq_n_ValueError(self):
137137
x = np.arange(10)
138-
pytest.raise(ValueError, mlab.stride_windows(x, 2, 2))
138+
pytest.raises(ValueError, mlab.stride_windows(x, 2, 2))
139139

140140
def test_stride_windows_n_gt_lenx_ValueError(self):
141141
x = np.arange(10)
142-
pytest.raise(ValueError, mlab.stride_windows(x, 11))
142+
pytest.raises(ValueError, mlab.stride_windows(x, 11))
143143

144144
def test_stride_windows_n_lt_1_ValueError(self):
145145
x = np.arange(10)
146-
pytest.raise(ValueError, mlab.stride_windows(x, 0))
146+
pytest.raises(ValueError, mlab.stride_windows(x, 0))
147147

148148
def test_stride_repeat_2D_ValueError(self):
149149
x = np.arange(10)[np.newaxis]
150-
pytest.raise(ValueError, mlab.stride_repeat(x, 5))
150+
pytest.raises(ValueError, mlab.stride_repeat(x, 5))
151151

152152
def test_stride_repeat_axis_lt_0_ValueError(self):
153153
x = np.array(0)
154-
pytest.raise(ValueError, mlab.stride_repeat(x, 5, axis=-1))
154+
pytest.raises(ValueError, mlab.stride_repeat(x, 5, axis=-1))
155155

156156
def test_stride_repeat_axis_gt_1_ValueError(self):
157157
x = np.array(0)
158-
pytest.raise(ValueError, mlab.stride_repeat(x, 5, axis=2))
158+
pytest.raises(ValueError, mlab.stride_repeat(x, 5, axis=2))
159159

160160
def test_stride_repeat_n_lt_1_ValueError(self):
161161
x = np.arange(10)
162-
pytest.raise(ValueError, mlab.stride_repeat(x, 0))
162+
pytest.raises(ValueError, mlab.stride_repeat(x, 0))
163163

164164
def test_stride_repeat_n1_axis0(self):
165165
x = np.arange(10)
@@ -337,7 +337,7 @@ def test_rec2csv_bad_shape_ValueError(self):
337337
(str('y'), np.float)])
338338

339339
# the bad recarray should trigger a ValueError for having ndim > 1.
340-
pytest.raise(ValueError, mlab.rec2csv( bad, self.fd))
340+
pytest.raises(ValueError, mlab.rec2csv( bad, self.fd))
341341

342342
def test_csv2rec_names_with_comments(self):
343343
self.fd.write('# comment\n1,2,3\n4,5,6\n')
@@ -399,24 +399,24 @@ def test_window_hanning_ones(self):
399399
def test_apply_window_1D_axis1_ValueError(self):
400400
x = self.sig_rand
401401
window = mlab.window_hanning
402-
pytest.raise(ValueError, mlab.apply_window( x, window, axis=1,
402+
pytest.raises(ValueError, mlab.apply_window( x, window, axis=1,
403403
return_window=False))
404404

405405
def test_apply_window_1D_els_wrongsize_ValueError(self):
406406
x = self.sig_rand
407407
window = mlab.window_hanning(np.ones(x.shape[0]-1))
408-
pytest.raise(ValueError, mlab.apply_window(x, window))
408+
pytest.raises(ValueError, mlab.apply_window(x, window))
409409

410410
def test_apply_window_0D_ValueError(self):
411411
x = np.array(0)
412412
window = mlab.window_hanning
413-
pytest.raise(ValueError, mlab.apply_window(x, window, axis=1,
413+
pytest.raises(ValueError, mlab.apply_window(x, window, axis=1,
414414
return_window=False))
415415

416416
def test_apply_window_3D_ValueError(self):
417417
x = self.sig_rand[np.newaxis][np.newaxis]
418418
window = mlab.window_hanning
419-
pytest.raise(ValueError, mlab.apply_window(x, window, axis=1,
419+
pytest.raises(ValueError, mlab.apply_window(x, window, axis=1,
420420
return_window=False))
421421

422422
def test_apply_window_hanning_1D(self):
@@ -1096,43 +1096,43 @@ def test_demean_2D_axism1(self):
10961096

10971097
def test_detrend_bad_key_str_ValueError(self):
10981098
input = self.sig_slope[np.newaxis]
1099-
pytest.raise(ValueError, mlab.detrend(input, key='spam'))
1099+
pytest.raises(ValueError, mlab.detrend(input, key='spam'))
11001100

11011101
def test_detrend_bad_key_var_ValueError(self):
11021102
input = self.sig_slope[np.newaxis]
1103-
pytest.raise(ValueError, mlab.detrend(input, key=5))
1103+
pytest.raises(ValueError, mlab.detrend(input, key=5))
11041104

11051105
def test_detrend_mean_0D_d0_ValueError(self):
11061106
input = 5.5
1107-
pytest.raise(ValueError, mlab.detrend_mean(input, axis=0))
1107+
pytest.raises(ValueError, mlab.detrend_mean(input, axis=0))
11081108

11091109
def test_detrend_0D_d0_ValueError(self):
11101110
input = 5.5
1111-
pytest.raise(ValueError, mlab.detrend(input, axis=0))
1111+
pytest.raises(ValueError, mlab.detrend(input, axis=0))
11121112

11131113
def test_detrend_mean_1D_d1_ValueError(self):
11141114
input = self.sig_slope
1115-
pytest.raise(ValueError, mlab.detrend_mean(input, axis=1))
1115+
pytest.raises(ValueError, mlab.detrend_mean(input, axis=1))
11161116

11171117
def test_detrend_1D_d1_ValueError(self):
11181118
input = self.sig_slope
1119-
pytest.raise(ValueError, mlab.detrend(input, axis=1))
1119+
pytest.raises(ValueError, mlab.detrend(input, axis=1))
11201120

11211121
def test_demean_1D_d1_ValueError(self):
11221122
input = self.sig_slope
1123-
pytest.raise(ValueError, mlab.demean(input, axis=1))
1123+
pytest.raises(ValueError, mlab.demean(input, axis=1))
11241124

11251125
def test_detrend_mean_2D_d2_ValueError(self):
11261126
input = self.sig_slope[np.newaxis]
1127-
pytest.raise(ValueError, mlab.detrend_mean(input, axis=2))
1127+
pytest.raises(ValueError, mlab.detrend_mean(input, axis=2))
11281128

11291129
def test_detrend_2D_d2_ValueError(self):
11301130
input = self.sig_slope[np.newaxis]
1131-
pytest.raise(ValueError, mlab.detrend(input, axis=2))
1131+
pytest.raises(ValueError, mlab.detrend(input, axis=2))
11321132

11331133
def test_demean_2D_d2_ValueError(self):
11341134
input = self.sig_slope[np.newaxis]
1135-
pytest.raise(ValueError, mlab.demean(input, axis=2))
1135+
pytest.raises(ValueError, mlab.demean(input, axis=2))
11361136

11371137
def test_detrend_linear_0D_zeros(self):
11381138
input = 0.
@@ -1196,7 +1196,7 @@ def test_detrend_linear_1d_slope_off_list(self):
11961196

11971197
def test_detrend_linear_2D_ValueError(self):
11981198
input = self.sig_slope[np.newaxis]
1199-
pytest.raise(ValueError, mlab.detrend_linear(input))
1199+
pytest.raises(ValueError, mlab.detrend_linear(input))
12001200

12011201
def test_detrend_str_linear_2d_slope_off_axis0(self):
12021202
arri = [self.sig_off,
@@ -1431,57 +1431,57 @@ def check_maxfreq(self, spec, fsp, fstims):
14311431

14321432
def test_spectral_helper_raises_complex_same_data(self):
14331433
# test that mode 'complex' cannot be used if x is not y
1434-
pytest.raise(ValueError, mlab._spectral_helper(
1434+
pytest.raises(ValueError, mlab._spectral_helper(
14351435
x=self.y, y=self.y+1, mode='complex'))
14361436

14371437
def test_spectral_helper_raises_magnitude_same_data(self):
14381438
# test that mode 'magnitude' cannot be used if x is not y
1439-
pytest.raise(ValueError, mlab._spectral_helper(
1439+
pytest.raises(ValueError, mlab._spectral_helper(
14401440
x=self.y, y=self.y+1, mode='magnitude'))
14411441

14421442
def test_spectral_helper_raises_angle_same_data(self):
14431443
# test that mode 'angle' cannot be used if x is not y
1444-
pytest.raise(ValueError, mlab._spectral_helper(
1444+
pytest.raises(ValueError, mlab._spectral_helper(
14451445
x=self.y, y=self.y+1, mode='angle'))
14461446

14471447
def test_spectral_helper_raises_phase_same_data(self):
14481448
# test that mode 'phase' cannot be used if x is not y
1449-
pytest.raise(ValueError, mlab._spectral_helper(
1449+
pytest.raises(ValueError, mlab._spectral_helper(
14501450
x=self.y, y=self.y+1, mode='phase'))
14511451

14521452
def test_spectral_helper_raises_unknown_mode(self):
14531453
# test that unknown value for mode cannot be used
1454-
pytest.raise(ValueError, mlab._spectral_helper(
1454+
pytest.raises(ValueError, mlab._spectral_helper(
14551455
x=self.y, mode='spam'))
14561456

14571457
def test_spectral_helper_raises_unknown_sides(self):
14581458
# test that unknown value for sides cannot be used
1459-
pytest.raise(ValueError, mlab._spectral_helper(
1459+
pytest.raises(ValueError, mlab._spectral_helper(
14601460
x=self.y, y=self.y, sides='eggs'))
14611461

14621462
def test_spectral_helper_raises_noverlap_gt_NFFT(self):
14631463
# test that noverlap cannot be larger than NFFT
1464-
pytest.raise(ValueError, mlab._spectral_helper(
1464+
pytest.raises(ValueError, mlab._spectral_helper(
14651465
x=self.y, y=self.y, NFFT=10, noverlap=20))
14661466

14671467
def test_spectral_helper_raises_noverlap_eq_NFFT(self):
14681468
# test that noverlap cannot be equal to NFFT
1469-
pytest.raise(ValueError, mlab._spectral_helper(
1469+
pytest.raises(ValueError, mlab._spectral_helper(
14701470
x=self.y, NFFT=10, noverlap=10))
14711471

14721472
def test_spectral_helper_raises_winlen_ne_NFFT(self):
14731473
# test that the window length cannot be different from NFFT
1474-
pytest.raise(ValueError, mlab._spectral_helper(
1474+
pytest.raises(ValueError, mlab._spectral_helper(
14751475
x=self.y, y=self.y, NFFT=10, window=np.ones(9)))
14761476

14771477
def test_single_spectrum_helper_raises_mode_default(self):
14781478
# test that mode 'default' cannot be used with _single_spectrum_helper
1479-
pytest.raise(ValueError, mlab._single_spectrum_helper(
1479+
pytest.raises(ValueError, mlab._single_spectrum_helper(
14801480
x=self.y, mode='default'))
14811481

14821482
def test_single_spectrum_helper_raises_mode_psd(self):
14831483
# test that mode 'psd' cannot be used with _single_spectrum_helper
1484-
pytest.raise(ValueError, mlab._single_spectrum_helper(
1484+
pytest.raises(ValueError, mlab._single_spectrum_helper(
14851485
x=self.y, mode='psd'))
14861486

14871487
def test_spectral_helper_psd(self):
@@ -1587,7 +1587,7 @@ def test_psd_detrend_mean_func_offset(self):
15871587
assert_array_equal(fsp_b, fsp_c)
15881588
assert_allclose(spec_g, spec_c, atol=1e-08)
15891589
# these should not be almost equal
1590-
pytest.raise(AssertionError,
1590+
pytest.raises(AssertionError,
15911591
assert_allclose(spec_b, spec_c, atol=1e-08))
15921592

15931593
def test_psd_detrend_mean_str_offset(self):
@@ -1623,7 +1623,7 @@ def test_psd_detrend_mean_str_offset(self):
16231623
assert_array_equal(fsp_b, fsp_c)
16241624
assert_allclose(spec_g, spec_c, atol=1e-08)
16251625
# these should not be almost equal
1626-
pytest.raise(AssertionError,
1626+
pytest.raises(AssertionError,
16271627
assert_allclose(spec_b, spec_c, atol=1e-08))
16281628

16291629
def test_psd_detrend_linear_func_trend(self):
@@ -1659,7 +1659,7 @@ def test_psd_detrend_linear_func_trend(self):
16591659
assert_array_equal(fsp_b, fsp_c)
16601660
assert_allclose(spec_g, spec_c, atol=1e-08)
16611661
# these should not be almost equal
1662-
pytest.raise(AssertionError,
1662+
pytest.raises(AssertionError,
16631663
assert_allclose(spec_b, spec_c, atol=1e-08))
16641664

16651665
def test_psd_detrend_linear_str_trend(self):
@@ -1695,7 +1695,7 @@ def test_psd_detrend_linear_str_trend(self):
16951695
assert_array_equal(fsp_b, fsp_c)
16961696
assert_allclose(spec_g, spec_c, atol=1e-08)
16971697
# these should not be almost equal
1698-
pytest.raise(AssertionError,
1698+
pytest.raises(AssertionError,
16991699
assert_allclose(spec_b, spec_c, atol=1e-08))
17001700

17011701
def test_psd_window_hanning(self):
@@ -1739,7 +1739,7 @@ def test_psd_window_hanning(self):
17391739
assert_array_equal(fsp_b, fsp_c)
17401740
assert_allclose(spec_g, spec_c, atol=1e-08)
17411741
# these should not be almost equal
1742-
pytest.raise(AssertionError,
1742+
pytest.raises(AssertionError,
17431743
assert_allclose(spec_b, spec_c, atol=1e-08))
17441744

17451745
def test_psd_window_hanning_detrend_linear(self):
@@ -1788,7 +1788,7 @@ def test_psd_window_hanning_detrend_linear(self):
17881788
assert_array_equal(fsp_b, fsp_c)
17891789
assert_allclose(spec_g, spec_c, atol=1e-08)
17901790
# these should not be almost equal
1791-
pytest.raise(AssertionError,
1791+
pytest.raises(AssertionError,
17921792
assert_allclose(spec_b, spec_c, atol=1e-08))
17931793

17941794
def test_psd_windowarray(self):
@@ -2771,9 +2771,9 @@ def get_z(x, y):
27712771
np.testing.assert_array_almost_equal(zi, correct_zi, 5)
27722772

27732773
# Decreasing xi or yi should raise ValueError.
2774-
pytest.raise(ValueError, mlab.griddata(x, y, z, xi[::-1], yi,
2774+
pytest.raises(ValueError, mlab.griddata(x, y, z, xi[::-1], yi,
27752775
interp='nn'))
2776-
pytest.raise(ValueError, mlab.griddata(x, y, z, xi, yi[::-1],
2776+
pytest.raises(ValueError, mlab.griddata(x, y, z, xi, yi[::-1],
27772777
interp='nn'))
27782778

27792779
# Passing 2D xi and yi arrays to griddata.
@@ -2844,17 +2844,17 @@ def test_kde_bandwidth_method(self):
28442844
class gaussian_kde_custom_tests(object):
28452845
def test_no_data(self):
28462846
"""Pass no data into the GaussianKDE class."""
2847-
pytest.raise(ValueError, mlab.GaussianKDE,([]))
2847+
pytest.raises(ValueError, mlab.GaussianKDE,([]))
28482848

28492849
def test_single_dataset_element(self):
28502850
"""Pass a single dataset element into the GaussianKDE class."""
2851-
pytest.raise(ValueError, mlab.GaussianKDE([42]))
2851+
pytest.raises(ValueError, mlab.GaussianKDE([42]))
28522852

28532853
def test_silverman_multidim_dataset(self):
28542854
"""Use a multi-dimensional array as the dataset and test silverman's
28552855
output"""
28562856
x1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
2857-
pytest.raise(np.linalg.LinAlgError, mlab.GaussianKDE(x1, "silverman"))
2857+
pytest.raises(np.linalg.LinAlgError, mlab.GaussianKDE(x1, "silverman"))
28582858

28592859
def test_silverman_singledim_dataset(self):
28602860
"""Use a single dimension list as the dataset and test silverman's
@@ -2868,7 +2868,7 @@ def test_scott_multidim_dataset(self):
28682868
"""Use a multi-dimensional array as the dataset and test scott's output
28692869
"""
28702870
x1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
2871-
pytest.raise(np.linalg.LinAlgError, mlab.GaussianKDE(x1, "scott"))
2871+
pytest.raises(np.linalg.LinAlgError, mlab.GaussianKDE(x1, "scott"))
28722872

28732873
def test_scott_singledim_dataset(self):
28742874
"""Use a single-dimensional array as the dataset and test scott's
@@ -2881,7 +2881,7 @@ def test_scott_singledim_dataset(self):
28812881
def test_scalar_empty_dataset(self):
28822882
"""Use an empty array as the dataset and test the scalar's cov factor
28832883
"""
2884-
pytest.raise(ValueError, mlab.GaussianKDE([], bw_method=5))
2884+
pytest.raises(ValueError, mlab.GaussianKDE([], bw_method=5))
28852885

28862886
def test_scalar_covariance_dataset(self):
28872887
"""Use a dataset and test a scalar's cov factor
@@ -2921,7 +2921,7 @@ def test_wrong_bw_method(self):
29212921
np.random.seed(8765678)
29222922
n_basesample = 50
29232923
data = np.random.randn(n_basesample)
2924-
pytest.raise(ValueError, mlab.GaussianKDE(data, bw_method="invalid"))
2924+
pytest.raises(ValueError, mlab.GaussianKDE(data, bw_method="invalid"))
29252925

29262926

29272927
class gaussian_kde_evaluate_tests(object):
@@ -2947,7 +2947,7 @@ def test_evaluate_inv_dim(self):
29472947
multidim_data = np.random.randn(n_basesample)
29482948
kde = mlab.GaussianKDE(multidim_data)
29492949
x2 = [[1], [2], [3]]
2950-
pytest.raise(ValueError, kde.evaluate(x2))
2950+
pytest.raises(ValueError, kde.evaluate(x2))
29512951

29522952
def test_evaluate_dim_and_num(self):
29532953
""" Tests if evaluated against a one by one array"""
@@ -2963,7 +2963,7 @@ def test_evaluate_point_dim_not_one(self):
29632963
x1 = np.arange(3, 10, 2)
29642964
x2 = [np.arange(3, 10, 2), np.arange(3, 10, 2)]
29652965
kde = mlab.GaussianKDE(x1)
2966-
pytest.raise(ValueError, kde.evaluate(x2))
2966+
pytest.raises(ValueError, kde.evaluate(x2))
29672967

29682968
def test_evaluate_equal_dim_and_num_lt(self):
29692969
"""Test when line 3810 fails"""

0 commit comments

Comments
 (0)