MCPcopy Create free account
hub / github.com/numpy/numpy / test_getattr_warning

Function test_getattr_warning

numpy/core/tests/test_protocols.py:7–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5
6@pytest.mark.filterwarnings("error")
7def test_getattr_warning():
8 # issue gh-14735: make sure we clear only getattr errors, and let warnings
9 # through
10 class Wrapper:
11 def __init__(self, array):
12 self.array = array
13
14 def __len__(self):
15 return len(self.array)
16
17 def __getitem__(self, item):
18 return type(self)(self.array[item])
19
20 def __getattr__(self, name):
21 if name.startswith("__array_"):
22 warnings.warn("object got converted", UserWarning, stacklevel=1)
23
24 return getattr(self.array, name)
25
26 def __repr__(self):
27 return "<Wrapper({self.array})>".format(self=self)
28
29 array = Wrapper(np.arange(10))
30 with pytest.raises(UserWarning, match="object got converted"):
31 np.asarray(array)
32
33
34def test_array_called():

Callers

nothing calls this directly

Calls 1

WrapperClass · 0.85

Tested by

no test coverage detected