Example #1
0
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_value(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
Example #2
0
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_value(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
Example #3
0
 def test_returns_false_for_multiple_operators(self):
     self.assertFalse(lib.is_score_value("++INFINITY"))
Example #4
0
 def test_returns_false_for_nonumber_noinfinity(self):
     self.assertFalse(lib.is_score_value("something else"))
Example #5
0
 def test_returns_true_for_plus_infinity(self):
     self.assertTrue(lib.is_score_value("+INFINITY"))
Example #6
0
 def test_returns_true_for_plus_number(self):
     self.assertTrue(lib.is_score_value("+1"))
Example #7
0
 def test_returns_false_for_multiple_operators(self):
     self.assertFalse(lib.is_score_value("++INFINITY"))
Example #8
0
 def test_returns_false_for_nonumber_noinfinity(self):
     self.assertFalse(lib.is_score_value("something else"))
Example #9
0
 def test_returns_true_for_plus_infinity(self):
     self.assertTrue(lib.is_score_value("+INFINITY"))
Example #10
0
 def test_returns_true_for_plus_number(self):
     self.assertTrue(lib.is_score_value("+1"))