def test_check_file_no_parse(state, temp_file_sum): child = cf.check_file(state, temp_file_sum.name, parse=False) has_code(child, "1 + 1", fixed=True) assert child.student_code == "1 + 1" assert child.student_ast is False assert child.solution_ast is None # no solution code is provided with pytest.raises(TypeError): assert check_node(child, "Expr", 0)
def test_where_brackets_with_has_code(): state = prepare_state("SELECT a FROM b WHERE c AND d", "SELECT a FROM b WHERE (d AND c)") sel = check_node(state, "SelectStmt") wc = check_edge(sel, "where_clause") has_code(wc, "d") with pytest.raises(TF): has_code(wc, "not_there")
def test_has_code_comment_only(): state_tst = prepare_state("/*blabla*/", "/*blabla*/") with pytest.raises(TF): result = has_code(state_tst, "blabla", fixed=True)
def test_has_code_no_ast(): state_tst = prepare_state("SELECT * FROM x!!", "SELECT * FROM x!!") has_code(state_tst, "*", fixed=True)
def test_has_code_fixed_star_pass(): state_tst = prepare_state("SELECT * FROM x", "SELECT * FROM x") has_code(state_tst, "*", fixed=True)
def test_has_code_upper_case_pass(state_tst): has_code(state_tst, "AND")
def test_has_code_subset_re_pass2(state_tst): select = check_node(state_tst, "SelectStmt", 0) where = check_edge(select, "where_clause") with pytest.raises(TF): has_code(where, "id > [a-z]")
def test_has_code_subset_re_pass(state_tst): select = check_node(state_tst, "SelectStmt", 0) where = check_edge(select, "where_clause") has_code(where, "id > [0-9]")
def test_has_code_fixed_subset_fail2(state_tst): select = check_node(state_tst, "SelectStmt", 0) where = check_edge(select, "where_clause") with pytest.raises(TF): has_code(where, "WHERE id > 4", fixed=True)
def test_has_code_fixed_subset_pass(state_tst): select = check_node(state_tst, "SelectStmt", 0) where = check_edge(select, "where_clause") has_code(where, "id > 4", fixed=True)
def test_has_code_fixed_subset_fail(state_tst): select = check_node(state_tst, "SelectStmt", 0) # should fail because the select statement does not include ';' with pytest.raises(TF): has_code(select, state_tst.student_code, fixed=True)
def test_has_code_itself_pass(state_tst): has_code(state_tst, text=state_tst.student_code, fixed=True)