예제 #1
0
def test_rename_across_files():
    files = {
        'foo': dedent(
            """
            def old():
                pass
            """),
        'bar': dedent(
            """
            from foo import old
            old()
            """)}

    refactoring = Rename(files={m: f.split('\n') for m, f in files.items()})
    refactoring.initialize(
        module='bar',
        position=Position(row=2, column=0),
        old_name='old',
        new_name='new')
    refactoring.apply()
    assert refactoring.get_result('foo') == dedent("""
        def new():
            pass
        """)
    assert refactoring.get_result('bar') == dedent("""
        from foo import new
        new()
        """)
예제 #2
0
def rename(source, cursor, old_name, new_name):
    refactoring = Rename(files={'module': source.split('\n')})
    refactoring.initialize(
        module='module',
        position=cursor,
        old_name=old_name,
        new_name=new_name)
    refactoring.apply()
    return refactoring.get_result('module')
예제 #3
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)
예제 #4
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'))