Esempio n. 1
0
def do_rename(buffer_contents, old_name, row, column, new_name):
    module_name = "module"
    refactoring = Rename(files={module_name: buffer_contents})
    refactoring.initialize(
        module=module_name, position=Position(row=row, column=column), old_name=old_name, new_name=new_name
    )
    refactoring.apply()
    for i, line in refactoring.get_changes(module_name):
        if buffer_contents[i] != line:
            yield (i, line)
Esempio n. 2
0
def test_renames_function_from_lines():
    refactoring = Rename(
        files={'module': [
            "def fun_old():",
            "    return 'result'",
            "result = fun_old()"]})
    refactoring.initialize(
        module='module',
        position=Position(row=0, column=4),
        old_name='fun_old',
        new_name='fun_new')

    refactoring.apply()

    assert [
        (0, "def fun_new():"),
        (2, "result = fun_new()")] == list(refactoring.get_changes('module'))