# Path: vip_hci/config/mem.py
# def check_enough_memory(input_bytes, factor=1, raise_error=True, error_msg='',
#                         verbose=True):
#     """
#     Check if ``input_bytes`` are larger than system's available memory times
#     ``factor``. This function is used to check the inputs (largest ones such as
#     multi-dimensional cubes) of algorithms and avoid system/Python crashes or
#     heavy swapping.
# 
#     Parameters
#     ----------
#     input_bytes : float
#         The size in bytes of the inputs of a given function.
#     factor : float, optional
#         Scales how much memory is needed in terms of the size of input_bytes.
#     raise_error : bool, optional
#         If True, a RuntimeError is raised when the condition is not met.
#     error_msg : str, optional
#         [raise_error=True] To be appended to the message of the RuntimeError.
#     verbose : bool, optional
#         If True, information about the available memory is printed out.
# 
#     """
#     available_memory = get_available_memory(verbose=verbose)
#     if input_bytes > factor * available_memory:
#         if raise_error:
#             raise RuntimeError('Input is larger than available system memory' +
#                                error_msg)
#         return False
#     else:
#         return True
# 
# Path: vip_hci/config/utils_conf.py
# def check_array(input_array, dim, msg=None):
#     """ Checks the dimensionality of input. In case the check is not successful,
#     a TypeError is raised.
# 
#     Parameters
#     ----------
#     input_array : list, tuple or np.ndarray
#         Input data.
#     dim : int or tuple
#         Number of dimensions that ``input_array`` should have. ``dim`` can take
#         one of these values: 1, 2, 3, 4, (1,2), (2,3), (3,4) or (2,3,4).
#     msg : str, optional
#         String to be used in the error message (``input_array`` name).
# 
#     """
#     if not isinstance(input_array, (list, tuple, np.ndarray)):
#         raise TypeError("`input_array` must be a list, tuple of numpy ndarray")
# 
#     if msg is None:
#         msg = 'Input array'
#     else:
#         msg = '`' + msg + '`'
# 
#     error_msg = "`dim` must be: 1, 2, 3, 4, (1,2), (2,3), (3,4) or (2,3,4)"
#     if isinstance(dim, int):
#         if dim < 1 or dim > 4:
#             raise ValueError(error_msg)
#     elif isinstance(dim, tuple):
#         if dim not in ((1,2), (2,3), (3,4), (2,3,4)):
#             raise ValueError(error_msg)
# 
#     msg2 = ' must be a '
#     msg3 = 'd numpy ndarray'
# 
#     if dim == 1:
#         if isinstance(input_array, (list, tuple)):
#             input_array = np.array(input_array)
#         if not isinstance(input_array, np.ndarray):
#             raise TypeError(msg + msg2 + 'list, tuple or a 1' + msg3)
#         if not input_array.ndim == dim:
#             raise TypeError(msg + msg2 + 'list, tuple or a 1' + msg3)
# 
#     elif dim in (2, 3, 4):
#         if not isinstance(input_array, np.ndarray):
#             raise TypeError(msg + msg2 + str(dim) + msg3)
#         else:
#             if not input_array.ndim == dim:
#                 raise TypeError(msg + msg2 + str(dim) + msg3)
# 
#     elif isinstance(dim, tuple):
#         if dim == (1, 2):
#             msg_tup = '1 or 2'
#         elif dim == (2, 3):
#             msg_tup = '2 or 3'
#         elif dim == (3, 4):
#             msg_tup = '3 or 4'
#         elif dim == (2, 3, 4):
#             msg_tup = '2, 3 or 4'
# 
#         if isinstance(input_array, np.ndarray):
#             if input_array.ndim not in dim:
#                 raise TypeError(msg + msg2 + msg_tup + msg3)
#         else:
#             raise TypeError(msg + msg2 + msg_tup + msg3)


import numpy as np
from vip_hci.config.mem import check_enough_memory
from vip_hci.config.utils_conf import check_array
"""
Tests for the conf submodule.
"""



def test_check_enough_memory():
    assert check_enough_memory(0, factor=1, raise_error=False) is True

    assert check_enough_memory(1e13, factor=1, raise_error=False) is False


def test_check_array():
    a1 = np.zeros((1))
    a2 = np.zeros((1, 1))
    a3 = np.zeros((1, 1, 1))
    a4 = np.zeros((1, 1, 1, 1))

    try:

