Example #1
0
    def test_is_valid_constraint_passes(self):
        sl = 1
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = [0,1,2]
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = (0,1,2)
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = slice(None,None,None)
        self.assertTrue(utils.is_valid_constraint(sl))
Example #2
0
    def test_is_valid_constraint_passes(self):
        sl = 1
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = [0,1,2]
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = (0,1,2)
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = slice(None,None,None)
        self.assertTrue(utils.is_valid_constraint(sl))
Example #3
0
    def test_is_valid_constraint_nested_passes(self):
        sl = [[1,2,3]]
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = ((1,2,3))
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = [slice(1,2,3),slice(None,None,None)]
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = [slice(1,2,3), 2, 3]
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = [1, slice(2,3,4), [1,3,5]]
        self.assertTrue(utils.is_valid_constraint(sl))
Example #4
0
    def test_is_valid_constraint_nested_passes(self):
        sl = [[1,2,3]]
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = ((1,2,3))
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = [slice(1,2,3),slice(None,None,None)]
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = [slice(1,2,3), 2, 3]
        self.assertTrue(utils.is_valid_constraint(sl))

        sl = [1, slice(2,3,4), [1,3,5]]
        self.assertTrue(utils.is_valid_constraint(sl))
    def __init__(self, slices, topoDim=None):
        if slices is None:
            raise StandardError('\'slices\' cannot be None')
        self.topoDim = topoDim or 0

        if is_valid_constraint(slices):
            if not np.iterable(slices):
                slices = [slices]

            self.slices = slices
        else:
            raise StandardError('\'slices\' must be either single, tuple, or list of slice or int objects')
Example #6
0
    def __init__(self, slices, topoDim=None):
        if slices is None:
            raise StandardError('\'slices\' cannot be None')
        self.topoDim = topoDim or 0

        if is_valid_constraint(slices):
            if not np.iterable(slices):
                slices = [slices]

            self.slices = slices
        else:
            raise StandardError(
                '\'slices\' must be either single, tuple, or list of slice or int objects'
            )
Example #7
0
    def test_is_valid_constraint_nested_fails(self):
        sl = ['bob', 1, 4]
        self.assertFalse(utils.is_valid_constraint(sl))

        sl = [1, slice(2,3,4), 10.4]
        self.assertFalse(utils.is_valid_constraint(sl))
Example #8
0
    def test_is_valid_constraint_fails(self):
        sl = 'bob'
        self.assertFalse(utils.is_valid_constraint(sl))

        sl = 43.2
        self.assertFalse(utils.is_valid_constraint(sl))
Example #9
0
    def test_is_valid_constraint_nested_fails(self):
        sl = ['bob', 1, 4]
        self.assertFalse(utils.is_valid_constraint(sl))

        sl = [1, slice(2,3,4), 10.4]
        self.assertFalse(utils.is_valid_constraint(sl))
Example #10
0
    def test_is_valid_constraint_fails(self):
        sl = 'bob'
        self.assertFalse(utils.is_valid_constraint(sl))

        sl = 43.2
        self.assertFalse(utils.is_valid_constraint(sl))