(self)
| 149 | class TestNDArrayArrayFunction: |
| 150 | |
| 151 | def test_method(self): |
| 152 | |
| 153 | class Other: |
| 154 | __array_function__ = _return_not_implemented |
| 155 | |
| 156 | class NoOverrideSub(np.ndarray): |
| 157 | pass |
| 158 | |
| 159 | class OverrideSub(np.ndarray): |
| 160 | __array_function__ = _return_not_implemented |
| 161 | |
| 162 | array = np.array([1]) |
| 163 | other = Other() |
| 164 | no_override_sub = array.view(NoOverrideSub) |
| 165 | override_sub = array.view(OverrideSub) |
| 166 | |
| 167 | result = array.__array_function__(func=dispatched_two_arg, |
| 168 | types=(np.ndarray,), |
| 169 | args=(array, 1.), kwargs={}) |
| 170 | assert_equal(result, 'original') |
| 171 | |
| 172 | result = array.__array_function__(func=dispatched_two_arg, |
| 173 | types=(np.ndarray, Other), |
| 174 | args=(array, other), kwargs={}) |
| 175 | assert_(result is NotImplemented) |
| 176 | |
| 177 | result = array.__array_function__(func=dispatched_two_arg, |
| 178 | types=(np.ndarray, NoOverrideSub), |
| 179 | args=(array, no_override_sub), |
| 180 | kwargs={}) |
| 181 | assert_equal(result, 'original') |
| 182 | |
| 183 | result = array.__array_function__(func=dispatched_two_arg, |
| 184 | types=(np.ndarray, OverrideSub), |
| 185 | args=(array, override_sub), |
| 186 | kwargs={}) |
| 187 | assert_equal(result, 'original') |
| 188 | |
| 189 | with assert_raises_regex(TypeError, 'no implementation found'): |
| 190 | np.concatenate((array, other)) |
| 191 | |
| 192 | expected = np.concatenate((array, array)) |
| 193 | result = np.concatenate((array, no_override_sub)) |
| 194 | assert_equal(result, expected.view(NoOverrideSub)) |
| 195 | result = np.concatenate((array, override_sub)) |
| 196 | assert_equal(result, expected.view(OverrideSub)) |
| 197 | |
| 198 | def test_no_wrapper(self): |
| 199 | # Regular numpy functions have wrappers, but do not presume |
nothing calls this directly
no test coverage detected