8000 TST: add broadcast_arrays() kwarg unit test for TypeError by tylerjereddy · Pull Request #11573 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TST: add broadcast_arrays() kwarg unit test for TypeError #11573

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 2 commits into from
Aug 21, 2018

Conversation

tylerjereddy
Copy link
Contributor
@tylerjereddy tylerjereddy commented Jul 14, 2018

In short, local coverage tests (hopefully reported online soon from: #11567) indicated that we weren't unit testing for the proper handling of invalid kwargs for np.broadcast_arrays().

In adding the unit test for this kwarg handling in this PR, I also noticed that the appropriate error message is not raised in Python 3 because dict.keys() is not a list anymore, so the test was also adjusted to verify the correct error message & the associated source code modified to ensure an indexable object in Python 3.

broadcast_arrays(x, y, dtype='float64')

assert ('broadcast_arrays() got an unexpected keyword' in
str(excinfo.value))
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I think we are still using assert_. We should probably have a agreement about how to proceed with the new options pytest gives us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reference, SciPy had this discussion a few months ago--not sure if we should similarly open an issue or ask on the mailing list? They decided in favor of allowing pytest assert usage in new PRs, but didn't mandate a mass migration.

Perhaps I'll just revert here for now?

Copy link
Member
@eric-wieser eric-wieser Aug 21, 2018

Choose a reason for hiding this comment

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

If we were using pytest more broadly here, I think you could spell this assert excinfo.match(r'broadcast_arrays\(\) got an unexpected keyword')

@@ -1,6 +1,7 @@
from __future__ import division, absolute_import, print_function

import numpy as np
import pytest
Copy link
Member

Choose a reason for hiding this comment

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

We generally import system stuff first.

@tylerjereddy
Copy link
Contributor Author

I've restored usage of assert_ to reduce the friction there.

As far as I can tell the NumPy assert_raises doesn't support catching the error string associated with an exception (or it isn't documented?), so if the use of pytest.raises() is not acceptable here I'll also have to remove the check for the error string / message added in testing changes here.

@charris
Copy link
Member
charris commented Jul 26, 2018

You probably want assert_raises_regex.

@tylerjereddy
Copy link
Contributor Author

assert_raises_regex calls nose.tools.assert_raises_regex in the source

@tylerjereddy
Copy link
Contributor Author

Is the preference here for me to still call the nose-dependent test utility or can I use the pytest one to check the message raised?

@charris
Copy link
Member
charris commented Aug 1, 2018

@tylerjereddy assert_raises-regex no longer uses nose, it comes from unittest, which is where nose got it from. You are looking at old code.

@tylerjereddy tylerjereddy force-pushed the broadcast_arrays_kw_test branch from ba1fdf3 to ff1e02f Compare August 1, 2018 20:42
@tylerjereddy
Copy link
Contributor Author

@charris Thanks for pointing out my mistake; I've now completely removed the pytest usage in the affected testing module and it seems to work just fine locally--hopefully the CI agrees.

* broadcast_arrays() is now tested for the case when an invalid
keyword argument is used; the appropriate error string content
is also tested for

* the TypeError message produced in the above case has been restored
to the correct value in Python 3
@tylerjereddy tylerjereddy force-pushed the broadcast_arrays_kw_test branch from ff1e02f to 81bd37e Compare August 2, 2018 00:28
Copy link
Member
@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

Made one small style tweak to reduce escaping - feel free to merge when tests pass

@mattip mattip merged commit 0b5dfb0 into numpy:master Aug 21, 2018
@mattip
Copy link
Member
mattip commented Aug 21, 2018

Thanks @tylerjereddy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0