コード例 #1
0
ファイル: test_helpers.py プロジェクト: ahulist/chunky3d
 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)
コード例 #2
0
    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))
コード例 #3
0
 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)),
     )
コード例 #4
0
 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)),
     )
コード例 #5
0
 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)),
     )
コード例 #6
0
 def test_out_of_bound(self):
     with self.assertRaises(IndexError):
         slice_normalize(self[3], (3, ))
コード例 #7
0
 def test_wraparound(self):
     self.assertEqual(slice_normalize(-3, (10, )), (slice(7, 8, 1), ))
コード例 #8
0
 def test_ellipse_error(self):
     with self.assertRaises(IndexError):
         slice_normalize(self[..., ...], (1, 2, 3))
コード例 #9
0
    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))
コード例 #10
0
 def test_simple(self):
     self.assertEqual(slice_normalize(self[1, 2], (2, 3)),
                      (slice(1, 2, 1), slice(2, 3, 1)))