Skip to content

Commit e78ccec

Browse files
authored
Add missing test for rope_rename.pys (#780)
1 parent 2796154 commit e78ccec

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/plugins/test_rope_rename.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
3+
import pytest
4+
from pyls import uris
5+
from pyls.plugins.rope_rename import pyls_rename
6+
from pyls.workspace import Document
7+
8+
DOC_NAME = "test1.py"
9+
DOC = """class Test1():
10+
pass
11+
12+
class Test2(Test1):
13+
pass
14+
"""
15+
16+
17+
@pytest.fixture
18+
def tmp_workspace(workspace):
19+
def create_file(name, content):
20+
fn = os.path.join(workspace.root_path, name)
21+
with open(fn, "w") as f:
22+
f.write(content)
23+
workspace.put_document(uris.from_fs_path(fn), content)
24+
25+
create_file(DOC_NAME, DOC)
26+
return workspace
27+
28+
29+
def test_rope_rename(tmp_workspace, config): # pylint: disable=redefined-outer-name
30+
position = {"line": 0, "character": 6}
31+
DOC_URI = uris.from_fs_path(os.path.join(tmp_workspace.root_path, DOC_NAME))
32+
doc = Document(DOC_URI)
33+
34+
result = pyls_rename(config, tmp_workspace, doc, position, "ShouldBeRenamed")
35+
assert len(result.keys()) == 1
36+
37+
changes = result.get("documentChanges")
38+
assert len(changes) == 1
39+
changes = changes[0]
40+
41+
assert changes.get("edits") == [
42+
{
43+
"range": {
44+
"start": {"line": 0, "character": 0},
45+
"end": {"line": 5, "character": 0},
46+
},
47+
"newText": "class ShouldBeRenamed():\n pass\n\nclass Test2(ShouldBeRenamed):\n pass\n",
48+
}
49+
]

0 commit comments

Comments
 (0)