| 5083 | assert actual.__class__.__name__ == 'foo' |
| 5084 | |
| 5085 | def test_outer_bad_subclass(): |
| 5086 | class BadArr1(np.ndarray): |
| 5087 | def __array_finalize__(self, obj): |
| 5088 | # The outer call reshapes to 3 dims, try to do a bad reshape. |
| 5089 | if self.ndim == 3: |
| 5090 | self._set_shape(self.shape + (1,)) |
| 5091 | |
| 5092 | class BadArr2(np.ndarray): |
| 5093 | def __array_finalize__(self, obj): |
| 5094 | if isinstance(obj, BadArr2): |
| 5095 | # outer inserts 1-sized dims. In that case disturb them. |
| 5096 | if self.shape[-1] == 1: |
| 5097 | self._set_shape(self.shape[::-1]) |
| 5098 | |
| 5099 | for cls in [BadArr1, BadArr2]: |
| 5100 | arr = np.ones((2, 3)).view(cls) |
| 5101 | with pytest.raises(TypeError): |
| 5102 | # The first array gets reshaped (not the second one) |
| 5103 | np.add.outer(arr, [1, 2]) |
| 5104 | |
| 5105 | # This actually works, since we only see the reshaping error: |
| 5106 | arr = np.ones((2, 3)).view(cls) |
| 5107 | assert type(np.add.outer([1, 2], arr)) is cls |
| 5108 | |
| 5109 | def test_outer_exceeds_maxdims(): |
| 5110 | deep = np.ones((1,) * 33) |