Beispiel #1
0
def step_impl(context: Context):
    raw_answer_identifiers = parse_table(context.table)
    grouped_answer_identifiers = defaultdict(list)
    for raw_answer_identifier in raw_answer_identifiers:
        owner = next(entry[1] for entry in raw_answer_identifier if entry[0] == AnswerIdentifierGroup.GROUP_COLUMN_NAME)
        grouped_answer_identifiers[owner].append(raw_answer_identifier)
    answer_identifier_groups = [AnswerIdentifierGroup(raw_identifiers) for raw_identifiers in grouped_answer_identifiers.values()]

    assert_that(context.answer_groups, has_length(len(answer_identifier_groups)),
                "Expected [%d] answer groups, but found [%d]." % (len(answer_identifier_groups), len(context.answer_groups)))

    for answer_identifier_group in answer_identifier_groups:
        identifier = parse_concept_identifier(answer_identifier_group.owner_identifier)
        answer_group = next((group for group in context.answer_groups if identifier.matches(context, group.owner())), None)
        assert_that(answer_group is not None,
                    reason="The group identifier [%s] does not match any of the answer group owners." % answer_identifier_group.owner_identifier)

        result_set = [(ai, []) for ai in answer_identifier_group.answer_identifiers]
        for answer in answer_group.concept_maps():
            for (answer_identifier, matched_answers) in result_set:
                if answer_concepts_match(context, answer_identifier, answer):
                    matched_answers.append(answer)

        for (answer_identifier, answers) in result_set:
            assert_that(answers, has_length(1), "Each answer identifier should match precisely 1 answer, but [%d] answers "
                                                "matched the identifier [%s]." % (len(answers), answer_identifier))
Beispiel #2
0
def step_impl(context: Context):
    raw_answer_identifiers = parse_table(context.table)
    expectations = {}
    for raw_answer_identifier in raw_answer_identifiers:
        owner = next(entry[1] for entry in raw_answer_identifier
                     if entry[0] == AnswerIdentifierGroup.GROUP_COLUMN_NAME)
        expected_answer = parse_float(
            next(entry[1] for entry in raw_answer_identifier
                 if entry[0] == "value"))
        expectations[owner] = expected_answer

    assert_that(context.numeric_answer_groups,
                has_length(len(expectations)),
                reason="Expected [%d] answer groups, but found [%d]." %
                (len(expectations), len(context.numeric_answer_groups)))

    for (owner_identifier, expected_answer) in expectations.items():
        identifier = parse_concept_identifier(owner_identifier)
        numeric_group = next((group for group in context.numeric_answer_groups
                              if identifier.matches(context, group.owner())),
                             None)
        assert_that(
            numeric_group is not None,
            reason=
            "The group identifier [%s] does not match any of the answer group owners."
            % owner_identifier)

        actual_answer = get_numeric_value(numeric_group.numeric())
        assert_numeric_value(
            numeric_group.numeric(),
            expected_answer,
            reason="Expected answer [%f] for group [%s], but got [%f]" %
            (expected_answer, owner_identifier, actual_answer))
Beispiel #3
0
def step_impl(context: Context):
    answer_identifiers = parse_table(context.table)
    assert_that(
        context.answers, has_length(len(answer_identifiers)),
        "The number of answers [%d] should match the number of answer identifiers [%d]."
        % (len(context.answers), len(answer_identifiers)))

    result_set = [(ai, [], []) for ai in answer_identifiers]
    for answer_identifier, matched_answers, match_attempts in result_set:
        for answer in context.answers:
            result = match_answer_concepts(context, answer_identifier, answer)
            match_attempts.append(result)
            if result.matches():
                matched_answers.append(answer)
        assert_that(
            matched_answers, has_length(1),
            "Each answer identifier should match precisely 1 answer, but [%d] answers matched the identifier [%s].\nThe match results were: %s"
            % (len(matched_answers), answer_identifier,
               [str(x) for x in match_attempts]))

    for answer in context.answers:
        matches = 0
        for answer_identifier, matched_answers, match_attempts in result_set:
            if answer in matched_answers:
                matches += 1
                break
        if matches != 1:
            match_attempts = []
            for answer_identifier in answer_identifiers:
                match_attempts.append(
                    match_answer_concepts(context, answer_identifier, answer))
            assert_that(
                matches, is_(1),
                "Each answer should match precisely 1 answer identifier, but [%d] answer identifiers matched the answer [%s].\nThe match results were: %s"
                % (matches, answer, [str(x) for x in match_attempts]))
Beispiel #4
0
def step_impl(context: Context):
    answer_identifiers = parse_table(context.table)
    assert_that(context.answers, has_length(len(answer_identifiers)),
                "The number of answers [%d] should match the number of answer identifiers [%d]." % (len(context.answers), len(answer_identifiers)))
    for i in range(len(context.answers)):
        answer = context.answers[i]
        answer_identifier = answer_identifiers[i]
        assert_that(answer_concepts_match(context, answer_identifier, answer),
                    reason="The answer at index [%d] does not match the identifier [%s]." % (i, answer_identifier))
Beispiel #5
0
def step_impl(context: Context):
    answer_identifiers = parse_table(context.table)
    assert_that(context.answers, has_length(len(answer_identifiers)),
                "The number of answers [%d] should match the number of answer identifiers [%d]." % (len(context.answers), len(answer_identifiers)))

    result_set = [(ai, []) for ai in answer_identifiers]
    for answer in context.answers:
        for answer_identifier, matched_answers in result_set:
            if answer_concepts_match(context, answer_identifier, answer):
                matched_answers.append(answer)

    for answer_identifier, answers in result_set:
        assert_that(answers, has_length(1), "Each answer identifier should match precisely 1 answer, but [%d] answers "
                                            "matched the identifier [%s]." % (len(answers), answer_identifier))
Beispiel #6
0
def step_impl(context: Context):
    answer_identifiers = parse_table(context.table)
    assert_that(
        context.answers, has_length(len(answer_identifiers)),
        "The number of answers [%d] should match the number of answer identifiers [%d]."
        % (len(context.answers), len(answer_identifiers)))
    for i in range(len(context.answers)):
        answer = context.answers[i]
        answer_identifier = answer_identifiers[i]
        result = match_answer_concepts(context, answer_identifier, answer)
        assert_that(
            result.matches(), is_(True),
            "The answer at index [%d] does not match the identifier [%s].\nThe match results were: %s"
            % (i, answer_identifier, result))