Ejemplo n.º 1
0
def test_attributes_to_classes(make_model_color_classes):
    chips_and_answers = make_model_color_classes

    # The keyr function, and the indices from the answer namedtuple
    # corresponding to what is returned by the function
    function_and_indices = (
        (utils.key_make_model, [0, 1]),
        (utils.key_color, [2]),
        (utils.key_make_model_color, [0, 1, 2]),
    )

    for chips, answers in chips_and_answers:
        for func, indices in function_and_indices:
            class_to_index = utils.attributes_to_classes(chips, func)

            # Make the answer set by selecting the correct entries out of the
            # answer namedtuple
            answer = []
            for a in answers:
                temp_tup = []
                for i in indices:
                    temp_tup.append(a[i])

                ans_str = utils.tuple_to_string(temp_tup)
                answer.append(ans_str)

            answer = set(answer)

            # Test that the keys are correct
            keys = set(class_to_index.keys())
            assert keys == answer

            # Test that the indices are correct
            indices = set(class_to_index.values())
            assert indices == {i for i in range(len(answer))}
Ejemplo n.º 2
0
def test_tuple_to_string():
    TUPLES = (
        ((None,), "None"),
        ((None, "Thing"), "None_Thing"),
        ((1, 2), "1_2"),
        (("Thing",), "Thing"),
    )
    for tup, answer in TUPLES:
        assert utils.tuple_to_string(tup) == answer
Ejemplo n.º 3
0
def test_key_make_model_color(chips_and_answers):
    for chip, answer in chips_and_answers:
        real_answer = utils.tuple_to_string(answer)
        assert utils.key_make_model_color(chip) == real_answer
Ejemplo n.º 4
0
def test_key_color(chips_and_answers):
    for chip, answer in chips_and_answers:
        real_answer = utils.tuple_to_string([answer.color])
        assert utils.key_color(chip) == real_answer
Ejemplo n.º 5
0
def test_key_make_model(chips_and_answers):
    for chip, answer in chips_and_answers:
        ans = (answer.make, answer.model)
        real_answer = utils.tuple_to_string(ans)
        assert utils.key_make_model(chip) == real_answer