# Path: ccdproc/utils/slices.py
# def slice_from_string(string, fits_convention=False):
#     """
#     Convert a string to a tuple of slices.
# 
#     Parameters
#     ----------
# 
#     string : str
#         A string that can be converted to a slice.
# 
#     fits_convention : bool, optional
#         If True, assume the input string follows the FITS convention for
#         indexing: the indexing is one-based (not zero-based) and the first
#         axis is that which changes most rapidly as the index increases.
# 
#     Returns
#     -------
# 
#     slice_tuple : tuple of slice objects
#         A tuple able to be used to index a numpy.array
# 
#     Notes
#     -----
# 
#     The ``string`` argument can be anything that would work as a valid way to
#     slice an array in Numpy. It must be enclosed in matching brackets; all
#     spaces are stripped from the string before processing.
# 
#     Examples
#     --------
# 
#     >>> import numpy as np
#     >>> arr1d = np.arange(5)
#     >>> a_slice = slice_from_string('[2:5]')
#     >>> arr1d[a_slice]
#     array([2, 3, 4])
#     >>> a_slice = slice_from_string('[ : : -2] ')
#     >>> arr1d[a_slice]
#     array([4, 2, 0])
#     >>> arr2d = np.array([arr1d, arr1d + 5, arr1d + 10])
#     >>> arr2d
#     array([[ 0,  1,  2,  3,  4],
#            [ 5,  6,  7,  8,  9],
#            [10, 11, 12, 13, 14]])
#     >>> a_slice = slice_from_string('[1:-1, 0:4:2]')
#     >>> arr2d[a_slice]
#     array([[5, 7]])
#     >>> a_slice = slice_from_string('[0:2,0:3]')
#     >>> arr2d[a_slice]
#     array([[0, 1, 2],
#            [5, 6, 7]])
#     """
#     no_space = string.replace(' ', '')
# 
#     if not no_space:
#         return ()
# 
#     if not (no_space.startswith('[') and no_space.endswith(']')):
#         raise ValueError('Slice string must be enclosed in square brackets.')
# 
#     no_space = no_space.strip('[]')
#     if fits_convention:
#         # Special cases first
#         # Flip dimension, with step
#         no_space = no_space.replace('-*:', '::-')
#         # Flip dimension
#         no_space = no_space.replace('-*', '::-1')
#         # Normal wildcard
#         no_space = no_space.replace('*', ':')
#     string_slices = no_space.split(',')
#     slices = []
#     for string_slice in string_slices:
#         slice_args = [int(arg) if arg else None
#                       for arg in string_slice.split(':')]
#         a_slice = slice(*slice_args)
#         slices.append(a_slice)
# 
#     if fits_convention:
#         slices = _defitsify_slice(slices)
# 
#     return tuple(slices)


import numpy as np
import pytest
from ..slices import slice_from_string
# Licensed under a 3-clause BSD style license - see LICENSE.rst





# none of these are properly enclosed in brackets; is an error raised?
@pytest.mark.parametrize('arg',
                         ['1:2', '[1:2', '1:2]'])
def test_slice_from_string_needs_enclosing_brackets(arg):
    with pytest.raises(ValueError):

# Path: ccdproc/utils/slices.py
# def slice_from_string(string, fits_convention=False):
#     """
#     Convert a string to a tuple of slices.
# 
#     Parameters
#     ----------
# 
#     string : str
#         A string that can be converted to a slice.
# 
#     fits_convention : bool, optional
#         If True, assume the input string follows the FITS convention for
#         indexing: the indexing is one-based (not zero-based) and the first
#         axis is that which changes most rapidly as the index increases.
# 
#     Returns
#     -------
# 
#     slice_tuple : tuple of slice objects
#         A tuple able to be used to index a numpy.array
# 
#     Notes
#     -----
# 
#     The ``string`` argument can be anything that would work as a valid way to
#     slice an array in Numpy. It must be enclosed in matching brackets; all
#     spaces are stripped from the string before processing.
# 
#     Examples
#     --------
# 
#     >>> import numpy as np
#     >>> arr1d = np.arange(5)
#     >>> a_slice = slice_from_string('[2:5]')
#     >>> arr1d[a_slice]
#     array([2, 3, 4])
#     >>> a_slice = slice_from_string('[ : : -2] ')
#     >>> arr1d[a_slice]
#     array([4, 2, 0])
#     >>> arr2d = np.array([arr1d, arr1d + 5, arr1d + 10])
#     >>> arr2d
#     array([[ 0,  1,  2,  3,  4],
#            [ 5,  6,  7,  8,  9],
#            [10, 11, 12, 13, 14]])
#     >>> a_slice = slice_from_string('[1:-1, 0:4:2]')
#     >>> arr2d[a_slice]
#     array([[5, 7]])
#     >>> a_slice = slice_from_string('[0:2,0:3]')
#     >>> arr2d[a_slice]
#     array([[0, 1, 2],
#            [5, 6, 7]])
#     """
#     no_space = string.replace(' ', '')
# 
#     if not no_space:
#         return ()
# 
#     if not (no_space.startswith('[') and no_space.endswith(']')):
#         raise ValueError('Slice string must be enclosed in square brackets.')
# 
#     no_space = no_space.strip('[]')
#     if fits_convention:
#         # Special cases first
#         # Flip dimension, with step
#         no_space = no_space.replace('-*:', '::-')
#         # Flip dimension
#         no_space = no_space.replace('-*', '::-1')
#         # Normal wildcard
#         no_space = no_space.replace('*', ':')
#     string_slices = no_space.split(',')
#     slices = []
#     for string_slice in string_slices:
#         slice_args = [int(arg) if arg else None
#                       for arg in string_slice.split(':')]
#         a_slice = slice(*slice_args)
#         slices.append(a_slice)
# 
#     if fits_convention:
#         slices = _defitsify_slice(slices)
# 
#     return tuple(slices)


# Path: ccdproc/utils/tests/test_slices.py
import numpy as np
import pytest
from ..slices import slice_from_string

# Licensed under a 3-clause BSD style license - see LICENSE.rst





# none of these are properly enclosed in brackets; is an error raised?
@pytest.mark.parametrize('arg',
                         ['1:2', '[1:2', '1:2]'])
def test_slice_from_string_needs_enclosing_brackets(arg):
    with pytest.raises(ValueError):

        slice_from_string(arg)