Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_score_type(self, score):
"""Check that the score is the correct type for this test."""
if not isinstance(score, (self.score_type, NoneScore, ErrorScore)):
msg = (("Score for test '%s' is not of correct type. "
"The test requires type %s but %s was provided.")
% (self.name, self.score_type.__name__,
score.__class__.__name__))
raise InvalidScoreError(msg)
def _judge(self, prediction1, prediction2, model1, model2=None):
# TODO: Not sure if below statement is required
# self.last_model = model
# 6.
score = self.compute_score(prediction1, prediction2)
if self.converter:
score = self.converter.convert(score)
# 7.
if not isinstance(score, (self.score_type, NoneScore, ErrorScore)):
raise InvalidScoreError(("Score for test '%s' is not of correct "
"type. The test requires type %s but %s "
"was provided.")
% (self.name, self.score_type.__name__,
score.__class__.__name__))
# 8.
self._bind_score(score, prediction1, prediction2, model1, model2)
return score
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_score(self, score):
if not (0.0 <= score <= 100.0):
raise errors.InvalidScoreError(("Score of %f must be in "
"range 0.0-100.0" % score))
def check_score(self, score):
if self._allowed_types and \
not isinstance(score, self._allowed_types+(Exception,)):
raise InvalidScoreError(self._allowed_types_message %
(type(score), self._allowed_types))
self._check_score(score)
def _check_score(self, score):
if isinstance(score, pq.Quantity) and score.size != 1:
raise errors.InvalidScoreError("Score must have size 1.")
def __init__(self, score, related_data=None):
if isinstance(score, str) or score is None:
super(NoneScore, self).__init__(score, related_data=related_data)
else:
raise InvalidScoreError("Score must be a string or None")