MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_ndarray_exceptions

Method test_ndarray_exceptions

Lib/test/test_buffer.py:1138–1294  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1136 self.assertTrue(is_contiguous(nd, 'C'))
1137
1138 def test_ndarray_exceptions(self):
1139 nd = ndarray([9], [1])
1140 ndm = ndarray([9], [1], flags=ND_VAREXPORT)
1141
1142 # Initialization of a new ndarray or mutation of an existing array.
1143 for c in (ndarray, nd.push, ndm.push):
1144 # Invalid types.
1145 self.assertRaises(TypeError, c, {1,2,3})
1146 self.assertRaises(TypeError, c, [1,2,'3'])
1147 self.assertRaises(TypeError, c, [1,2,(3,4)])
1148 self.assertRaises(TypeError, c, [1,2,3], shape={3})
1149 self.assertRaises(TypeError, c, [1,2,3], shape=[3], strides={1})
1150 self.assertRaises(TypeError, c, [1,2,3], shape=[3], offset=[])
1151 self.assertRaises(TypeError, c, [1], shape=[1], format={})
1152 self.assertRaises(TypeError, c, [1], shape=[1], flags={})
1153 self.assertRaises(TypeError, c, [1], shape=[1], getbuf={})
1154
1155 # ND_FORTRAN flag is only valid without strides.
1156 self.assertRaises(TypeError, c, [1], shape=[1], strides=[1],
1157 flags=ND_FORTRAN)
1158
1159 # ND_PIL flag is only valid with ndim > 0.
1160 self.assertRaises(TypeError, c, [1], shape=[], flags=ND_PIL)
1161
1162 # Invalid items.
1163 self.assertRaises(ValueError, c, [], shape=[1])
1164 self.assertRaises(ValueError, c, ['XXX'], shape=[1], format="L")
1165 # Invalid combination of items and format.
1166 self.assertRaises(struct.error, c, [1000], shape=[1], format="B")
1167 self.assertRaises(ValueError, c, [1,(2,3)], shape=[2], format="B")
1168 self.assertRaises(ValueError, c, [1,2,3], shape=[3], format="QL")
1169
1170 # Invalid ndim.
1171 n = ND_MAX_NDIM+1
1172 self.assertRaises(ValueError, c, [1]*n, shape=[1]*n)
1173
1174 # Invalid shape.
1175 self.assertRaises(ValueError, c, [1], shape=[-1])
1176 self.assertRaises(ValueError, c, [1,2,3], shape=['3'])
1177 self.assertRaises(OverflowError, c, [1], shape=[2**128])
1178 # prod(shape) * itemsize != len(items)
1179 self.assertRaises(ValueError, c, [1,2,3,4,5], shape=[2,2], offset=3)
1180
1181 # Invalid strides.
1182 self.assertRaises(ValueError, c, [1,2,3], shape=[3], strides=['1'])
1183 self.assertRaises(OverflowError, c, [1], shape=[1],
1184 strides=[2**128])
1185
1186 # Invalid combination of strides and shape.
1187 self.assertRaises(ValueError, c, [1,2], shape=[2,1], strides=[1])
1188 # Invalid combination of strides and format.
1189 self.assertRaises(ValueError, c, [1,2,3,4], shape=[2], strides=[3],
1190 format="L")
1191
1192 # Invalid offset.
1193 self.assertRaises(ValueError, c, [1,2,3], shape=[3], offset=4)
1194 self.assertRaises(ValueError, c, [1,2,3], shape=[1], offset=3,
1195 format="L")

Callers

nothing calls this directly

Calls 5

listClass · 0.85
assertRaisesMethod · 0.45
pushMethod · 0.45
releaseMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected