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

Method test_method

numpy/core/tests/test_overrides.py:148–193  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

146class TestNDArrayArrayFunction:
147
148 def test_method(self):
149
150 class Other:
151 __array_function__ = _return_not_implemented
152
153 class NoOverrideSub(np.ndarray):
154 pass
155
156 class OverrideSub(np.ndarray):
157 __array_function__ = _return_not_implemented
158
159 array = np.array([1])
160 other = Other()
161 no_override_sub = array.view(NoOverrideSub)
162 override_sub = array.view(OverrideSub)
163
164 result = array.__array_function__(func=dispatched_two_arg,
165 types=(np.ndarray,),
166 args=(array, 1.), kwargs={})
167 assert_equal(result, 'original')
168
169 result = array.__array_function__(func=dispatched_two_arg,
170 types=(np.ndarray, Other),
171 args=(array, other), kwargs={})
172 assert_(result is NotImplemented)
173
174 result = array.__array_function__(func=dispatched_two_arg,
175 types=(np.ndarray, NoOverrideSub),
176 args=(array, no_override_sub),
177 kwargs={})
178 assert_equal(result, 'original')
179
180 result = array.__array_function__(func=dispatched_two_arg,
181 types=(np.ndarray, OverrideSub),
182 args=(array, override_sub),
183 kwargs={})
184 assert_equal(result, 'original')
185
186 with assert_raises_regex(TypeError, 'no implementation found'):
187 np.concatenate((array, other))
188
189 expected = np.concatenate((array, array))
190 result = np.concatenate((array, no_override_sub))
191 assert_equal(result, expected.view(NoOverrideSub))
192 result = np.concatenate((array, override_sub))
193 assert_equal(result, expected.view(OverrideSub))
194
195 def test_no_wrapper(self):
196 # This shouldn't happen unless a user intentionally calls

Callers

nothing calls this directly

Calls 6

assert_equalFunction · 0.90
assert_Function · 0.90
assert_raises_regexFunction · 0.90
OtherClass · 0.70
viewMethod · 0.45
__array_function__Method · 0.45

Tested by

no test coverage detected