Exemple #1
0
def test_exercise(
    sct,
    student_code,
    solution_code,
    pre_exercise_code,
    student_process,
    solution_process,
    raw_student_output,
    ex_type,
    error,
    force_diagnose=False,
):
    """
    Point of interaction with the Python backend.
    Args:
            sct (str): The solution corectness test as a string of code.
            student_code (str): The code which is entered by the student.
            solution_code (str): The code which is in the solution.
            pre_exercise_code (str): The code which is executed pre exercise.
            student_process (Process): Process in which the student code was executed.
            solution_process (Process): Process in which the solution code was executed.
            raw_student_output (str): The output which is given by executing the student's program.
            ex_type (str): The type of the exercise.
            error (tuple): A tuple with some information on possible errors.
    Returns:
            dict: Returns dict with correct - whether the SCT passed, message - the feedback message and
              tags - the tags belonging to the SCT execution.
    """

    try:
        state = State(
            student_code=check_str(student_code),
            solution_code=check_str(solution_code),
            pre_exercise_code=check_str(pre_exercise_code),
            student_process=check_process(student_process),
            solution_process=check_process(solution_process),
            raw_student_output=check_str(raw_student_output),
            force_diagnose=force_diagnose,
            reporter=Reporter([error] if error else [])
        )

        State.root_state = state

        tree, sct_cntxt = prep_context()

        # Actually execute SCTs
        exec(sct, sct_cntxt)

        # Run remaining nodes on tree (v1 only)
        if tree:
            for test in tree.crnt_node:
                test(state)

    except TestFail as e:
        return e.payload

    return state.reporter.build_final_payload()
Exemple #2
0
def test_exercise(sct,
                  student_code,
                  solution_code,
                  pre_exercise_code,
                  student_process,
                  solution_process,
                  raw_student_output,
                  ex_type,
                  error):
    """
    Point of interaction with the Python backend.
    Args:
            sct (str): The solution corectness test as a string of code.
            student_code (str): The code which is entered by the student.
            solution_code (str): The code which is in the solution.
            pre_exercise_code (str): The code which is executed pre exercise.
            student_process (Process): Process in which the student code was executed.
            solution_process (Process): Process in which the solution code was executed.
            raw_student_output (str): The output which is given by executing the student's program.
            ex_type (str): The type of the exercise.
            error (tuple): A tuple with some information on possible errors.
    Returns:
            dict: Returns dict with correct - whether the SCT passed, message - the feedback message and
              tags - the tags belonging to the SCT execution.
    """

    rep = Reporter(error)
    Reporter.active_reporter = rep

    try:
        state = State(
            student_code = check_str(student_code),
            solution_code = check_str(solution_code),
            pre_exercise_code = check_str(pre_exercise_code),
            student_process = check_process(student_process),
            solution_process = check_process(solution_process),
            raw_student_output = check_str(raw_student_output)
        )

        State.root_state = state

        # Populate sct context with 'old' functions (in terms of probes) and check functions.
        tree, sct_cntxt = create_test_probes(cntxt)
        sct_cntxt.update(spec_2_context)

        # Actually execute SCTs
        exec(sct, sct_cntxt)         # Spec v2 tests run immediately
        for test in tree.crnt_node:  # Spec v1 tests run after
            test(state)

    except TestFail as e:
        return e.payload

    return rep.build_final_payload()
Exemple #3
0
def test_exercise(sct,
                  student_code,
                  solution_code,
                  pre_exercise_code,
                  student_process,
                  solution_process,
                  raw_student_output,
                  ex_type,
                  error):
    """
    Point of interaction with the Python backend.
    Args:
            sct (str): The solution corectness test as a string of code.
            student_code (str): The code which is entered by the student.
            solution_code (str): The code which is in the solution.
            pre_exercise_code (str): The code which is executed pre exercise.
            student_process (Process): Process in which the student code was executed.
            solution_process (Process): Process in which the solution code was executed.
            raw_student_output (str): The output which is given by executing the student's program.
            ex_type (str): The type of the exercise.
            error (tuple): A tuple with some information on possible errors.
    Returns:
            dict: Returns dict with correct - whether the SCT passed, message - the feedback message and
              tags - the tags belonging to the SCT execution.
    """

    rep = Reporter()
    Reporter.active_reporter = rep

    state = State(
        student_code = check_str(student_code),
        solution_code = check_str(solution_code),
        full_student_code = check_str(student_code),
        full_solution_code = check_str(solution_code),
        pre_exercise_code = check_str(pre_exercise_code),
        student_process = check_process(student_process),
        solution_process = check_process(solution_process),
        raw_student_output = check_str(raw_student_output))

    State.root_state = state

    # Populate sct context with 'old' functions (in terms of probes) and check functions.
    tree, sct_cntxt = create_test_probes(cntxt)
    sct_cntxt.update(spec_2_context)

    try:
        if not rep.failed_test:
            exec(sct, sct_cntxt)         # Spec v2 tests run immediately
            for test in tree.crnt_node:  # Spec v1 tests run after
                test(state)
    except TestFail: pass

    return(rep.build_payload(error))