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

Method test_treatment_of_NotImplemented

numpy/ma/tests/test_core.py:2513–2554  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2511 assert_(not isinstance(test.mask, MaskedArray))
2512
2513 def test_treatment_of_NotImplemented(self):
2514 # Check that NotImplemented is returned at appropriate places
2515
2516 a = masked_array([1., 2.], mask=[1, 0])
2517 assert_raises(TypeError, operator.mul, a, "abc")
2518 assert_raises(TypeError, operator.truediv, a, "abc")
2519
2520 class MyClass:
2521 __array_priority__ = a.__array_priority__ + 1
2522
2523 def __mul__(self, other):
2524 return "My mul"
2525
2526 def __rmul__(self, other):
2527 return "My rmul"
2528
2529 me = MyClass()
2530 assert_(me * a == "My mul")
2531 assert_(a * me == "My rmul")
2532
2533 # and that __array_priority__ is respected
2534 class MyClass2:
2535 __array_priority__ = 100
2536
2537 def __mul__(self, other):
2538 return "Me2mul"
2539
2540 def __rmul__(self, other):
2541 return "Me2rmul"
2542
2543 def __rdiv__(self, other):
2544 return "Me2rdiv"
2545
2546 __rtruediv__ = __rdiv__
2547
2548 me_too = MyClass2()
2549 assert_(a.__mul__(me_too) is NotImplemented)
2550 assert_(all(multiply.outer(a, me_too) == "Me2rmul"))
2551 assert_(a.__truediv__(me_too) is NotImplemented)
2552 assert_(me_too * a == "Me2mul")
2553 assert_(a * me_too == "Me2rmul")
2554 assert_(a / me_too == "Me2rdiv")
2555
2556 def test_no_masked_nan_warnings(self):
2557 # check that a nan in masked position does not

Callers

nothing calls this directly

Calls 8

assert_raisesFunction · 0.90
allFunction · 0.90
MyClass2Class · 0.85
MyClassClass · 0.70
assert_Function · 0.50
__mul__Method · 0.45
outerMethod · 0.45
__truediv__Method · 0.45

Tested by

no test coverage detected