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

MAINT: Remove assertRaises from testing #16089

Merged
merged 1 commit into from
Apr 21, 2017

Conversation

gfyoung
Copy link
Member

@gfyoung gfyoung commented Apr 21, 2017

Title is self-explanatory. Pretty hefty PR this one.

Partially addresses #15990.

@codecov
Copy link

codecov bot commented Apr 21, 2017

Codecov Report

Merging #16089 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #16089   +/-   ##
=======================================
  Coverage   90.84%   90.84%           
=======================================
  Files         159      159           
  Lines       50771    50771           
=======================================
  Hits        46125    46125           
  Misses       4646     4646
Flag Coverage Δ
#multiple 88.62% <100%> (ø) ⬆️
#single 40.36% <100%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/util/testing.py 79.51% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f9c854...51ed9f5. Read the comment docs.

@jreback jreback added the Testing pandas testing functions or related to the test suite label Apr 21, 2017
@jreback jreback added this to the 0.20.0 milestone Apr 21, 2017
@jreback jreback merged commit d528a10 into pandas-dev:master Apr 21, 2017
@jreback
Copy link
Contributor

jreback commented Apr 21, 2017

thanks!

awesome job!

@gfyoung
Copy link
Member Author

gfyoung commented Apr 21, 2017

FYI (for future PR's), tm.assertRaisesRegexp should not be used. Rather, we should use this paradigm:

with pytest.raises(cls) as exc_info:
   ...
exc_info.matches(regexp)

I stumbled upon this while doing this massive PR. Removing assertRaisesRegexp is going to take A LOT more work to replace than it was to replace assertRaises.

@gfyoung gfyoung deleted the assertRaises-remove branch April 21, 2017 22:04
@jreback
Copy link
Contributor

jreback commented Apr 21, 2017

hmm, that's going to be a change, though ok with it if its documented :>

can you create a context manager which emulated assertRaisesRegexp (or gives a better name)?

@gfyoung
Copy link
Member Author

gfyoung commented Apr 21, 2017

hmm, that's going to be a change, though ok with it if its documented :>

Yes, I added that in this PR.

can you create a context manager which emulated assertRaisesRegexp (or gives a better name)?

I think the name is alright, and we do have a context manager for this (it's a port of Python 2.7's implementation).

@jorisvandenbossche
Copy link
Member

@gfyoung what is wrong with tm.assertRaisesRegexp ? (why should it not be used)

@gfyoung
Copy link
Member Author

gfyoung commented Apr 21, 2017

It isn't idiomatic under the pytest framework. Also, it is a port of Python's unittest tm.assertRaisesRegexp (extra bloat to test framework).

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Apr 21, 2017

Why isn't it idiomatic? I think it is very similar to pytest.raises in usage, but with a more specific functionality (just a different style in the naming)

And it is not because it is a port of a unittest function, that it is bad?

@jreback
Copy link
Contributor

jreback commented Apr 21, 2017

i agree with joris
let's just rename to non camel

@gfyoung
Copy link
Member Author

gfyoung commented Apr 22, 2017

The docs explicitly address regex matching in the form that I described above. Also, is it not preferable to use the built-in methods instead of maintaining our own version of a port? Does that change anything?

Also, I don't know what you think about this, but what about pytest.warns instead of tm.assert_produces_warning (see here)?

I'm not pushing these very hard (I ask because they are the pytest conventions instead of unittest for example). However, even if we don't make these changes, we could at least document in #15990 why they were not made.

gfyoung added a commit to forking-repos/pandas that referenced this pull request Apr 22, 2017
Rewrite _AssertRaisesContextManager with more
documentation and remove vestigial assertRaises.

Follow-up to pandas-devgh-16089.
gfyoung added a commit to forking-repos/pandas that referenced this pull request Apr 22, 2017
Rewrite _AssertRaisesContextManager with more
documentation and remove vestigial assertRaises.

Follow-up to pandas-devgh-16089.
gfyoung added a commit to forking-repos/pandas that referenced this pull request Apr 22, 2017
Rewrite _AssertRaisesContextManager with more
documentation and remove vestigial assertRaises.

Follow-up to pandas-devgh-16089.
gfyoung added a commit to forking-repos/pandas that referenced this pull request Apr 22, 2017
Rewrite _AssertRaisesContextManager with more
documentation and remove vestigial assertRaises.

Follow-up to pandas-devgh-16089.
jreback pushed a commit that referenced this pull request Apr 23, 2017
* MAINT: Refactor _AssertRaisesContextManager

Rewrite _AssertRaisesContextManager with more
documentation and remove vestigial assertRaises.

Follow-up to gh-16089.

* MAINT: Remove assertNotIn from testing
@gfyoung gfyoung mentioned this pull request Apr 23, 2017
9 tasks
@jorisvandenbossche
Copy link
Member

I still think a helper function is more easy to use than what the pytest docs propose to do (but nice docs actually!), but based on what they do, we can probably simplify the current implementation of assertRaisesRegex a lot?

@gfyoung
Copy link
Member Author

gfyoung commented Apr 24, 2017

The current implementation of assertRaisesRegexp is relatively stripped down I thought. Most of the heavy lifting is done by the context manager. What did you think we could simplify?

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Apr 24, 2017

What I meant was that wrapping the code snippet you gave above in a new contextmanager, may be less code than the current implementation (thus, using the pytest functionality for asserting the raised error, checking the error message).
But I didn't look in detail whether this would be worth it (actually improve code simplicity), and it may also not cover directly all cases that the current code can handle.

@gfyoung
Copy link
Member Author

gfyoung commented Apr 24, 2017

Hmmm...I'm not sure how worthwhile that may be since you have to consider both cases when it is used as a context manager (with) statement or a pure function call (context manager used internally). And I don't think wrapping the pytest snippet is flexible enough to avoid duplicating logic across both cases.

tswast added a commit to tswast/python-bigquery-pandas that referenced this pull request May 19, 2017
This method was removed in
pandas-dev/pandas#16089 in favor of
pytest.raises.
pcluo pushed a commit to pcluo/pandas that referenced this pull request May 22, 2017
pcluo pushed a commit to pcluo/pandas that referenced this pull request May 22, 2017
* MAINT: Refactor _AssertRaisesContextManager

Rewrite _AssertRaisesContextManager with more
documentation and remove vestigial assertRaises.

Follow-up to pandas-devgh-16089.

* MAINT: Remove assertNotIn from testing
parthea pushed a commit to parthea/pandas-gbq that referenced this pull request Jun 11, 2017
This method was removed in
pandas-dev/pandas#16089 in favor of
pytest.raises.
parthea added a commit to googleapis/python-bigquery-pandas that referenced this pull request Jun 11, 2017
* TST: Fix broken tests failing with 'NoneType' object is not iterable

* MAINT: pandas.util.testing.assertRaises removed

This method was removed in
pandas-dev/pandas#16089 in favor of
pytest.raises.

* MAINT: pandas.util.testing.assert_equals removed

This method was removed in
pandas-dev/pandas#16017 in favor of
pytest.raises.
tswast added a commit to tswast/python-bigquery-pandas that referenced this pull request Jun 12, 2017
This method was removed in
pandas-dev/pandas#16089 in favor of
pytest.raises.
parthea pushed a commit to parthea/pandas-gbq that referenced this pull request Jun 16, 2017
This method was removed in
pandas-dev/pandas#16089 in favor of
pytest.raises.
parthea pushed a commit to tswast/python-bigquery-pandas that referenced this pull request Jun 16, 2017
This method was removed in
pandas-dev/pandas#16089 in favor of
pytest.raises.
parthea pushed a commit to googleapis/python-bigquery-pandas that referenced this pull request Jun 16, 2017
* BUG: oauth2client deprecated, use google-auth instead.

Remove the use of oauth2client and use google-auth library, instead.
See GH#37.

Rather than check for multiple versions of the libraries, use the
setup.py to specify compatible versions. I believe this is safe since
Pandas checks for the pandas_gbq package.

Since google-auth does not use the argparse module to override user
authentication flow settings, add a parameter to choose between the web
and console flow.

Addresses some eventual consistency issues in table/dataset listing in
the integration tests.

* MAINT: pandas.util.testing.assertRaises removed

This method was removed in
pandas-dev/pandas#16089 in favor of
pytest.raises.

* MAINT: pandas.util.testing.assert_equals removed

This method was removed in
pandas-dev/pandas#16017 in favor of
pytest.raises.

* DOC: add version tags for new auth_local_webserver params.

* CLN: share _test_imports between main module and tests

* TST: pin versions on 3.5 rather than 2.7.
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.

3 participants