def _validate_value(self, value: ValuePair) -> ReportItemList: report_list = [] if not is_score(value.normalized): report_list.append( ReportItem.error(reports.messages.InvalidScore( value.original))) return report_list
def prepare_options_with_set(cib, options, resource_set_list): options = constraint.prepare_options( ("score", ), options, partial(constraint.create_id, cib, "colocation", resource_set_list), partial(check_new_id_applicable, cib, DESCRIPTION), ) if "score" in options: if not is_score(options["score"]): raise LibraryError( ReportItem.error( reports.messages.InvalidScore(options["score"]))) else: options["score"] = SCORE_INFINITY return options
def prepare_options_with_set(cib, options, resource_set_list): options = constraint.prepare_options( tuple(SCORE_NAMES), options, partial(constraint.create_id, cib, TAG_NAME, resource_set_list), partial(check_new_id_applicable, cib, DESCRIPTION), ) if "score" in options and not is_score(options["score"]): raise LibraryError(reports.invalid_score(options["score"])) score_attrs_count = len( [name for name in options.keys() if name in SCORE_NAMES]) if score_attrs_count > 1: raise LibraryError(reports.multiple_score_options()) if score_attrs_count == 0: options["score"] = SCORE_INFINITY return options
def prepare_options_with_set(cib, options, resource_set_list): options = constraint.prepare_options( tuple(SCORE_NAMES), options, partial(constraint.create_id, cib, TAG_NAME, resource_set_list), partial(check_new_id_applicable, cib, DESCRIPTION), ) if "score" in options and not is_score(options["score"]): raise LibraryError(reports.invalid_score(options["score"])) score_attrs_count = len([ name for name in options.keys() if name in SCORE_NAMES ]) if score_attrs_count > 1: raise LibraryError(reports.multiple_score_options()) if score_attrs_count == 0: options["score"] = SCORE_INFINITY return options
def test_returns_false_for_multiple_operators(self): self.assertFalse(lib.is_score("++INFINITY"))
def test_returns_false_for_nonumber_noinfinity(self): self.assertFalse(lib.is_score("something else"))
def test_returns_true_for_plus_infinity(self): self.assertTrue(lib.is_score("+INFINITY"))
def test_returns_true_for_plus_number(self): self.assertTrue(lib.is_score("+1"))