Exemplo n.º 1
0
def test_reporter_line_info_1_based_cols():
    rep = Reporter()
    rep.failed_test = True
    rep.feedback = Feedback("MESSAGE", ast.parse("\nSELECT x FROM y"))
    payload = rep.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]
Exemplo n.º 2
0
def get_ast(code, start, parser_name):
    if parser_name == "plsql":
        return plsql_ast.parse(code, start)
    elif parser_name == "tsql":
        return tsql_ast.parse(code, start)
    elif parser_name == "python":
        return python_ast.parse(code)

    return None
Exemplo n.º 3
0
def test_ast_examples_parse(fname):
    # just make sure they don't throw error for now..
    import yaml
    dirname = os.path.dirname(__file__)
    data = yaml.load(open(dirname + '/' + fname))
    res = {}
    for start, cmds in data['code'].items():
        res[start] = []
        for cmd in cmds: res[start].append([cmd, repr(ast.parse(cmd, start, strict=True))])
    print(res)
    with open(dirname + '/dump_' + fname, 'w') as out_f:
        yaml.dump(res, out_f)
Exemplo n.º 4
0
def ast_examples_parse(fname):
    # just make sure they don't throw error for now..
    import yaml

    dirname = os.path.dirname(__file__)
    data = yaml.safe_load(open(dirname + "/" + fname))
    res = {}
    for start, cmds in data["code"].items():
        res[start] = []
        for cmd in cmds:
            res[start].append([cmd, repr(ast.parse(cmd, start, strict=True))])
    print(res)
    filename = "dump_" + fname
    with open(dirname + "/" + filename, "w") as out_f:
        yaml.dump(res, out_f)
    return filename
Exemplo n.º 5
0
def test_ast_parse_strict():
    with pytest.raises(ast.AntlrException):
        ast.parse("SELECT x FROM ____!", strict = True)   # ____! is ungrammatical
Exemplo n.º 6
0
def test_case_sensitivity(stu):
    lowercase = "select \"Preserve\" from b where b.name = 'Casing'"
    assert repr(ast.parse(lowercase, strict=True)) != repr(
        ast.parse(stu, strict=True))
Exemplo n.º 7
0
def test_ast_parse_strict():
    with pytest.raises(AntlrException):
        ast.parse("SELECT x FROM ____!", strict=True)  # ____! is ungrammatical
    # Test export of exception class
    with pytest.raises(ast.ParseError):
        ast.parse("SELECT x FROM ____!", strict=True)  # ____! is ungrammatical
Exemplo n.º 8
0
def test_dump(start, cmd, res):
    assert repr(ast.parse(cmd, start, strict=True)) == res
Exemplo n.º 9
0
def test_feedback_init(sql_cmd, start, pos):
    tree = ast.parse(sql_cmd, start)
    fb = Feedback("MESSAGE", tree, strict=True)
    pos_names = ['line_start', 'column_start', 'line_end', 'column_end']
    for ii, k in enumerate(pos_names):
        assert fb.line_info[k] == pos[ii]