def test_F(self): self.data["DC_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) ''' sct_payload = helper.run(self.data) self.assertTrue(sct_payload['correct'])
def test_multi_generator(self): self.data["DC_SCT"] = """ Ex().check_list_comp(0).check_body()\ .multi(set_context(aa=i).has_equal_value('wrong') for i in range(2)) """ sct_payload = helper.run(self.data) self.assertTrue(sct_payload['correct'])
def test_multi_splits_node_and_check(self): self.data["DC_SCT"] = ''' test_body = F().check_list_comp(0).check_body().set_context(aa=2).has_equal_value('wrong') Ex().check_list_comp(0).multi(F().check_body().set_context(aa=2).has_equal_value('wrong')) ''' sct_payload = helper.run(self.data) self.assertTrue(sct_payload['correct'])
def test_check_to_F_nested(self): self.data["DC_SCT"] = ''' # 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) ''' sct_payload = helper.run(self.data) self.assertTrue(sct_payload['correct'])
def test_spec_run_order(self): self.data["DC_CODE"] = '''[aa for aa in range(2)]''' self.data["DC_SCT"] = ''' Ex().test_list_comp(body=test_expression_result(extra_env={'aa': 2}, incorrect_msg = 'spec1')) Ex().check_list_comp(0).check_body().set_context(aa=2).has_equal_value('spec2') ''' sct_payload = helper.run(self.data) self.assertFalse(sct_payload['correct']) self.assertIn('spec1', sct_payload['message'])
def test_spec1_in_multi_pass(self): self.data["DC_SCT"] = ''' te = test_expression_result(extra_env={'aa':2}, incorrect_msg='unequal') Ex().multi(test_list_comp(body=te)) # spec 1 inside multi Ex().check_list_comp(0).check_body().multi(te) # half of each spec Ex().check_list_comp(0).check_body().set_context(aa=2).has_equal_value('unequal') # full spec 2 test_list_comp(body=te) # full spec 1 ''' sct_payload = helper.run(self.data) self.assertTrue(sct_payload['correct'])
def setup_state(stu_code="", sol_code="", pec="", pid=None): stu_output = io.StringIO() with redirect_stdout(stu_output): stu_process = StubProcess("%s\n%s" % (pec, stu_code), pid) sol_output = io.StringIO() with redirect_stdout(sol_output): sol_process = StubProcess("%s\n%s" % (pec, sol_code), pid) rep = Reporter() Reporter.active_reporter = rep 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=stu_output.getvalue()) State.root_state = state return (Ex(state))
def test_F_assign_getattr(self): self.data["DC_SCT"] = '''
def ex(): return Ex('state')._sct_copy(lambda x, state=None: 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'
def test_check_to_F(self): self.data["DC_SCT"] = '''