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

Function test_function_like

numpy/core/tests/test_overrides.py:709–738  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

707
708
709def test_function_like():
710 # We provide a `__get__` implementation, make sure it works
711 assert type(np.mean) is np.core._multiarray_umath._ArrayFunctionDispatcher
712
713 class MyClass:
714 def __array__(self):
715 # valid argument to mean:
716 return np.arange(3)
717
718 func1 = staticmethod(np.mean)
719 func2 = np.mean
720 func3 = classmethod(np.mean)
721
722 m = MyClass()
723 assert m.func1([10]) == 10
724 assert m.func2() == 1 # mean of the arange
725 with pytest.raises(TypeError, match="unsupported operand type"):
726 # Tries to operate on the class
727 m.func3()
728
729 # Manual binding also works (the above may shortcut):
730 bound = np.mean.__get__(m, MyClass)
731 assert bound() == 1
732
733 bound = np.mean.__get__(None, MyClass) # unbound actually
734 assert bound([10]) == 10
735
736 bound = np.mean.__get__(MyClass) # classmethod
737 with pytest.raises(TypeError, match="unsupported operand type"):
738 bound()
739
740
741def test_scipy_trapz_support_shim():

Callers

nothing calls this directly

Calls 2

__get__Method · 0.80
MyClassClass · 0.70

Tested by

no test coverage detected