def test_shape_extension(self): self.assertEqual(slice_normalize(self[0, 0, ...], (2, 2, 2)), (slice(0, 1, 1), slice(0, 1, 1), slice(0, 2, 1))) self.assertEqual(slice_normalize(self[0, 0], (2, 2, 2)), (slice(0, 1, 1), slice(0, 1, 1), slice(0, 2, 1))) self.assertEqual(slice_normalize(self[0, 0, 0, ...], (2, 2, 2)), (slice(0, 1, 1), ) * 3) self.assertEqual(slice_normalize(self[...], (2, 2, 2)), (slice(0, 2, 1), ) * 3) self.assertEqual(slice_normalize(self[:], (2, 2, 2)), (slice(0, 2, 1), ) * 3)
def test_bad_slice_type(self): # slices with self.assertRaises(IndexError): slice_normalize(self["a":"b"], (1, 2, 3)) with self.assertRaises(IndexError): slice_normalize(self[0:1:"b"], (1, 2, 3)) # lone indices with self.assertRaises(IndexError): slice_normalize(self[None], (1, 2, 3)) with self.assertRaises(IndexError): slice_normalize(self["hello"], (1, 2, 3)) # no exceptions: slice_normalize(self[0:None], (1, 2, 3))
def test_unsigned_shape(self): self.assertEqual( slice_normalize(self[1], tuple(np.array([2, 3, 4], dtype=np.uint16))), (slice(1, 2, 1), slice(0, 3, 1), slice(0, 4, 1)), )
def test_backward_slice(self): self.assertEqual( slice_normalize(self[::-1], (3, 3, 3)), (slice(2, -1, -1), slice(0, 3, 1), slice(0, 3, 1)), )
def test_step_prefix(self): self.assertEqual( slice_normalize(self[::2], (3, 3, 3)), (slice(0, 3, 2), slice(0, 3, 1), slice(0, 3, 1)), )
def test_out_of_bound(self): with self.assertRaises(IndexError): slice_normalize(self[3], (3, ))
def test_wraparound(self): self.assertEqual(slice_normalize(-3, (10, )), (slice(7, 8, 1), ))
def test_ellipse_error(self): with self.assertRaises(IndexError): slice_normalize(self[..., ...], (1, 2, 3))
def test_overindexing(self): with self.assertRaises(IndexError): slice_normalize(self[1, 2, 3, 4], (1, 2, 3)) # ellipsis doesn't overindex slice_normalize(self[0, 1, 2, ...], (1, 2, 3))
def test_simple(self): self.assertEqual(slice_normalize(self[1, 2], (2, 3)), (slice(1, 2, 1), slice(2, 3, 1)))