(self)
| 503 | assert_equal(np.sum(MyArray()), 'yes') |
| 504 | |
| 505 | def test_sum_on_mock_array(self): |
| 506 | |
| 507 | # We need a proxy for mocks because __array_function__ is only looked |
| 508 | # up in the class dict |
| 509 | class ArrayProxy: |
| 510 | def __init__(self, value): |
| 511 | self.value = value |
| 512 | def __array_function__(self, *args, **kwargs): |
| 513 | return self.value.__array_function__(*args, **kwargs) |
| 514 | def __array__(self, *args, **kwargs): |
| 515 | return self.value.__array__(*args, **kwargs) |
| 516 | |
| 517 | proxy = ArrayProxy(mock.Mock(spec=ArrayProxy)) |
| 518 | proxy.value.__array_function__.return_value = 1 |
| 519 | result = np.sum(proxy) |
| 520 | assert_equal(result, 1) |
| 521 | proxy.value.__array_function__.assert_called_once_with( |
| 522 | np.sum, (ArrayProxy,), (proxy,), {}) |
| 523 | proxy.value.__array__.assert_not_called() |
| 524 | |
| 525 | def test_sum_forwarding_implementation(self): |
| 526 |
nothing calls this directly
no test coverage detected