How to use the sciunit.errors.CapabilityError 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 / unit_test / error_tests.py View on Github external
def test_error_types(self):
        from sciunit.errors import CapabilityError, BadParameterValueError,\
                                   PredictionError, InvalidScoreError
        from sciunit import Model, Capability

        CapabilityError(Model(),Capability)
        PredictionError(Model(),'foo')
        InvalidScoreError()
        BadParameterValueError('x',3)
github scidash / sciunit / sciunit / unit_test / core_tests.py View on Github external
def test_error_types(self):
        from sciunit.errors import CapabilityError, BadParameterValueError,\
                                   PredictionError, InvalidScoreError
        from sciunit import Model, Capability

        CapabilityError(Model(),Capability)
        PredictionError(Model(),'foo')
        InvalidScoreError()
        BadParameterValueError('x',3)
github scidash / sciunit / sciunit / tests.py View on Github external
def check_capability(self, model, c, skip_incapable=False,
                         require_extra=False):
        """Check if `model` has capability `c`.

        Optionally (default:True) raise a `CapabilityError` if it does not.
        """
        capable = c.check(model, require_extra=require_extra)
        if not capable and not skip_incapable:
            raise CapabilityError(model, c)
        return capable
github scidash / sciunit / sciunit / tests.py View on Github external
for model in models:
            if not isinstance(model, Model):
                raise TypeError(("TestM2M's judge method received a non-Model."
                                 "Invalid model name: '%s'" % model))
            else:
                try:
                    # 3.
                    self.check_capabilities(model,
                                            skip_incapable=skip_incapable)
                    # 4.
                    prediction = self.generate_prediction(model)
                    self.check_prediction(prediction)
                    predictions.append(prediction)
                except CapabilityError as e:
                    raise CapabilityError(model, e.capability,
                                          ("TestM2M's judge method resulted in"
                                           " error for '%s'. Error: '%s'" %
                                           (model, str(e))))
                except Exception as e:
                    raise Exception(("TestM2M's judge method resulted in error"
                                     "for '%s'. Error: '%s'" %
                                     (model, str(e))))

        # 5. 2D list for scores; num(rows) = num(cols) = num(predictions)
        scores = [[NoneScore for x in range(len(predictions))]
                  for y in range(len(predictions))]

        for i in range(len(predictions)):
            for j in range(len(predictions)):
                if not self.observation:
                    model1 = models[i]
github scidash / sciunit / sciunit / errors.py View on Github external
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)
github scidash / sciunit / sciunit / errors.py View on Github external
"""The action that has failed ('provide' or 'implement')"""
    
    model = None
    """The model instance that does not have the capability."""

    capability = None
    """The capability class that is not provided."""


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))