Skip to content

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 6 commits into from
Apr 19, 2020
Merged

Conversation

sathyz
Copy link
Contributor

@sathyz sathyz commented Mar 30, 2020

Comment on lines 541 to 545
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()
Copy link
Member

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 the indices.delete(), on L545.

And I think that this also means you need to change the error message.

Copy link
Member

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

@ShaharNaveh ShaharNaveh added the Testing pandas testing functions or related to the test suite label Mar 30, 2020

with pytest.raises(TypeError):
{} in idx._engine
value in idx
Copy link
Member

Choose a reason for hiding this comment

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

we also need to check for value in idx._engine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @jbrockmendel added it now.

with pytest.raises((IndexError, ValueError)):
# Exception raised depends on NumPy version.
msg = "index 6 is out of bounds for axis 0 with size 6"
with pytest.raises(IndexError, match=msg):
idx.delete(len(idx))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@sathyz Thank you for looking into this!

@sathyz sathyz marked this pull request as ready for review March 31, 2020 04:18
with pytest.raises(TypeError, match=msg):
[] in idx

msg = (
Copy link
Member

Choose a reason for hiding this comment

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

Can you please use the pattern of:

msg = "|".join([
     "foo",
     "bar",
     "baz"
])

Copy link
Member

Choose a reason for hiding this comment

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

+1

@@ -105,7 +105,11 @@ def test_unsortedindex():
expected = df.iloc[0]
tm.assert_series_equal(result, expected)

with pytest.raises(UnsortedIndexError):
msg = (
r"MultiIndex slicing requires the index to be lexsorted: "
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
r"MultiIndex slicing requires the index to be lexsorted: "
"MultiIndex slicing requires the index to be lexsorted: "

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A single line is split into multiple lines, to adhere to the formatting rules. If I were to do this, one of the lines will be "" and other will be r"".

# either depending on numpy version
indices.delete()
indices.delete(length)
Copy link
Member

Choose a reason for hiding this comment

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

are we testing the missing-argument case somewhere else?

i think the "either depending..." comment is obsolete

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

@jbrockmendel mentioned to remove a comment, pls do so and ping on green.

@jreback jreback added this to the 1.1 milestone Apr 3, 2020
@sathyz
Copy link
Contributor Author

sathyz commented Apr 13, 2020

I'm not sure if I have broken something in the tests, the failures are from the modules which I haven't touched, waiting for the fixes in master.

@jbrockmendel
Copy link
Member

LGTM

@sathyz
Copy link
Contributor Author

sathyz commented Apr 19, 2020

@jreback should be good to merge now.

@jreback jreback merged commit 37022be into pandas-dev:master Apr 19, 2020
@jreback
Copy link
Contributor

jreback commented Apr 19, 2020

thanks @sathyz

CloseChoice pushed a commit to CloseChoice/pandas that referenced this pull request Apr 20, 2020
rhshadrach pushed a commit to rhshadrach/pandas that referenced this pull request May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants