Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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)
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
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]
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)
"""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))