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

Method test_sum_on_mock_array

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

assert_equalFunction · 0.90
ArrayProxyClass · 0.85
sumMethod · 0.45

Tested by

no test coverage detected