def setup_state(stu_code="", sol_code="", pec="", **kwargs): sol_process, stu_process, raw_stu_output, error = run_exercise( pec, sol_code, stu_code, **kwargs) state = State( student_code=stu_code, solution_code=sol_code, pre_exercise_code=pec, student_process=stu_process, solution_process=sol_process, raw_student_output=raw_stu_output, reporter=Reporter(errors=[error] if error else []), ) State.root_state = state return Ex(state)
def setup_state(stu_code="", sol_code="", pec="", pid=None): sol_process, stu_process, raw_stu_output, _ = run_exercise(pec, sol_code, stu_code, pid=pid) state = State(student_code=stu_code, solution_code=sol_code, pre_exercise_code=pec, student_process=stu_process, solution_process=sol_process, raw_student_output=raw_stu_output, reporter=Reporter()) State.root_state = state return Ex(state)
def ex(): return ChainExtender(Ex("state"), lambda state, x: state + x)("x")
@pytest.mark.parametrize( "sct", [ """ list_comp = F().check_list_comp(0).check_body().set_context(ii=2).has_equal_value('unequal') Ex().check_list_comp(0).check_body().set_context(aa=2).multi(list_comp) """, """ list_comp = check_list_comp(0).check_body().set_context(ii=2).has_equal_value('unequal') Ex().check_list_comp(0).check_body().set_context(aa=2).multi(list_comp) """, """ # funky, but we're testing nested check functions! multi_test = multi(check_list_comp(0).check_body().set_context(aa=2).has_equal_value('badbody')) Ex().multi(multi_test) """, """ list_comp = F().check_list_comp(0).check_body().set_context(ii=2).has_equal_value('unequal') Ex().check_list_comp(0).check_body().set_context(aa=2).multi(list_comp) Ex().check_list_comp(1).check_body().set_context(bb=4).multi(list_comp) """, """ eq_test = F().check_list_comp(0).check_body().set_context(1).has_equal_value Ex().multi(eq_test('unequal')) """, ], ) def test_f_chain(sct): code = "[[ii+1 for ii in range(aa)] for aa in range(2)]\n[[ii*2 for ii in range(bb)] for bb in range(1,3)]" res = helper.run({"DC_SOLUTION": code, "DC_CODE": code, "DC_SCT": sct})
def ex(): return Ex("state")._sct_copy(lambda state, x: state + x)("x")
def test_ex_sct_copy_pos(addx): assert Ex("state")._sct_copy(addx)("x")._state == "statex"
def test_ex_sct_copy_kw(addx): assert Ex("state")._sct_copy(addx)(x="x")._state == "statex"