3
3
4
4
5
5
// Place this right on top
6
- import { initialize , PYTHON_PATH , closeActiveWindows } from '../initialize' ;
6
+ import { initialize , PYTHON_PATH , closeActiveWindows , setPythonExecutable } from '../initialize' ;
7
7
// The module 'assert' provides assertion methods from node
8
8
import * as assert from 'assert' ;
9
9
import { EOL } from 'os' ;
@@ -12,22 +12,29 @@ import { EOL } from 'os';
12
12
import * as vscode from 'vscode' ;
13
13
import * as path from 'path' ;
14
14
import * as settings from '../../client/common/configSettings' ;
15
+ import { execPythonFile } from '../../client/common/utils' ;
16
+ import { createDeferred } from '../../client/common/helpers' ;
15
17
16
18
let pythonSettings = settings . PythonSettings . getInstance ( ) ;
19
+ let disposable : vscode . Disposable ;
17
20
let autoCompPath = path . join ( __dirname , '..' , '..' , '..' , 'src' , 'test' , 'pythonFiles' , 'definition' ) ;
18
21
const fileOne = path . join ( autoCompPath , 'one.py' ) ;
19
22
const fileTwo = path . join ( autoCompPath , 'two.py' ) ;
20
23
const fileThree = path . join ( autoCompPath , 'three.py' ) ;
21
24
const fileDecorator = path . join ( autoCompPath , 'decorators.py' ) ;
25
+ const fileAwait = path . join ( autoCompPath , 'await.test.py' ) ;
22
26
const fileEncoding = path . join ( autoCompPath , 'four.py' ) ;
23
27
const fileEncodingUsed = path . join ( autoCompPath , 'five.py' ) ;
24
28
29
+
25
30
suite ( 'Code Definition' , ( ) => {
26
- suiteSetup ( done => {
27
- initialize ( ) . then ( ( ) => {
28
- pythonSettings . pythonPath = PYTHON_PATH ;
29
- done ( ) ;
30
- } , done ) ;
31
+ const isPython3Deferred = createDeferred < boolean > ( ) ;
32
+ const isPython3 = isPython3Deferred . promise ;
33
+ suiteSetup ( async ( ) => {
34
+ disposable = setPythonExecutable ( pythonSettings ) ;
35
+ await initialize ( ) ;
36
+ let version = await execPythonFile ( pythonSettings . pythonPath , [ '--version' ] , __dirname , true ) ;
37
+ isPython3Deferred . resolve ( version . indexOf ( '3.' ) >= 0 ) ;
31
38
} ) ;
32
39
33
40
suiteTeardown ( done => {
@@ -50,6 +57,7 @@ suite('Code Definition', () => {
50
57
return vscode . commands . executeCommand < vscode . Location [ ] > ( 'vscode.executeDefinitionProvider' , textDocument . uri , position ) ;
51
58
} ) . then ( def => {
52
59
assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
60
+ assert . equal ( def [ 0 ] . uri . fsPath , fileOne , 'Incorrect file' ) ;
53
61
assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '17,4' , 'Start position is incorrect' ) ;
54
62
assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '21,11' , 'End position is incorrect' ) ;
55
63
} ) . then ( done , done ) ;
@@ -68,6 +76,7 @@ suite('Code Definition', () => {
68
76
return vscode . commands . executeCommand < vscode . Location [ ] > ( 'vscode.executeDefinitionProvider' , textDocument . uri , position ) ;
69
77
} ) . then ( def => {
70
78
assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
79
+ assert . equal ( def [ 0 ] . uri . fsPath , fileOne , 'Incorrect file' ) ;
71
80
assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '32,0' , 'Start position is incorrect' ) ;
72
81
assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '33,21' , 'End position is incorrect' ) ;
73
82
} ) . then ( done , done ) ;
@@ -79,10 +88,32 @@ suite('Code Definition', () => {
79
88
const position = new vscode . Position ( 7 , 2 ) ;
80
89
const def = await vscode . commands . executeCommand < vscode . Location [ ] > ( 'vscode.executeDefinitionProvider' , textDocument . uri , position ) ;
81
90
assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
91
+ assert . equal ( def [ 0 ] . uri . fsPath , fileDecorator , 'Incorrect file' ) ;
82
92
assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '4,0' , 'Start position is incorrect' ) ;
83
93
assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '5,22' , 'End position is incorrect' ) ;
84
94
} ) ;
85
95
96
+ test ( 'Go to function with decorator (jit)' , async ( ) => {
97
+ const textDocument = await vscode . workspace . openTextDocument ( fileDecorator ) ;
98
+ await vscode . window . showTextDocument ( textDocument ) ;
99
+ const position = new vscode . Position ( 27 , 2 ) ;
100
+ const def = await vscode . commands . executeCommand < vscode . Location [ ] > ( 'vscode.executeDefinitionProvider' , textDocument . uri , position ) ;
101
+ assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
102
+ assert . equal ( def [ 0 ] . uri . fsPath , fileDecorator , 'Incorrect file' ) ;
103
+ assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '19,0' , 'Start position is incorrect' ) ;
104
+ assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '26,42' , 'End position is incorrect' ) ;
105
+ } ) ;
106
+
107
+ test ( 'Go to function with decorator (fabric)' , async ( ) => {
108
+ const textDocument = await vscode . workspace . openTextDocument ( fileDecorator ) ;
109
+ await vscode . window . showTextDocument ( textDocument ) ;
110
+ const position = new vscode . Position ( 13 , 2 ) ;
111
+ const def = await vscode . commands . executeCommand < vscode . Location [ ] > ( 'vscode.executeDefinitionProvider' , textDocument . uri , position ) ;
112
+ assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
113
+ assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '19,0' , 'Start position is incorrect' ) ;
114
+ assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '26,42' , 'End position is incorrect' ) ;
115
+ } ) ;
116
+
86
117
test ( 'Go to function decorator' , async ( ) => {
87
118
const textDocument = await vscode . workspace . openTextDocument ( fileDecorator ) ;
88
119
await vscode . window . showTextDocument ( textDocument ) ;
@@ -93,6 +124,34 @@ suite('Code Definition', () => {
93
124
assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '1,12' , 'End position is incorrect' ) ;
94
125
} ) ;
95
126
127
+ test ( 'Go to async method' , async ( ) => {
128
+ if ( ! await isPython3 ) {
129
+ return ;
130
+ }
131
+ const textDocument = await vscode . workspace . openTextDocument ( fileAwait ) ;
132
+ await vscode . window . showTextDocument ( textDocument ) ;
133
+ const position = new vscode . Position ( 10 , 22 ) ;
134
+ const def = await vscode . commands . executeCommand < vscode . Location [ ] > ( 'vscode.executeDefinitionProvider' , textDocument . uri , position ) ;
135
+ assert . equal ( def . length , 1 , 'Definition length is incorrect (currently not working)' ) ;
136
+ assert . equal ( def [ 0 ] . uri . fsPath , fileAwait , 'Wrong file (currently not working)' ) ;
137
+ assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '6,10' , 'Start position is incorrect (currently not working)' ) ;
138
+ assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '1,12' , 'End position is incorrect (currently not working)' ) ;
139
+ } ) ;
140
+
141
+ test ( 'Go to async function' , async ( ) => {
142
+ if ( ! await isPython3 ) {
143
+ return ;
144
+ }
145
+ const textDocument = await vscode . workspace . openTextDocument ( fileAwait ) ;
146
+ await vscode . window . showTextDocument ( textDocument ) ;
147
+ const position = new vscode . Position ( 18 , 12 ) ;
148
+ const def = await vscode . commands . executeCommand < vscode . Location [ ] > ( 'vscode.executeDefinitionProvider' , textDocument . uri , position ) ;
149
+ assert . equal ( def . length , 1 , 'Definition length is incorrect (currently not working)' ) ;
150
+ assert . equal ( def [ 0 ] . uri . fsPath , fileAwait , 'Wrong file (currently not working)' ) ;
151
+ assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '6,10' , 'Start position is incorrect (currently not working)' ) ;
152
+ assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '1,12' , 'End position is incorrect (currently not working)' ) ;
153
+ } ) ;
154
+
96
155
test ( 'Across files' , done => {
97
156
let textEditor : vscode . TextEditor ;
98
157
let textDocument : vscode . TextDocument ;
0 commit comments