Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: add message matches to pytest.raises in various tests GH30999 #38350

Merged
merged 8 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 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,22 @@ def test_complex_indexing_error(setup_path):
{"A": [1, 2, 3, 4], "B": ["a", "b", "c", "d"], "C": complex128},
index=list("abcd"),
)

msg = "indexing error with complex numbers"

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 = "type error in series of complex"

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 = "invalid coding, encoding must be ascii"
# test case for testing invalid encoding
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=msg):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the CI the message being thrown is different

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that the message didn't exist and wrote one, I'll fix them so they match with what's supposed to say. Where can I find the exact message?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run the code that throws the error

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
10 changes: 7 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,11 @@ 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 = "can't create subplots with layout (1,1) or (-1,-1)"

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

@pytest.mark.parametrize(
Expand Down Expand Up @@ -272,7 +274,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 = "number of axes passed is different than the ones required"

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