示例#1
0
def check_compiles(dsl_expr, code):
    types = graph_types(ENV)

    expr, functions = to_expr(dsl_expr)
    env = fn_types(functions)
    env.update(types['__root__'].__field_types__)

    expr = check(expr, types, env)

    # test eval
    lambda_expr = ExpressionCompiler.compile_lambda_expr(expr)
    eval(compile(lambda_expr, '<expr>', 'eval'))

    # test compile
    py_expr = ExpressionCompiler.compile_expr(expr)

    first = astor.to_source(py_expr).strip()
    if not PY3:
        first = first.replace("u'", "'")
    second = dedent(code).strip()
    if first != second:
        msg = ('Compiled code is not equal:\n\n{}'
               .format('\n'.join(difflib.ndiff(first.splitlines(),
                                               second.splitlines()))))
        raise AssertionError(msg)
示例#2
0
def check_query(dsl_expr, query):
    expr, functions = to_expr(dsl_expr)
    env = fn_types(functions)
    env.update(ROOT_TYPES)
    expr = check(expr, TYPES, env)
    expr_reqs = RequirementsExtractor.extract(TYPES, expr)
    with reqs_eq_patcher():
        assert expr_reqs == query
示例#3
0
def check_query(dsl_expr, query):
    expr, functions = to_expr(dsl_expr)
    types = TYPES.copy()
    types.update(fn_types(functions))
    expr = check(expr, types)
    expr_reqs = RequirementsExtractor.extract(types, expr)
    with reqs_eq_patcher():
        assert expr_reqs == query
示例#4
0
def check_refs(types, expr, query_items):
    ast, functions = to_expr(expr)
    query = build(query_items)
    env = fn_types(functions)
    env.update(types['__root__'].__field_types__)
    ast = check(ast, types, env)
    expr_reqs = RequirementsExtractor.extract(types, ast)
    assert expr_reqs == query
示例#5
0
    def assertCompiles(self, dsl_expr, code):
        expr, functions = to_expr(dsl_expr)

        types = graph_types(ENV)
        types.update(fn_types(functions))

        expr = check(expr, types)

        py_expr = ExpressionCompiler.compile_expr(expr)

        first = astor.to_source(py_expr)
        if not PY3:
            first = first.replace("u'", "'")
        second = dedent(code).strip()
        if first != second:
            msg = ('Compiled code is not equal:\n\n{}'
                   .format('\n'.join(difflib.ndiff(first.splitlines(),
                                                   second.splitlines()))))
            raise self.failureException(msg)

        # test eval
        lambda_expr = ExpressionCompiler.compile_lambda_expr(expr)
        eval(compile(lambda_expr, '<expr>', 'eval'))
示例#6
0
def check_expr(expr):
    expr, functions = to_expr(expr)
    env = fn_types(functions)
    env.update(ROOT_TYPES)
    return check(expr, TYPES, env)
示例#7
0
def check_expr(types, expr):
    ast, functions = to_expr(expr)
    env = fn_types(functions)
    env.update(types['__root__'].__field_types__)
    return check(ast, types, env)
示例#8
0
def check_expr(expr):
    expr, functions = to_expr(expr)
    types = TYPES.copy()
    types.update(fn_types(functions))
    return check(expr, types)