Skip to content

TST: Bare pytest raises #38576

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 14 commits into from
Dec 20, 2020
Merged

Conversation

MJafarMashhadi
Copy link
Contributor

@MJafarMashhadi MJafarMashhadi commented Dec 19, 2020

Comment on lines 33 to 43
msg = (
"(unsupported operand type\\(s\\) for)|"
"(cannot perform [\\w_]+ with this index type: [\\w_]+)|"
"(Object with dtype category cannot perform the numpy op [\\w_]+)|"
"(cannot add [\\w_]+ and [\\w_]+)|"
"(can't multiply sequence by non-int of type '[\\w_]+')|"
'(can only concatenate str \\(not "[\\w_]+"\\) to str)|'
"(Object with dtype category cannot perform the numpy op [\\w_]+)|"
"(Concatenation operation is not implemented for NumPy arrays)"
)
with pytest.raises(exc, 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.

nice! I haven't tried running this, but I would have thought that the parentheses would be redundant - does

Suggested change
msg = (
"(unsupported operand type\\(s\\) for)|"
"(cannot perform [\\w_]+ with this index type: [\\w_]+)|"
"(Object with dtype category cannot perform the numpy op [\\w_]+)|"
"(cannot add [\\w_]+ and [\\w_]+)|"
"(can't multiply sequence by non-int of type '[\\w_]+')|"
'(can only concatenate str \\(not "[\\w_]+"\\) to str)|'
"(Object with dtype category cannot perform the numpy op [\\w_]+)|"
"(Concatenation operation is not implemented for NumPy arrays)"
)
with pytest.raises(exc, match=msg):
msg = (
"unsupported operand type\\(s\\) for|"
"cannot perform [\\w_]+ with this index type: [\\w_]+|"
"Object with dtype category cannot perform the numpy op [\\w_]+|"
"cannot add [\\w_]+ and [\\w_]+|"
"can't multiply sequence by non-int of type '[\\w_]+'|"
'can only concatenate str \\(not "[\\w_]+"\\) to str|'
"Object with dtype category cannot perform the numpy op [\\w_]+|"
"Concatenation operation is not implemented for NumPy arrays"
)
with pytest.raises(exc, match=msg):

work?

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 tested it; it works without the parentheses, I put them there just to be cautious. I'll push a new commit removing them in a moment :-]

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Looks good to me

@MarcoGorelli MarcoGorelli added the Testing pandas testing functions or related to the test suite label Dec 19, 2020
@MarcoGorelli MarcoGorelli added this to the 1.3 milestone Dec 19, 2020
@mroeschke mroeschke merged commit 9919623 into pandas-dev:master Dec 20, 2020
@mroeschke
Copy link
Member

Thanks @MJafarMashhadi

@jorisvandenbossche
Copy link
Member

This are base extension tests, which are also used by external projects. IMO, we should not be adding such specific message tests. I would propose to revert this change.

(and @MJafarMashhadi, to be clear, not your fault!)

@MarcoGorelli
Copy link
Member

Makes sense

Should this be reverted and then ^pandas/tests/extension/ excluded from when the "disallow bare pytest raises" will be applied to CI, or should something generic like match='' be added here?

@xhochy
Copy link
Contributor

xhochy commented Dec 27, 2020

Yes, please revert that. I need to hardcode specific messages now in xhochy/fletcher#212

@jorisvandenbossche
Copy link
Member

Will do a revert tomorrow

jorisvandenbossche added a commit that referenced this pull request Dec 28, 2020
jreback pushed a commit that referenced this pull request Dec 28, 2020
* Revert "TST: Bare pytest raises (#38576)"

This reverts commit 9919623.
@MJafarMashhadi
Copy link
Contributor Author

MJafarMashhadi commented Dec 30, 2020

@jorisvandenbossche There are 4 files that are changed in this PR, two of them are not in extension/ should those be reverted too?

@jorisvandenbossche
Copy link
Member

The non-extension tests in test_assert_series_equal.py were not reverted in #38748

luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
* test_assert_series_equal.py

* test_setitem_slice_mismatch_length_raises

* test_setitem_scalar_key_sequence_raise

* test_sub

* test_arithmetic

* black pandas on test_arithmetic.py

* black pandas on setitem.py

* BaseComparisonOpsTests

* extension/base/ops.py

* Break too long lines

* The numpy error was an external one

* Update RegExs to match more tests

* Added new error messages

* Removed redundant parenthesis in regexps
luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
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.

5 participants