Skip to content

Commit 32bebdb

Browse files
authored
TST: add message matches to pytest.raises in various tests GH30999 (#38350)
1 parent 54ac621 commit 32bebdb

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

pandas/tests/io/pytables/test_complex.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,34 @@ def test_complex_indexing_error(setup_path):
149149
{"A": [1, 2, 3, 4], "B": ["a", "b", "c", "d"], "C": complex128},
150150
index=list("abcd"),
151151
)
152+
153+
msg = (
154+
"Columns containing complex values can be stored "
155+
"but cannot be indexed when using table format. "
156+
"Either use fixed format, set index=False, "
157+
"or do not include the columns containing complex "
158+
"values to data_columns when initializing the table."
159+
)
160+
152161
with ensure_clean_store(setup_path) as store:
153-
with pytest.raises(TypeError):
162+
with pytest.raises(TypeError, match=msg):
154163
store.append("df", df, data_columns=["C"])
155164

156165

157166
def test_complex_series_error(setup_path):
158167
complex128 = np.array([1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j])
159168
s = Series(complex128, index=list("abcd"))
160169

170+
msg = (
171+
"Columns containing complex values can be stored "
172+
"but cannot be indexed when using table format. "
173+
"Either use fixed format, set index=False, "
174+
"or do not include the columns containing complex "
175+
"values to data_columns when initializing the table."
176+
)
177+
161178
with ensure_clean_path(setup_path) as path:
162-
with pytest.raises(TypeError):
179+
with pytest.raises(TypeError, match=msg):
163180
s.to_hdf(path, "obj", format="t")
164181

165182
with ensure_clean_path(setup_path) as path:

pandas/tests/io/test_clipboard.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,11 @@ def test_read_clipboard_infer_excel(self, request, mock_clipboard):
238238
tm.assert_frame_equal(res, exp)
239239

240240
def test_invalid_encoding(self, df):
241+
msg = "clipboard only supports utf-8 encoding"
241242
# test case for testing invalid encoding
242-
with pytest.raises(ValueError):
243+
with pytest.raises(ValueError, match=msg):
243244
df.to_clipboard(encoding="ascii")
244-
with pytest.raises(NotImplementedError):
245+
with pytest.raises(NotImplementedError, match=msg):
245246
pd.read_clipboard(encoding="ascii")
246247

247248
@pytest.mark.parametrize("enc", ["UTF-8", "utf-8", "utf8"])

pandas/tests/plotting/frame/test_frame_subplots.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,13 @@ def test_subplots_layout_multi_column(self):
218218
self._check_axes_shape(axes, axes_num=3, layout=(4, 1))
219219
assert axes.shape == (4, 1)
220220

221-
with pytest.raises(ValueError):
221+
msg = "Layout of 1x1 must be larger than required size 3"
222+
223+
with pytest.raises(ValueError, match=msg):
222224
df.plot(subplots=True, layout=(1, 1))
223-
with pytest.raises(ValueError):
225+
226+
msg = "At least one dimension of layout must be positive"
227+
with pytest.raises(ValueError, match=msg):
224228
df.plot(subplots=True, layout=(-1, -1))
225229

226230
@pytest.mark.parametrize(
@@ -272,7 +276,9 @@ def test_subplots_multiple_axes(self):
272276
self._check_axes_shape(axes, axes_num=6, layout=(2, 3))
273277
tm.close()
274278

275-
with pytest.raises(ValueError):
279+
msg = "The number of passed axes must be 3, the same as the output plot"
280+
281+
with pytest.raises(ValueError, match=msg):
276282
fig, axes = self.plt.subplots(2, 3)
277283
# pass different number of axes from required
278284
df.plot(subplots=True, ax=axes)

0 commit comments

Comments
 (0)