|
| 1 | +from sqlwhat.Reporter import Reporter |
| 2 | +from sqlwhat.State import State |
| 3 | +from sqlwhat.selectors import Dispatcher |
| 4 | +from sqlwhat.Test import TestFail as TF |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +def prepare_state(sol_result, stu_result): |
| 9 | + dispatcher = Dispatcher.from_dialect('postgresql') |
| 10 | + |
| 11 | + return State( |
| 12 | + student_code = "", |
| 13 | + solution_code = "", |
| 14 | + reporter = Reporter(), |
| 15 | + # args below should be ignored |
| 16 | + pre_exercise_code = "", |
| 17 | + student_result = stu_result, solution_result = sol_result, |
| 18 | + student_conn = None, solution_conn = None, |
| 19 | + ast_dispatcher = dispatcher) |
| 20 | + |
| 21 | + |
| 22 | +from sqlwhat.sct_syntax import Ex |
| 23 | +from sqlwhat_ext import check_result_tsql |
| 24 | + |
| 25 | +def test_check_result_tsql_chain(): |
| 26 | + state = prepare_state({'a': [1,2,3]}, {'a': [1,2,3]}) |
| 27 | + Ex(state) >> check_result_tsql() |
| 28 | + |
| 29 | +@pytest.mark.parametrize('sol_res,stu_res', [ # pass cases where... |
| 30 | + ( {'a': [1,2,3]}, {'a': [1,2,3]} ), # identical |
| 31 | + ( {'a': [1,2,3]}, {'b': [1,2,3]} ), # diff colnames |
| 32 | + ( {'a': [1,2,3]}, {'b': [3,2,1]} ), # diff colnames + reordered |
| 33 | + ( {'a': [1]} , {'a': [1], 'b': [2]} ) # extra cols in student result |
| 34 | + ]) |
| 35 | +def test_check_result_tsql_pass(sol_res, stu_res): |
| 36 | + state = prepare_state(sol_res, stu_res) |
| 37 | + check_result_tsql(state) |
| 38 | + |
| 39 | +@pytest.mark.parametrize('sol_res,stu_res', [ # fail cases where... |
| 40 | + ( {'a': [1,2,3]}, {'a': [1,2]} ), # too few rows |
| 41 | + ( {'a': [1,2,3]}, {'a': [1,2,2]} ) # values mismatch |
| 42 | + ]) |
| 43 | +def test_check_result_tsql_match_fail(sol_res, stu_res): |
| 44 | + state = prepare_state(sol_res, stu_res) |
| 45 | + with pytest.raises(TF): |
| 46 | + check_result_tsql(state) |
0 commit comments