Skip to content

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

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

Merged
merged 8 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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):
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
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