-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
add match message for pytest.raises() #33144
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
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cb2eae7
add msg for groupby test_categorical
sathyz 8ec1552
add message when checking for exceptions.
sathyz 8d8759c
Merge remote-tracking branch 'upstream/master' into issue-30999-2
sathyz 9d6b5c6
add match for pytest.raises()
sathyz 3aa222b
remove numpy comment and use "|".join()
sathyz a958b81
Merge remote-tracking branch 'upstream/master' into issue-30999-2
sathyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,7 +349,8 @@ def test_take(self, indices): | |
|
||
if not isinstance(indices, (DatetimeIndex, PeriodIndex, TimedeltaIndex)): | ||
# GH 10791 | ||
with pytest.raises(AttributeError): | ||
msg = r"'(.*Index)' object has no attribute 'freq'" | ||
with pytest.raises(AttributeError, match=msg): | ||
indices.freq | ||
|
||
def test_take_invalid_kwargs(self): | ||
|
@@ -537,9 +538,11 @@ def test_delete_base(self, indices): | |
assert result.equals(expected) | ||
assert result.name == expected.name | ||
|
||
with pytest.raises((IndexError, ValueError)): | ||
length = len(indices) | ||
msg = r"delete\(\) missing 1 required positional argument: 'loc'" | ||
with pytest.raises(TypeError, match=msg): | ||
# either depending on numpy version | ||
indices.delete(len(indices)) | ||
indices.delete() | ||
|
||
def test_equals(self, indices): | ||
if isinstance(indices, IntervalIndex): | ||
|
@@ -787,13 +790,14 @@ def test_putmask_with_wrong_mask(self): | |
# GH18368 | ||
index = self.create_index() | ||
|
||
with pytest.raises(ValueError): | ||
msg = "putmask: mask and data must be the same size" | ||
with pytest.raises(ValueError, match=msg): | ||
index.putmask(np.ones(len(index) + 1, np.bool), 1) | ||
|
||
with pytest.raises(ValueError): | ||
with pytest.raises(ValueError, match=msg): | ||
index.putmask(np.ones(len(index) - 1, np.bool), 1) | ||
|
||
with pytest.raises(ValueError): | ||
with pytest.raises(ValueError, match=msg): | ||
index.putmask("foo", 1) | ||
|
||
@pytest.mark.parametrize("copy", [True, False]) | ||
|
@@ -859,13 +863,11 @@ def test_getitem_2d_deprecated(self): | |
|
||
assert isinstance(res, np.ndarray), type(res) | ||
|
||
def test_contains_requires_hashable_raises(self): | ||
@pytest.mark.parametrize("value", [[], {}]) | ||
def test_contains_requires_hashable_raises(self, value): | ||
idx = self.create_index() | ||
with pytest.raises(TypeError, match="unhashable type"): | ||
[] in idx | ||
|
||
with pytest.raises(TypeError): | ||
{} in idx._engine | ||
value in idx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we also need to check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @jbrockmendel added it now. |
||
|
||
def test_copy_copies_cache(self): | ||
# GH32898 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot to put
length
inside theindices.delete()
, on L545.And I think that this also means you need to change the error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think @MomIsBestFriend is correct here, the unused
length
is also the source of the linting failure