예제 #1
0
def test_tc_09_any_function_uma_instrucao_existe():
    str_source = """
print("String")
def ola_mundo():
    a = 10
string = "String"
        """

    str_pattern = """
anyFunction("String")
        """
    source = ast.parse(str_source)
    pattern = ast.parse(str_pattern)

    tree = SourceTree(source)

    ERR_MESSAGE = "A AST do codigo fonte deveria conter o padrão"

    positions = tree.get_simple_position_pattern(pattern)
    print(positions)
    assert [[({
        'lineno': 2,
        'col_offset': 0
    }, {
        'lineno': 2,
        'col_offset': 0
    })]] == positions
    assert True == (len(tree.get_all_occurrences(pattern)) == 1), ERR_MESSAGE
예제 #2
0
def test_tc_07_wildcards_some_variable_multiplas_instrucoes_existe():
    str_source = """
def ola_mundo(): 
    a = 10
    print(a)
        """

    str_pattern = """
someVariableA = 10
print(someVariableA)
        """
    source = ast.parse(str_source)
    pattern = ast.parse(str_pattern)

    tree = SourceTree(source)

    ERR_MESSAGE = "A AST do codigo fonte deveria conter o padrão"

    positions = tree.get_simple_position_pattern(pattern)
    print(positions)
    assert [[({
        'col_offset': 4,
        'lineno': 3
    }, {
        'col_offset': 8,
        'lineno': 3
    }), ({
        'col_offset': 4,
        'lineno': 4
    }, {
        'col_offset': 4,
        'lineno': 4
    })]] == positions
    assert True == (len(tree.get_all_occurrences(pattern)) == 1), ERR_MESSAGE
예제 #3
0
def test_tc06_wildcards_any_variable_uma_variavel_existe():
    str_source = """
print("String")
def ola_mundo():
    a = 10
string = "String"
    """

    str_pattern = """
anyVariable = 10
    """
    source = ast.parse(str_source)
    pattern = ast.parse(str_pattern)

    tree = SourceTree(source)

    ERR_MESSAGE = "A AST do codigo fonte deveria conter o padrão"

    positions = tree.get_simple_position_pattern(pattern)
    print(positions)
    assert [[({
        'lineno': 4,
        'col_offset': 4
    }, {
        'lineno': 4,
        'col_offset': 8
    })]] == positions
    assert True == (len(tree.get_all_occurrences(pattern)) == 1), ERR_MESSAGE
예제 #4
0
def test_tc_16_any_literal_value_uma_instrucao_nao_existe():
    str_source = """
a = 'valorLiteral'
                """

    str_pattern = """
a = 'anyNumber'
                """
    source = ast.parse(str_source)
    pattern = ast.parse(str_pattern)

    tree = SourceTree(source)

    ERR_MESSAGE = "A AST do codigo fonte nao deveria conter o padrão"

    assert True == (len(tree.get_all_occurrences(pattern)) == 0), ERR_MESSAGE
예제 #5
0
def test_tc_08_wildcards_some_variable_multiplas_instrucoes_nao_existe():
    str_source = """
def ola_mundo(): 
    a = 10
    print(b)
        """

    str_pattern = """
someVariableA = 10
print(someVariableA)
        """
    source = ast.parse(str_source)
    pattern = ast.parse(str_pattern)

    tree = SourceTree(source)

    ERR_MESSAGE = "A AST do codigo fonte deveria conter o padrão"

    positions = tree.get_simple_position_pattern(pattern)
    assert True == (len(tree.get_all_occurrences(pattern)) == 0), ERR_MESSAGE
예제 #6
0
def test_tc_13_multiplas_ocorrencias_multiplas_instrucoes():
    str_source = """
def ola_mundo():
    a = 'texto'
    
    a = 'texto1'
    
    a = 'texto2'
                    """

    str_pattern = """
a = 'anyLiteralValue'
                    """
    source = ast.parse(str_source)
    pattern = ast.parse(str_pattern)

    tree = SourceTree(source)

    ERR_MESSAGE = "A AST do codigo fonte deveria conter 3 instancias do padrão"
    ERR_MESSAGE_POSITION = "As posiccoes do padrao nao coincidem "
    position = tree.get_simple_position_pattern(pattern)
    assert [[({
        'lineno': 3,
        'col_offset': 4
    }, {
        'lineno': 3,
        'col_offset': 8
    })], [({
        'lineno': 5,
        'col_offset': 4
    }, {
        'lineno': 5,
        'col_offset': 8
    })], [({
        'lineno': 7,
        'col_offset': 4
    }, {
        'lineno': 7,
        'col_offset': 8
    })]] == position, ERR_MESSAGE_POSITION
    assert True == (len(tree.get_all_occurrences(pattern)) == 3), ERR_MESSAGE
예제 #7
0
def test_tc_11_some_function_multiplas_intrucoes_nao_existe():
    str_source = """
print("String")
def ola_mundo():
    a = 10
    metodo("String")
    outroMetodo("String")
string = "String"
                """

    str_pattern = """
someFunction("String")
someFunction("String")
                """
    source = ast.parse(str_source)
    pattern = ast.parse(str_pattern)

    tree = SourceTree(source)

    ERR_MESSAGE = "A AST do codigo fonte nao deveria conter o padrão"

    assert True == (len(tree.get_all_occurrences(pattern)) == 0), ERR_MESSAGE
예제 #8
0
def test_tc_15_any_literal_value_uma_instrucao_existe():
    str_source = """
a = 10
                """

    str_pattern = """
a = 'anyNumber'
                """
    source = ast.parse(str_source)
    pattern = ast.parse(str_pattern)

    tree = SourceTree(source)

    ERR_MESSAGE = "A AST do codigo fonte deveria conter o padrão"
    position = tree.get_simple_position_pattern(pattern)
    assert [[({
        'lineno': 2,
        'col_offset': 0
    }, {
        'lineno': 2,
        'col_offset': 4
    })]] == position
    assert True == (len(tree.get_all_occurrences(pattern)) == 1), ERR_MESSAGE
예제 #9
0
def test_tc_10_some_function_multiplas_instrucoes_existe():
    str_source = """
print("String")
def ola_mundo():
    a = 10
    print("String")
    print("String")
string = "String"
            """

    str_pattern = """
someFunction("String")
someFunction("String")
            """
    source = ast.parse(str_source)
    pattern = ast.parse(str_pattern)

    tree = SourceTree(source)

    ERR_MESSAGE = "A AST do codigo fonte deveria conter o padrão"

    positions = tree.get_simple_position_pattern(pattern)
    print(positions)
    assert [[({
        'lineno': 5,
        'col_offset': 4
    }, {
        'lineno': 5,
        'col_offset': 4
    }), ({
        'lineno': 6,
        'col_offset': 4
    }, {
        'lineno': 6,
        'col_offset': 4
    })]] == positions
    assert True == (len(tree.get_all_occurrences(pattern)) == 1), ERR_MESSAGE