Skip to content

Commit

Permalink
TST: Add a test for slots and NDArrayOperatorsMixin subclassing
Browse files Browse the repository at this point in the history
  • Loading branch information
hmaarrfk committed Jan 27, 2023
1 parent 35c41af commit a38eb6d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions numpy/ma/tests/test_subclassing.py
Expand Up @@ -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):
Expand Down Expand Up @@ -448,3 +449,12 @@ def test_masked_binary_operations(self):
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)

0 comments on commit a38eb6d

Please sign in to comment.