Skip to content

Commit 4298eba

Browse files
committed
more detailed AssertionError message for assert_identical
1 parent f9464fd commit 4298eba

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

xarray/testing.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from __future__ import division
44
from __future__ import print_function
55

6+
from io import StringIO
7+
68
import numpy as np
79

810
from xarray.core import duck_array_ops
@@ -27,6 +29,12 @@ def _data_allclose_or_equiv(arr1, arr2, rtol=1e-05, atol=1e-08,
2729
arr1, arr2, rtol=rtol, atol=atol)
2830

2931

32+
def _get_info_as_str(dataset):
33+
buf = StringIO()
34+
dataset.info(buf=buf)
35+
return buf.getvalue()
36+
37+
3038
def assert_equal(a, b):
3139
"""Like :py:func:`numpy.testing.assert_array_equal`, but for xarray
3240
objects.
@@ -82,7 +90,10 @@ def assert_identical(a, b):
8290
assert a.name == b.name
8391
assert_identical(a._to_temp_dataset(), b._to_temp_dataset())
8492
elif isinstance(a, (xr.Dataset, xr.Variable)):
85-
assert a.identical(b), '{}\n{}'.format(a, b)
93+
assert a.identical(b), (
94+
'{}\n{}\n---\n{}\n{}'
95+
.format(a, b, _get_info_as_str(a), _get_info_as_str(b))
96+
)
8697
else:
8798
raise TypeError('{} not supported by assertion comparison'
8899
.format(type(a)))

0 commit comments

Comments
 (0)