def test_multiple_state_init(conn): state1 = State( student_code="SELECT * FROM company", solution_code="SELECT * FROM company", pre_exercise_code="", student_result={ "id": [1], "name": ["greg"] }, solution_result={ "id": [0], "name": ["greg"] }, student_conn=conn, solution_conn=None, reporter=Reporter(), ) state2 = State( student_code="SELECT * FROM company", solution_code="SELECT * FROM company", pre_exercise_code="", student_result={ "id": [1], "name": ["greg"] }, solution_result={ "id": [0], "name": ["greg"] }, student_conn=conn, solution_conn=None, reporter=Reporter(), )
def test_get_dispatcher_oracle(): # Given conn2 = MagicMock() dialect = MagicMock() conn2.dialect = dialect dialect.name = "oracle" state = State( student_code="SELECT * FROM company", solution_code="SELECT * FROM company", pre_exercise_code="", student_result={ "id": [1], "name": ["greg"] }, solution_result={ "id": [1], "name": ["greg"] }, student_conn=conn2, solution_conn=None, reporter=Reporter(), ) # When output = state.get_dispatcher() # Then assert output.ast_mod.grammar.__spec__.name == 'antlr_plsql.antlr_py'
def test_line_info(sql_cmd, start, pos): state = State(sql_cmd, "", "", None, None, {}, {}, Reporter(), ast_dispatcher=Dispatcher.from_module( PARSER_MODULES['mssql'])) try: state.do_test("failure message") except TF as tf: for ii, k in enumerate(pos_names): assert tf.payload[k] == pos[ii]
def test_exercise(sct, student_code, student_result, student_conn, solution_code, solution_result, solution_conn, pre_exercise_code, ex_type, error, force_diagnose = False, debug = False # currently unused ): """ """ state = State( student_code = student_code, solution_code = solution_code, pre_exercise_code = pre_exercise_code, student_conn = student_conn, solution_conn = solution_conn, student_result = student_result, solution_result = solution_result, reporter = Reporter(error), force_diagnose = force_diagnose) SCT_CTX['Ex'].root_state = state try: exec(sct, SCT_CTX) except TestFail as tf: return tf.payload return state.reporter.build_final_payload()
def test_exercise( sct, student_code, student_result, student_conn, solution_code, solution_result, solution_conn, pre_exercise_code, ex_type, error, debug=False # currently unused ): """ """ state = State(student_code=student_code, solution_code=solution_code, pre_exercise_code=pre_exercise_code, student_conn=student_conn, solution_conn=solution_conn, student_result=student_result, solution_result=solution_result, reporter=Reporter(error)) SCT_CTX['Ex'].root_state = state try: exec(sct, SCT_CTX) except TestFail: pass return (state.reporter.build_payload())
def prepare_state(sol_result, stu_result): return State( student_code = "", solution_code = "", reporter = Reporter(), # args below should be ignored pre_exercise_code = "", student_result = stu_result, solution_result = sol_result, student_conn = None, solution_conn = None)
def test_state_line_info(): state = State("\nSELECT x FROM y", "SELECT x FROM y", "", None, None, {}, {}, Reporter(), ast_dispatcher=Dispatcher.from_module( PARSER_MODULES['mssql'])) with pytest.raises(TF): state.do_test("failure message") payload = state.reporter.build_payload() pos = [2, 1, 2, 15] pos_names = ['line_start', 'column_start', 'line_end', 'column_end'] for ii, k in enumerate(pos_names): assert payload[k] == pos[ii]
def prepare_state(student_code): return State( student_code = "", reporter = Reporter(), # args below should be ignored solution_code = "NA", pre_exercise_code = "NA", solution_ast = "NA", student_ast = "NA", student_result = [], solution_result = [], student_conn = None, solution_conn = None, ast_dispatcher = "NA")
def test_multiple_state_init(conn): state1 = State( student_code = "SELECT * FROM company", solution_code = "SELECT * FROM company", pre_exercise_code = "", student_result = {'id': [1], 'name': ['greg']}, solution_result = {'id': [0], 'name': ['greg']}, student_conn = conn, solution_conn = None, reporter= Reporter()) state2 = State( student_code = "SELECT * FROM company", solution_code = "SELECT * FROM company", pre_exercise_code = "", student_result = {'id': [1], 'name': ['greg']}, solution_result = {'id': [0], 'name': ['greg']}, student_conn = conn, solution_conn = None, reporter= Reporter())
def prepare_state(sol_result, stu_result): conn = Connection('postgresql') return State( student_code="", solution_code="", reporter=Reporter(), # args below should be ignored pre_exercise_code="NA", student_result=stu_result, solution_result=sol_result, student_conn=conn, solution_conn=None)
def prepare_state(sol_result, stu_result): dispatcher = Dispatcher.from_dialect('postgresql') return State( student_code = "", solution_code = "", reporter = Reporter(), # args below should be ignored pre_exercise_code = "", student_result = stu_result, solution_result = sol_result, student_conn = None, solution_conn = None, ast_dispatcher = dispatcher)
def state(): conn = Connection('postgresql') return State( student_code="", solution_code="", reporter=Reporter(), # args below should be ignored pre_exercise_code="NA", student_result={'a': [1]}, solution_result={'b': [2]}, student_conn=conn, solution_conn=None)
def prepare_state(solution_code, student_code, dialect='postgresql'): dispatcher = Dispatcher.from_module(PARSER_MODULES[dialect]) return State( student_code=student_code, solution_code=solution_code, reporter=Reporter(), # args below should be ignored pre_exercise_code="NA", student_result=[], solution_result=[], student_conn=None, solution_conn=None, ast_dispatcher=dispatcher)
def test_pass(conn): state = State( student_code = "SELECT * FROM company", solution_code = "SELECT * FROM company", pre_exercise_code = "", student_result = {'id': [1], 'name': ['greg']}, solution_result = {'id': [1], 'name': ['greg']}, student_conn = conn, solution_conn = None, reporter= Reporter()) Ex.root_state = state assert Ex().check_result()
def test_fail(conn): state = State( student_code = "SELECT * FROM company", solution_code = "SELECT * FROM company", pre_exercise_code = "", student_result = {'id': [1], 'name': ['greg']}, solution_result = {'id': [0], 'name': ['greg']}, student_conn = conn, solution_conn = None, reporter= Reporter()) Ex.root_state = state with pytest.raises(TF): Ex().check_result()