-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add names for test failures #1690
Conversation
xarray/testing.py
Outdated
b.coords[v].values) | ||
assert allclose, 'coord {}:{}\n{}'.format(a.coords[v].name, | ||
a.coords[v].values, | ||
b.coords[v].values) |
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.
What about adding name
to the error message for non-coordinates, too? We could do this by adding an optional name
argument to this function. (It would also be useful for assert_equal
and assert_identical
.)
@shoyer I had to think a bit on your suggestion to figure out a way to make the name parameter work for the recursive cases, but now here's something to that effect. Also made me wonder how useful a test suite for testing test failures would be... |
@@ -42,6 +42,8 @@ def assert_equal(a, b): | |||
The first object to compare. | |||
b : xarray.Dataset, xarray.DataArray or xarray.Variable | |||
The second object to compare. | |||
name : str, optional |
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.
Maybe we should have a private function, e.g., assert_variable_equal
, that accepts an optional name
and call that from assert_equal
? It's a little weird to allow names for Dataset objects.
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 didn't consider it as a name for either object, but rather an identifier for the specific assertion. Maybe it should be named/documented better as such?
xarray/testing.py
Outdated
@@ -27,7 +27,7 @@ def _data_allclose_or_equiv(arr1, arr2, rtol=1e-05, atol=1e-08, | |||
arr1, arr2, rtol=rtol, atol=atol) | |||
|
|||
|
|||
def assert_equal(a, b): | |||
def assert_equal(a, b, name=''): |
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.
None
is probably a better default value. It's valid (though obviously not a great idea) to have an xarray object with name given by an empty string.
Could this be merged? From what I can see, |
Now that #1507 is merged, alternatively we could just reuse the |
This PR adds the coordinate name to the test failure printout in
assert_allclose()
when cycling through the coordinates . Specifying the coordinate makes test failures much easier to diagnose just based on the message.git diff upstream/master **/*py | flake8 --diff
whats-new.rst
for all changes andapi.rst
for new API