File: test_rename.py

package info (click to toggle)
python-lsp-rope 0.1.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 340 kB
  • sloc: python: 2,319; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 2,467 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pytest
from pylsp_rope import typing
from pylsp_rope.plugin import pylsp_rename
from pylsp_rope.text import Position
from test.conftest import create_document
from test.helpers import assert_text_edits, assert_modified_documents


@pytest.fixture(autouse=True)
def enable_pylsp_rope_rename_plugin(config):
    config._plugin_settings["plugins"]["pylsp_rope"] = {"rename": True}
    return config


def test_rope_rename(config, workspace) -> None:
    document = create_document(workspace, "simple_rename.py")
    extra_document = create_document(workspace, "simple_rename_extra.py")
    line = 0
    pos = document.lines[line].index("Test1")
    position = Position(line, pos)

    response: typing.SimpleWorkspaceEdit = pylsp_rename(config, workspace, document, position, "ShouldBeRenamed")
    assert len(response.keys()) == 1

    assert_modified_documents(response, {document.uri, extra_document.uri})

    new_text = assert_text_edits(
        response["changes"][document.uri], target="simple_rename_result.py"
    )
    assert "class ShouldBeRenamed()" in new_text
    assert "class Test2(ShouldBeRenamed)" in new_text

    new_text = assert_text_edits(
        response["changes"][extra_document.uri], target="simple_rename_extra_result.py"
    )
    assert "from simple_rename import ShouldBeRenamed" in new_text
    assert "x = ShouldBeRenamed()" in new_text


def test_rope_rename_disabled(config, workspace) -> None:
    document = create_document(workspace, "simple_rename.py")
    extra_document = create_document(workspace, "simple_rename_extra.py")
    line = 0
    pos = document.lines[line].index("Test1")
    position = Position(line, pos)

    plugin_settings = config.plugin_settings("pylsp_rope", document.uri)
    plugin_settings["rename"] = False

    response: typing.SimpleWorkspaceEdit = pylsp_rename(config, workspace, document, position, "ShouldBeRenamed")

    assert response is None


def test_rope_rename_missing_key(config, workspace) -> None:
    document = create_document(workspace, "simple_rename.py")
    extra_document = create_document(workspace, "simple_rename_extra.py")
    line = 0
    pos = document.lines[line].index("Test1")
    position = Position(line, pos)

    plugin_settings = config.plugin_settings("pylsp_rope", document.uri)
    del plugin_settings["rename"]

    response: typing.SimpleWorkspaceEdit = pylsp_rename(config, workspace, document, position, "ShouldBeRenamed")

    assert response is None