def test_osh_selector_var_sub(state): target = state.ast_dispatcher.nodes.get('SimpleVarSub') cl = check_node(state, "SimpleCommand") word = check_field(cl, 'words', 2) varsub = check_field(word, 'parts', 0) assert isinstance(varsub.student_ast, target) assert varsub.student_ast.token == "$b"
def test_check_field_antlr_exception_skips(dialect_name): state = prepare_state("SELECT x FROM ___!", "SELECT x FROM ___!", dialect_name) assert isinstance(state.student_ast, state.ast_dispatcher.ast.AntlrException) select = check_field(state, "where", 0) # should be skipped assert select is state
def test_has_equal_ast_field_fail(): state = prepare_state('SELECT id, name FROM Trips', "SELECT name FROM Trips") sel = cf.check_node(state, "SelectStmt", 0) tl = cf.check_field(sel, "target_list", 0) with pytest.raises(TF) as exc_info: has_equal_ast(tl) print_message(exc_info)
def test_check_field_index_none_fail(): state = prepare_state("SELECT a, b FROM b WHERE a < 10", "SELECT a FROM b") sel = check_node(state, 'SelectStmt') with pytest.raises(TF) as exc_info: from_field = check_field(sel, 'where_clause') print_message(exc_info)
def test_student_typed_subset_re_pass(state_tst): select = check_node(state_tst, "SelectStmt", 0) where = check_field(select, "where_clause") with pytest.raises(TF): cf.test_student_typed(where, "id > [a-z]")
def test_student_typed_subset_re_pass(state_tst): select = check_node(state_tst, "SelectStmt", 0) where = check_field(select, "where_clause") cf.test_student_typed(where, "id > [0-9]")
def test_student_typed_fixed_subset_fail(state_tst): select = check_node(state_tst, "SelectStmt", 0) where = check_field(select, "where_clause") with pytest.raises(TF): cf.test_student_typed(where, "WHERE id > 4", fixed=True)
def test_check_field_index_fail(): state = prepare_state("SELECT id, name FROM Trips", "SELECT id FROM Trips") select = check_node(state, "SelectStmt", 0) with pytest.raises(TF) as exc_info: check_field(select, "target_list", 1) print_message(exc_info)
def test_check_field_index_pass(): state = prepare_state("SELECT id, name FROM Trips", "SELECT id, name FROM Trips") select = check_node(state, "SelectStmt", 0) check_field(select, "target_list", 1)
def test_check_field_fail(): state = prepare_state("SELECT id FROM Trips WHERE id > 3", "SELECT id FROM Trips WHERE id>4") select = check_node(state, "SelectStmt", 0) check_field(select, "where_clause")
def test_check_node_from_list(): state = prepare_state("SELECT a, b, c FROM x", "SELECT a, b, c FROM x") sel = check_node(state, "SelectStmt", 0) tl = check_field(sel, "target_list") check_node(tl, "Identifier")
def test_has_equal_ast_subcode(state): word = check_field(check_node(state, 'SimpleCommand'), 'words', 0) has_equal_ast(word)
def test_osh_selector_fail(state): child = check_node(state, 'SimpleCommand') with pytest.raises(TF): check_field(child, 'words', 4)
def test_osh_selector_result(state): target = state.ast_dispatcher.nodes.get('CompoundWord') cl = check_node(state, "SimpleCommand") cmd = check_field(cl, 'words', 0) assert isinstance(cmd.student_ast, target) assert cmd.student_ast.parts[0].token == "echo"