예제 #1
0
def check_ndarray_int(array, no_exception=False):
    """Return only if the array is of type numpy.ndarray, with int dtype.
    If not, raise a mureilexception.ArrayDataTypeException
    If no_exception is True, don't raise the exception, but return False.
    """
    
    if type(array) is not numpy.ndarray:
        if no_exception:
            return False
        else:
            msg = ('Expected array to be numpy array, but found ' + array.dtype.name + 
                ' in ' + mureilexception.find_caller(1))
            raise mureilexception.ArrayDataTypeException(msg, {})
    
    if not(array.dtype.name.startswith('int')):
        if no_exception:
            return False
        else:
            msg = ('Expected array to be int dtype, but found ' + array.dtype.name + 
                ' in ' + mureilexception.find_caller(1))
            raise mureilexception.ArrayDataTypeException(msg, {})

    return True
예제 #2
0
def check_subclass(class_instance, baseclass):
    """Check if the class instance provided is a subclass of the 
    base class provided. 
    
    Inputs:
        class_instance: a constructed class object
        baseclass: a class object

    Ouputs:
        None. Raises ClassTypeException if it fails.
    """

    if not issubclass(class_instance.__class__, baseclass):
        msg = ('in ' + mureilexception.find_caller(1) + ' ' + 
            class_instance.__class__.__name__ + 
            ' does not implement ' + baseclass.__name__)
        logging.critical(msg)
        raise(mureilexception.ClassTypeException(msg,  
            class_instance.__class__.__name__, baseclass.__name__, {}))