MCPcopy
hub / github.com/numpy/numpy / test_treatment_of_NotImplemented

Method test_treatment_of_NotImplemented

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

Source from the content-addressed store, hash-verified

2701 assert_(not isinstance(test.mask, MaskedArray))
2702
2703 def test_treatment_of_NotImplemented(self):
2704 # Check that NotImplemented is returned at appropriate places
2705
2706 a = masked_array([1., 2.], mask=[1, 0])
2707 assert_raises(TypeError, operator.mul, a, "abc")
2708 assert_raises(TypeError, operator.truediv, a, "abc")
2709
2710 class MyClass:
2711 __array_priority__ = a.__array_priority__ + 1
2712
2713 def __mul__(self, other):
2714 return "My mul"
2715
2716 def __rmul__(self, other):
2717 return "My rmul"
2718
2719 me = MyClass()
2720 assert_(me * a == "My mul")
2721 assert_(a * me == "My rmul")
2722
2723 # and that __array_priority__ is respected
2724 class MyClass2:
2725 __array_priority__ = 100
2726
2727 def __mul__(self, other):
2728 return "Me2mul"
2729
2730 def __rmul__(self, other):
2731 return "Me2rmul"
2732
2733 def __rtruediv__(self, other):
2734 return "Me2rdiv"
2735
2736 me_too = MyClass2()
2737 assert_(a.__mul__(me_too) is NotImplemented)
2738 assert_(all(multiply.outer(a, me_too) == "Me2rmul"))
2739 assert_(a.__truediv__(me_too) is NotImplemented)
2740 assert_(me_too * a == "Me2mul")
2741 assert_(a * me_too == "Me2rmul")
2742 assert_(a / me_too == "Me2rdiv")
2743
2744 def test_no_masked_nan_warnings(self):
2745 # check that a nan in masked position does not

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected