Exemplo n.º 1
0
def test_greedy_decompose(fname, mode, type_comments, feature_version):
    ast_tree = astutils.ast_parse(fname,
                                  mode=mode,
                                  type_comments=type_comments,
                                  feature_version=feature_version)
    sourcecode = _read(fname)
    ast_heap = astutils.ast2heap(ast_tree, source=sourcecode)
    sub_heaps = astutils.greedy_decompose(ast_heap)
Exemplo n.º 2
0
def test_ast2dict_dict2ast(fname, mode, type_comments, feature_version):
    ast_tree1 = astutils.ast_parse(fname,
                                   mode=mode,
                                   type_comments=type_comments,
                                   feature_version=feature_version)
    ast_dict = astutils.ast2dict(ast_tree1)
    ast_tree2 = astutils.dict2ast(ast_dict)
    ast_dict2 = astutils.ast2dict(ast_tree2)

    assert _check_instances(ast_dict, ast_dict2)
Exemplo n.º 3
0
def test_ast_unparse(fname, mode, type_comments, feature_version):
    ast_tree = astutils.ast_parse(fname,
                                  mode=mode,
                                  type_comments=type_comments,
                                  feature_version=feature_version)
    if sys.version_info < (3, 9):
        with pytest.raises(Exception):
            astutils.ast_unparse(ast_tree)
    else:
        astutils.ast_unparse(ast_tree)
Exemplo n.º 4
0
def test_ast2heap_heap2code(fname, mode, type_comments, feature_version):
    ast_tree = astutils.ast_parse(fname,
                                  mode=mode,
                                  type_comments=type_comments,
                                  feature_version=feature_version)
    sourcecode = _read(fname)

    ast_heap = astutils.ast2heap(ast_tree, source=sourcecode)
    source_code_1 = astutils.heap2code(ast_heap)

    assert _check_instances(sourcecode, source_code_1)
Exemplo n.º 5
0
def test_ast2heap_heap2tokens(fname, mode, type_comments, feature_version):
    ast_tree = astutils.ast_parse(fname,
                                  mode=mode,
                                  type_comments=type_comments,
                                  feature_version=feature_version)
    sourcecode = _read(fname)

    ast_heap = astutils.ast2heap(ast_tree, source=sourcecode)
    tokens = astutils.heap2tokens(ast_heap)

    source_code_1 = "".join([token["tok"] for token in tokens])

    assert _check_instances(sourcecode, source_code_1)
Exemplo n.º 6
0
def test_ast_parse(fname, mode, type_comments, feature_version):
    astutils.ast_parse(fname,
                       mode=mode,
                       type_comments=type_comments,
                       feature_version=feature_version)