How to use the sciunit.errors.Error function in sciunit

To help you get started, we’ve selected a few sciunit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scidash / sciunit / sciunit / tests.py View on Github external
def check_capabilities(self, model, skip_incapable=False,
                           require_extra=False):
        """Check that test's required capabilities are implemented by `model`.

        Raises an Error if model is not a Model.
        Raises a CapabilityError if model does not have a capability.
        """
        if not isinstance(model, Model):
            raise Error("Model %s is not a sciunit.Model." % str(model))
        capable = all([self.check_capability(model, c, skip_incapable,
                                             require_extra)
                       for c in self.required_capabilities])
        return capable
github scidash / sciunit / sciunit / errors.py View on Github external
self.model = model
        self.method = method
        self.args = args

        super(PredictionError, self).__init__(
            ("During prediction, model '%s' could not successfully execute "
             "method '%s' with arguments %s") % (model.name, method, args))

    model = None
    """The model that does not have the capability."""

    argument = None
    """The argument that could not be handled."""


class InvalidScoreError(Error):
    """Error raised when a score is invalid."""
    pass


class BadParameterValueError(Error):
    """Error raised when a model parameter value is unreasonable."""
    def __init__(self, name, value):
        self.name = name
        self.value = value

        super(BadParameterValueError, self).__init__(
            "Parameter %s has unreasonable value of %s" % (name, value))
github scidash / sciunit / sciunit / errors.py View on Github external
("During prediction, model '%s' could not successfully execute "
             "method '%s' with arguments %s") % (model.name, method, args))

    model = None
    """The model that does not have the capability."""

    argument = None
    """The argument that could not be handled."""


class InvalidScoreError(Error):
    """Error raised when a score is invalid."""
    pass


class BadParameterValueError(Error):
    """Error raised when a model parameter value is unreasonable."""
    def __init__(self, name, value):
        self.name = name
        self.value = value

        super(BadParameterValueError, self).__init__(
            "Parameter %s has unreasonable value of %s" % (name, value))
github scidash / sciunit / sciunit / errors.py View on Github external
class CapabilityNotProvidedError(CapabilityError):
    """Error raised when a required capability is not *provided* by a model.
    Do not use for capabilities provided but not implemented."""
    
    action = 'provide'

class CapabilityNotImplementedError(CapabilityError):
    """Error raised when a required capability is not *implemented* by a model.
    Do not use for capabilities that are not provided at all."""
    
    action = 'implement'


class PredictionError(Error):
    """Raised when a tests's generate_prediction chokes on a model's method"""
    def __init__(self, model, method, **args):
        self.model = model
        self.method = method
        self.args = args

        super(PredictionError, self).__init__(
            ("During prediction, model '%s' could not successfully execute "
             "method '%s' with arguments %s") % (model.name, method, args))

    model = None
    """The model that does not have the capability."""

    argument = None
    """The argument that could not be handled."""
github scidash / sciunit / sciunit / errors.py View on Github external
"""
Exception classes for SciUnit
"""

import inspect
import sciunit

class Error(Exception):
    """Base class for errors in sciunit's core."""
    pass


class ObservationError(Error):
    """Raised when an observation passed to a test is invalid."""
    pass


class ParametersError(Error):
    """Raised when params passed to a test are invalid."""
    pass


class CapabilityError(Error):
    """Abstract error class for capabilities"""
    def __init__(self, model, capability, details=''):
        """
        model: a model instance
        capablity: a capability class
        """
github scidash / sciunit / sciunit / utils.py View on Github external
def config_get_from_path(config_path, key):
    try:
        with open(config_path) as f:
            config = json.load(f)
            value = config[key]
    except FileNotFoundError:
        raise Error("Config file not found at '%s'" % config_path)
    except json.JSONDecodeError:
        log("Config file JSON at '%s' was invalid" % config_path)
        raise Error("Config file not found at '%s'" % config_path)
    except KeyError:
        raise Error("Config file does not contain key '%s'" % key)
    return value
github scidash / sciunit / sciunit / errors.py View on Github external
class Error(Exception):
    """Base class for errors in sciunit's core."""
    pass


class ObservationError(Error):
    """Raised when an observation passed to a test is invalid."""
    pass


class ParametersError(Error):
    """Raised when params passed to a test are invalid."""
    pass


class CapabilityError(Error):
    """Abstract error class for capabilities"""
    def __init__(self, model, capability, details=''):
        """
        model: a model instance
        capablity: a capability class
        """
        self.model = model
        self.capability = capability
        if details:
            details = ' (%s)' % details
        if self.action:
            msg = "Model '%s' does not %s required capability: '%s'%s" % \
                  (model.name, self.action, capability.__name__, details)
        super(CapabilityError, self).__init__(details)
    
    action = None
github scidash / sciunit / sciunit / utils.py View on Github external
def config_get_from_path(config_path, key):
    try:
        with open(config_path) as f:
            config = json.load(f)
            value = config[key]
    except FileNotFoundError:
        raise Error("Config file not found at '%s'" % config_path)
    except json.JSONDecodeError:
        log("Config file JSON at '%s' was invalid" % config_path)
        raise Error("Config file not found at '%s'" % config_path)
    except KeyError:
        raise Error("Config file does not contain key '%s'" % key)
    return value
github scidash / sciunit / sciunit / errors.py View on Github external
"""

import inspect
import sciunit

class Error(Exception):
    """Base class for errors in sciunit's core."""
    pass


class ObservationError(Error):
    """Raised when an observation passed to a test is invalid."""
    pass


class ParametersError(Error):
    """Raised when params passed to a test are invalid."""
    pass


class CapabilityError(Error):
    """Abstract error class for capabilities"""
    def __init__(self, model, capability, details=''):
        """
        model: a model instance
        capablity: a capability class
        """
        self.model = model
        self.capability = capability
        if details:
            details = ' (%s)' % details
        if self.action: