1
1
"""Testing functions exposed to the user API"""
2
2
import functools
3
+ import warnings
3
4
from typing import Hashable , Set , Union
4
5
5
6
import numpy as np
21
22
)
22
23
23
24
25
+ def ensure_warnings (func ):
26
+ # sometimes tests elevate warnings to errors
27
+ # -> make sure that does not happen in the assert_* functions
28
+ @functools .wraps (func )
29
+ def wrapper (* args , ** kwargs ):
30
+ with warnings .catch_warnings ():
31
+ warnings .simplefilter ("always" )
32
+
33
+ return func (* args , ** kwargs )
34
+
35
+ return wrapper
36
+
37
+
24
38
def _decode_string_data (data ):
25
39
if data .dtype .kind == "S" :
26
40
return np .core .defchararray .decode (data , "utf-8" , "replace" )
@@ -38,6 +52,7 @@ def _data_allclose_or_equiv(arr1, arr2, rtol=1e-05, atol=1e-08, decode_bytes=Tru
38
52
return duck_array_ops .allclose_or_equiv (arr1 , arr2 , rtol = rtol , atol = atol )
39
53
40
54
55
+ @ensure_warnings
41
56
def assert_equal (a , b ):
42
57
"""Like :py:func:`numpy.testing.assert_array_equal`, but for xarray
43
58
objects.
@@ -69,6 +84,7 @@ def assert_equal(a, b):
69
84
raise TypeError ("{} not supported by assertion comparison" .format (type (a )))
70
85
71
86
87
+ @ensure_warnings
72
88
def assert_identical (a , b ):
73
89
"""Like :py:func:`xarray.testing.assert_equal`, but also matches the
74
90
objects' names and attributes.
@@ -99,6 +115,7 @@ def assert_identical(a, b):
99
115
raise TypeError ("{} not supported by assertion comparison" .format (type (a )))
100
116
101
117
118
+ @ensure_warnings
102
119
def assert_allclose (a , b , rtol = 1e-05 , atol = 1e-08 , decode_bytes = True ):
103
120
"""Like :py:func:`numpy.testing.assert_allclose`, but for xarray objects.
104
121
@@ -182,6 +199,7 @@ def _format_message(x, y, err_msg, verbose):
182
199
return "\n " .join (parts )
183
200
184
201
202
+ @ensure_warnings
185
203
def assert_duckarray_allclose (
186
204
actual , desired , rtol = 1e-07 , atol = 0 , err_msg = "" , verbose = True
187
205
):
@@ -192,6 +210,7 @@ def assert_duckarray_allclose(
192
210
assert allclose , _format_message (actual , desired , err_msg = err_msg , verbose = verbose )
193
211
194
212
213
+ @ensure_warnings
195
214
def assert_duckarray_equal (x , y , err_msg = "" , verbose = True ):
196
215
""" Like `np.testing.assert_array_equal`, but for duckarrays """
197
216
__tracebackhide__ = True
0 commit comments