@@ -17,10 +17,18 @@ class Test2(Test1):
1717 pass
1818'''
1919
20+ DOC_NAME_EXTRA = 'test2.py'
21+ DOC_EXTRA = '''from test1 import Test1
22+ x = Test1()
23+ '''
24+
2025
2126@pytest .fixture
2227def tmp_workspace (temp_workspace_factory ):
23- return temp_workspace_factory ({DOC_NAME : DOC })
28+ return temp_workspace_factory ({
29+ DOC_NAME : DOC ,
30+ DOC_NAME_EXTRA : DOC_EXTRA
31+ })
2432
2533
2634@pytest .mark .skipif (LT_PY36 , reason = 'Jedi refactoring isnt supported on Python 2.x/3.5' )
@@ -34,10 +42,11 @@ def test_jedi_rename(tmp_workspace, config): # pylint: disable=redefined-outer-
3442 assert len (result .keys ()) == 1
3543
3644 changes = result .get ('documentChanges' )
37- assert len (changes ) == 1
38- changes = changes [0 ]
45+ assert len (changes ) == 2
3946
40- assert changes .get ('edits' ) == [
47+ assert changes [0 ]['textDocument' ]['uri' ] == doc .uri
48+ assert changes [0 ]['textDocument' ]['version' ] == doc .version
49+ assert changes [0 ].get ('edits' ) == [
4150 {
4251 'range' : {
4352 'start' : {'line' : 0 , 'character' : 0 },
@@ -46,3 +55,23 @@ def test_jedi_rename(tmp_workspace, config): # pylint: disable=redefined-outer-
4655 'newText' : 'class ShouldBeRenamed():\n pass\n \n class Test2(ShouldBeRenamed):\n pass\n ' ,
4756 }
4857 ]
58+ path = os .path .join (tmp_workspace .root_path , DOC_NAME_EXTRA )
59+ uri_extra = uris .from_fs_path (path )
60+ assert changes [1 ]['textDocument' ]['uri' ] == uri_extra
61+ # This also checks whether documents not yet added via textDocument/didOpen
62+ # but that do need to be renamed in the project have a `null` version
63+ # number.
64+ assert changes [1 ]['textDocument' ]['version' ] is None
65+ expected = 'from test1 import ShouldBeRenamed\n x = ShouldBeRenamed()\n '
66+ if os .name == 'nt' :
67+ # The .write method in the temp_workspace_factory functions writes
68+ # Windows-style line-endings.
69+ expected = expected .replace ('\n ' , '\r \n ' )
70+ assert changes [1 ].get ('edits' ) == [
71+ {
72+ 'range' : {
73+ 'start' : {'line' : 0 , 'character' : 0 },
74+ 'end' : {'line' : 2 , 'character' : 0 }},
75+ 'newText' : expected
76+ }
77+ ]
0 commit comments