33
44
55// Place this right on top
6- import { initialize , PYTHON_PATH , closeActiveWindows } from '../initialize' ;
6+ import { initialize , PYTHON_PATH , closeActiveWindows , setPythonExecutable } from '../initialize' ;
77// The module 'assert' provides assertion methods from node
88import * as assert from 'assert' ;
99import { EOL } from 'os' ;
@@ -12,22 +12,29 @@ import { EOL } from 'os';
1212import * as vscode from 'vscode' ;
1313import * as path from 'path' ;
1414import * as settings from '../../client/common/configSettings' ;
15+ import { execPythonFile } from '../../client/common/utils' ;
16+ import { createDeferred } from '../../client/common/helpers' ;
1517
1618let pythonSettings = settings . PythonSettings . getInstance ( ) ;
19+ let disposable : vscode . Disposable ;
1720let autoCompPath = path . join ( __dirname , '..' , '..' , '..' , 'src' , 'test' , 'pythonFiles' , 'definition' ) ;
1821const fileOne = path . join ( autoCompPath , 'one.py' ) ;
1922const fileTwo = path . join ( autoCompPath , 'two.py' ) ;
2023const fileThree = path . join ( autoCompPath , 'three.py' ) ;
2124const fileDecorator = path . join ( autoCompPath , 'decorators.py' ) ;
25+ const fileAwait = path . join ( autoCompPath , 'await.test.py' ) ;
2226const fileEncoding = path . join ( autoCompPath , 'four.py' ) ;
2327const fileEncodingUsed = path . join ( autoCompPath , 'five.py' ) ;
2428
29+
2530suite ( '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 ) ;
3138 } ) ;
3239
3340 suiteTeardown ( done => {
@@ -50,6 +57,7 @@ suite('Code Definition', () => {
5057 return vscode . commands . executeCommand < vscode . Location [ ] > ( 'vscode.executeDefinitionProvider' , textDocument . uri , position ) ;
5158 } ) . then ( def => {
5259 assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
60+ assert . equal ( def [ 0 ] . uri . fsPath , fileOne , 'Incorrect file' ) ;
5361 assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '17,4' , 'Start position is incorrect' ) ;
5462 assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '21,11' , 'End position is incorrect' ) ;
5563 } ) . then ( done , done ) ;
@@ -68,6 +76,7 @@ suite('Code Definition', () => {
6876 return vscode . commands . executeCommand < vscode . Location [ ] > ( 'vscode.executeDefinitionProvider' , textDocument . uri , position ) ;
6977 } ) . then ( def => {
7078 assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
79+ assert . equal ( def [ 0 ] . uri . fsPath , fileOne , 'Incorrect file' ) ;
7180 assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '32,0' , 'Start position is incorrect' ) ;
7281 assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '33,21' , 'End position is incorrect' ) ;
7382 } ) . then ( done , done ) ;
@@ -79,10 +88,32 @@ suite('Code Definition', () => {
7988 const position = new vscode . Position ( 7 , 2 ) ;
8089 const def = await vscode . commands . executeCommand < vscode . Location [ ] > ( 'vscode.executeDefinitionProvider' , textDocument . uri , position ) ;
8190 assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
91+ assert . equal ( def [ 0 ] . uri . fsPath , fileDecorator , 'Incorrect file' ) ;
8292 assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '4,0' , 'Start position is incorrect' ) ;
8393 assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '5,22' , 'End position is incorrect' ) ;
8494 } ) ;
8595
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+
86117 test ( 'Go to function decorator' , async ( ) => {
87118 const textDocument = await vscode . workspace . openTextDocument ( fileDecorator ) ;
88119 await vscode . window . showTextDocument ( textDocument ) ;
@@ -93,6 +124,34 @@ suite('Code Definition', () => {
93124 assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '1,12' , 'End position is incorrect' ) ;
94125 } ) ;
95126
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+
96155 test ( 'Across files' , done => {
97156 let textEditor : vscode . TextEditor ;
98157 let textDocument : vscode . TextDocument ;
0 commit comments