# Path: vip_hci/config/mem.py
# def check_enough_memory(input_bytes, factor=1, raise_error=True, error_msg='',
#                         verbose=True):
#     """
#     Check if ``input_bytes`` are larger than system's available memory times
#     ``factor``. This function is used to check the inputs (largest ones such as
#     multi-dimensional cubes) of algorithms and avoid system/Python crashes or
#     heavy swapping.
# 
#     Parameters
#     ----------
#     input_bytes : float
#         The size in bytes of the inputs of a given function.
#     factor : float, optional
#         Scales how much memory is needed in terms of the size of input_bytes.
#     raise_error : bool, optional
#         If True, a RuntimeError is raised when the condition is not met.
#     error_msg : str, optional
#         [raise_error=True] To be appended to the message of the RuntimeError.
#     verbose : bool, optional
#         If True, information about the available memory is printed out.
# 
#     """
#     available_memory = get_available_memory(verbose=verbose)
#     if input_bytes > factor * available_memory:
#         if raise_error:
#             raise RuntimeError('Input is larger than available system memory' +
#                                error_msg)
#         return False
#     else:
#         return True
# 
# Path: vip_hci/config/utils_conf.py
# def check_array(input_array, dim, msg=None):
#     """ Checks the dimensionality of input. In case the check is not successful,
#     a TypeError is raised.
# 
#     Parameters
#     ----------
#     input_array : list, tuple or np.ndarray
#         Input data.
#     dim : int or tuple
#         Number of dimensions that ``input_array`` should have. ``dim`` can take
#         one of these values: 1, 2, 3, 4, (1,2), (2,3), (3,4) or (2,3,4).
#     msg : str, optional
#         String to be used in the error message (``input_array`` name).
# 
#     """
#     if not isinstance(input_array, (list, tuple, np.ndarray)):
#         raise TypeError("`input_array` must be a list, tuple of numpy ndarray")
# 
#     if msg is None:
#         msg = 'Input array'
#     else:
#         msg = '`' + msg + '`'
# 
#     error_msg = "`dim` must be: 1, 2, 3, 4, (1,2), (2,3), (3,4) or (2,3,4)"
#     if isinstance(dim, int):
#         if dim < 1 or dim > 4:
#             raise ValueError(error_msg)
#     elif isinstance(dim, tuple):
#         if dim not in ((1,2), (2,3), (3,4), (2,3,4)):
#             raise ValueError(error_msg)
# 
#     msg2 = ' must be a '
#     msg3 = 'd numpy ndarray'
# 
#     if dim == 1:
#         if isinstance(input_array, (list, tuple)):
#             input_array = np.array(input_array)
#         if not isinstance(input_array, np.ndarray):
#             raise TypeError(msg + msg2 + 'list, tuple or a 1' + msg3)
#         if not input_array.ndim == dim:
#             raise TypeError(msg + msg2 + 'list, tuple or a 1' + msg3)
# 
#     elif dim in (2, 3, 4):
#         if not isinstance(input_array, np.ndarray):
#             raise TypeError(msg + msg2 + str(dim) + msg3)
#         else:
#             if not input_array.ndim == dim:
#                 raise TypeError(msg + msg2 + str(dim) + msg3)
# 
#     elif isinstance(dim, tuple):
#         if dim == (1, 2):
#             msg_tup = '1 or 2'
#         elif dim == (2, 3):
#             msg_tup = '2 or 3'
#         elif dim == (3, 4):
#             msg_tup = '3 or 4'
#         elif dim == (2, 3, 4):
#             msg_tup = '2, 3 or 4'
# 
#         if isinstance(input_array, np.ndarray):
#             if input_array.ndim not in dim:
#                 raise TypeError(msg + msg2 + msg_tup + msg3)
#         else:
#             raise TypeError(msg + msg2 + msg_tup + msg3)


# Path: tests/test_conf.py
import numpy as np
from vip_hci.config.mem import check_enough_memory
from vip_hci.config.utils_conf import check_array

"""
Tests for the conf submodule.
"""



def test_check_enough_memory():
    assert check_enough_memory(0, factor=1, raise_error=False) is True

    assert check_enough_memory(1e13, factor=1, raise_error=False) is False


def test_check_array():
    a1 = np.zeros((1))
    a2 = np.zeros((1, 1))
    a3 = np.zeros((1, 1, 1))
    a4 = np.zeros((1, 1, 1, 1))

    try:

        check_array([2, 3], dim=1)