diff options
author | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2013-10-12 16:06:14 -0400 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-10-12 19:06:00 -0600 |
commit | 1b283cf0eae908138daa34b5777784cac64cb115 (patch) | |
tree | 49039997bbb37e62dbd19f604aa005cfa2798891 | |
parent | 72bb6ad851f60ace43ea2470c942e015e4db3231 (diff) | |
download | numpy-1b283cf0eae908138daa34b5777784cac64cb115.tar.gz |
Add test cases to ensure NotImplemented is passed on
-rw-r--r-- | numpy/ma/tests/test_core.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index faca0c81a..deb269636 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -1631,6 +1631,26 @@ class TestUfuncs(TestCase): assert_equal(test.mask, control.mask) self.assertTrue(not isinstance(test.mask, MaskedArray)) + def test_treatment_of_NotImplemented(self): + "Check we return NotImplemented if ufunc cannot deal with other" + a = masked_array([1., 2.], mask=[1, 0]) + # basic test + assert a.__mul__('abc') == NotImplemented # _MaskedBinaryOperation + assert multiply.outer(a, 'abc') == NotImplemented + assert a.__div__('abc') == NotImplemented # _DomainedBinaryOperation + + # also check that rmul of another class can be accessed + class MyClass(str): + def __mul__(self, other): + return "My mul" + + def __rmul__(self, other): + return "My rmul" + + me = MyClass() + assert me * a == "My mul" + assert a * me == "My rmul" + #------------------------------------------------------------------------------ class TestMaskedArrayInPlaceArithmetics(TestCase): |