diff options
| author | Stephan Hoyer <shoyer@google.com> | 2019-05-25 16:18:59 -0700 |
|---|---|---|
| committer | Stephan Hoyer <shoyer@google.com> | 2019-05-25 16:18:59 -0700 |
| commit | 37df5e641f19d9e5221cb519532b6cc5647ebe53 (patch) | |
| tree | abbfe6d2770de60c3faa55e3b42729fcf6bf8c42 /numpy | |
| parent | 766281d1bef8845407855ddf48e3d6b50668e7b7 (diff) | |
| download | numpy-37df5e641f19d9e5221cb519532b6cc5647ebe53.tar.gz | |
Tests for NUMPY_EXPERIMENTAL_ARRAY_FUNCTION=0
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/overrides.py | 11 | ||||
| -rw-r--r-- | numpy/core/tests/test_overrides.py | 17 |
2 files changed, 17 insertions, 11 deletions
diff --git a/numpy/core/overrides.py b/numpy/core/overrides.py index 347e71bd4..13688e0a7 100644 --- a/numpy/core/overrides.py +++ b/numpy/core/overrides.py @@ -146,16 +146,9 @@ def array_function_dispatch(dispatcher, module=None, verify=True, def decorator(implementation): if docs_from_dispatcher: add_docstring(implementation, dispatcher.__doc__) - - public_api = implementation - if module is not None: - public_api.__module__ = module - - public_api._implementation = implementation - - return public_api - + implementation.__module__ = module + return implementation return decorator def decorator(implementation): diff --git a/numpy/core/tests/test_overrides.py b/numpy/core/tests/test_overrides.py index 8b87fba13..dc8bf0613 100644 --- a/numpy/core/tests/test_overrides.py +++ b/numpy/core/tests/test_overrides.py @@ -9,8 +9,14 @@ from numpy.testing import ( assert_, assert_equal, assert_raises, assert_raises_regex) from numpy.core.overrides import ( _get_implementing_args, array_function_dispatch, - verify_matching_signatures) + verify_matching_signatures, ENABLE_ARRAY_FUNCTION) from numpy.compat import pickle +import pytest + + +requires_array_function = pytest.mark.skipif( + not ENABLE_ARRAY_FUNCTION, + reason="__array_function__ dispatch not enabled.") def _return_not_implemented(self, *args, **kwargs): @@ -143,6 +149,7 @@ class TestGetImplementingArgs(object): class TestNDArrayArrayFunction(object): + @requires_array_function def test_method(self): class Other(object): @@ -195,12 +202,13 @@ class TestNDArrayArrayFunction(object): # __array_function__ with invalid arguments, but check that we raise # an appropriate error all the same. array = np.array(1) - func = dispatched_one_arg._implementation + func = lambda x: x with assert_raises_regex(AttributeError, '_implementation'): array.__array_function__(func=func, types=(np.ndarray,), args=(array,), kwargs={}) +@requires_array_function class TestArrayFunctionDispatch(object): def test_pickle(self): @@ -240,6 +248,7 @@ class TestArrayFunctionDispatch(object): dispatched_one_arg(array) +@requires_array_function class TestVerifyMatchingSignatures(object): def test_verify_matching_signatures(self): @@ -292,6 +301,7 @@ def _new_duck_type_and_implements(): return (MyArray, implements) +@requires_array_function class TestArrayFunctionImplementation(object): def test_one_arg(self): @@ -372,6 +382,7 @@ class TestNumPyFunctions(object): signature = inspect.signature(np.sum) assert_('axis' in signature.parameters) + @requires_array_function def test_override_sum(self): MyArray, implements = _new_duck_type_and_implements() @@ -381,6 +392,7 @@ class TestNumPyFunctions(object): assert_equal(np.sum(MyArray()), 'yes') + @requires_array_function def test_sum_on_mock_array(self): # We need a proxy for mocks because __array_function__ is only looked @@ -401,6 +413,7 @@ class TestNumPyFunctions(object): np.sum, (ArrayProxy,), (proxy,), {}) proxy.value.__array__.assert_not_called() + @requires_array_function def test_sum_forwarding_implementation(self): class MyArray(np.ndarray): |
