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

Method test_opt_out

numpy/lib/tests/test_mixins.py:122–148  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

120 _assert_equal_type_and_value(array, ArrayLike(np.array([1])))
121
122 def test_opt_out(self):
123
124 class OptOut:
125 """Object that opts out of __array_ufunc__."""
126 __array_ufunc__ = None
127
128 def __add__(self, other):
129 return self
130
131 def __radd__(self, other):
132 return self
133
134 array_like = ArrayLike(1)
135 opt_out = OptOut()
136
137 # supported operations
138 assert_(array_like + opt_out is opt_out)
139 assert_(opt_out + array_like is opt_out)
140
141 # not supported
142 with assert_raises(TypeError):
143 # don't use the Python default, array_like = array_like + opt_out
144 array_like += opt_out
145 with assert_raises(TypeError):
146 array_like - opt_out
147 with assert_raises(TypeError):
148 opt_out - array_like
149
150 def test_subclass(self):
151

Callers

nothing calls this directly

Calls 4

assert_Function · 0.90
assert_raisesFunction · 0.90
ArrayLikeClass · 0.70
OptOutClass · 0.70

Tested by

no test coverage detected