Skip to content

Commit

Permalink
TST: add message matches to pytest.raises in various tests GH30999 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseNavy authored Dec 8, 2020
1 parent 54ac621 commit 32bebdb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
21 changes: 19 additions & 2 deletions pandas/tests/io/pytables/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,34 @@ def test_complex_indexing_error(setup_path):
{"A": [1, 2, 3, 4], "B": ["a", "b", "c", "d"], "C": complex128},
index=list("abcd"),
)

msg = (
"Columns containing complex values can be stored "
"but cannot be indexed when using table format. "
"Either use fixed format, set index=False, "
"or do not include the columns containing complex "
"values to data_columns when initializing the table."
)

with ensure_clean_store(setup_path) as store:
with pytest.raises(TypeError):
with pytest.raises(TypeError, match=msg):
store.append("df", df, data_columns=["C"])


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

msg = (
"Columns containing complex values can be stored "
"but cannot be indexed when using table format. "
"Either use fixed format, set index=False, "
"or do not include the columns containing complex "
"values to data_columns when initializing the table."
)

with ensure_clean_path(setup_path) as path:
with pytest.raises(TypeError):
with pytest.raises(TypeError, match=msg):
s.to_hdf(path, "obj", format="t")

with ensure_clean_path(setup_path) as path:
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/io/test_clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,11 @@ def test_read_clipboard_infer_excel(self, request, mock_clipboard):
tm.assert_frame_equal(res, exp)

def test_invalid_encoding(self, df):
msg = "clipboard only supports utf-8 encoding"
# test case for testing invalid encoding
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=msg):
df.to_clipboard(encoding="ascii")
with pytest.raises(NotImplementedError):
with pytest.raises(NotImplementedError, match=msg):
pd.read_clipboard(encoding="ascii")

@pytest.mark.parametrize("enc", ["UTF-8", "utf-8", "utf8"])
Expand Down
12 changes: 9 additions & 3 deletions pandas/tests/plotting/frame/test_frame_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,13 @@ def test_subplots_layout_multi_column(self):
self._check_axes_shape(axes, axes_num=3, layout=(4, 1))
assert axes.shape == (4, 1)

with pytest.raises(ValueError):
msg = "Layout of 1x1 must be larger than required size 3"

with pytest.raises(ValueError, match=msg):
df.plot(subplots=True, layout=(1, 1))
with pytest.raises(ValueError):

msg = "At least one dimension of layout must be positive"
with pytest.raises(ValueError, match=msg):
df.plot(subplots=True, layout=(-1, -1))

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

with pytest.raises(ValueError):
msg = "The number of passed axes must be 3, the same as the output plot"

with pytest.raises(ValueError, match=msg):
fig, axes = self.plt.subplots(2, 3)
# pass different number of axes from required
df.plot(subplots=True, ax=axes)
Expand Down

0 comments on commit 32bebdb

Please sign in to comment.