diff options
author | Mark Harfouche <mark.harfouche@gmail.com> | 2023-01-27 09:58:54 -0500 |
---|---|---|
committer | Mark Harfouche <mark.harfouche@gmail.com> | 2023-01-27 12:01:36 -0500 |
commit | a38eb6d9bb5990b70e042c19f2d6daa51d784d6c (patch) | |
tree | 88fa3a3a97f13c54d9310eb8be7388fe403f2740 /numpy/ma/tests/test_subclassing.py | |
parent | 35c41afd61540c27af5004d480618b59355d02f8 (diff) | |
download | numpy-a38eb6d9bb5990b70e042c19f2d6daa51d784d6c.tar.gz |
TST: Add a test for slots and NDArrayOperatorsMixin subclassing
Diffstat (limited to 'numpy/ma/tests/test_subclassing.py')
-rw-r--r-- | numpy/ma/tests/test_subclassing.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/numpy/ma/tests/test_subclassing.py b/numpy/ma/tests/test_subclassing.py index 64c66eeb9..e3c885253 100644 --- a/numpy/ma/tests/test_subclassing.py +++ b/numpy/ma/tests/test_subclassing.py @@ -154,6 +154,7 @@ class WrappedArray(NDArrayOperatorsMixin): ufunc deferrals are commutative. See: https://github.com/numpy/numpy/issues/15200) """ + __slots__ = ('_array', 'attrs') __array_priority__ = 20 def __init__(self, array, **attrs): @@ -448,3 +449,12 @@ class TestClassWrapping: assert_(isinstance(np.divide(wm, m2), WrappedArray)) assert_(isinstance(np.divide(m2, wm), WrappedArray)) assert_equal(np.divide(m2, wm), np.divide(wm, m2)) + + def test_mixins_have_slots(self): + mixin = NDArrayOperatorsMixin() + # Should raise an error + assert_raises(AttributeError, mixin.__setattr__, "not_a_real_attr", 1) + + m = np.ma.masked_array([1, 3, 5], mask=[False, True, False]) + wm = WrappedArray(m) + assert_raises(AttributeError, wm.__setattr__, "not_an_attr", 2) |