MCPcopy Create free account
hub / github.com/datacamp/pythonwhat / test_exercise

Function test_exercise

pythonwhat/test_exercise.py:10–70  ·  view source on GitHub ↗

Point of interaction with the Python backend. Args: sct (str): The solution correctness 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_exercis

(
    sct,
    student_code,
    solution_code,
    pre_exercise_code,
    student_process,
    solution_process,
    raw_student_output,
    ex_type,
    error,
    force_diagnose=False,
)

Source from the content-addressed store, hash-verified

8
9
10def test_exercise(
11 sct,
12 student_code,
13 solution_code,
14 pre_exercise_code,
15 student_process,
16 solution_process,
17 raw_student_output,
18 ex_type,
19 error,
20 force_diagnose=False,
21):
22 """
23 Point of interaction with the Python backend.
24 Args:
25 sct (str): The solution correctness test as a string of code.
26 student_code (str): The code which is entered by the student.
27 solution_code (str): The code which is in the solution.
28 pre_exercise_code (str): The code which is executed pre exercise.
29 student_process (Process): Process in which the student code was executed.
30 solution_process (Process): Process in which the solution code was executed.
31 raw_student_output (str): The output which is given by executing the student's program.
32 ex_type (str): The type of the exercise.
33 error (tuple): A tuple with some information on possible errors.
34 Returns:
35 dict: Returns dict with correct - whether the SCT passed, message - the feedback message and
36 tags - the tags belonging to the SCT execution.
37 """
38
39 reporter = Reporter(errors=[error] if error else [])
40
41 try:
42 state = State(
43 student_code=check_str(student_code),
44 solution_code=check_str(solution_code),
45 pre_exercise_code=check_str(pre_exercise_code),
46 student_process=check_process(student_process),
47 solution_process=check_process(solution_process),
48 raw_student_output=check_str(raw_student_output),
49 force_diagnose=force_diagnose,
50 reporter=reporter,
51 )
52
53 State.root_state = state
54 tree, sct_cntxt = prep_context()
55
56 # Actually execute SCTs
57 exec(sct, sct_cntxt)
58
59 # Run remaining nodes on tree (v1 only)
60 if tree:
61 for test in tree.crnt_node:
62 test(state)
63
64 except Failure as e:
65 if isinstance(e, InstructorError):
66 # TODO: decide based on context
67 raise e

Callers 1

runFunction · 0.90

Calls 4

StateClass · 0.90
check_strFunction · 0.90
check_processFunction · 0.90
prep_contextFunction · 0.85

Tested by

no test coverage detected