@@ -2,47 +2,43 @@ import * as assert from 'assert';
22import * as fs from 'fs' ;
33import * as path from 'path' ;
44import * as vscode from 'vscode' ;
5- import { clearPythonPathInWorkspaceFolder } from './common' ;
5+ import { PythonSettings } from '../client/common/configSettings' ;
6+ import { activated } from '../client/extension' ;
7+ import { clearPythonPathInWorkspaceFolder , setPythonPathInWorkspaceRoot } from './common' ;
8+
69const dummyPythonFile = path . join ( __dirname , '..' , '..' , 'src' , 'test' , 'pythonFiles' , 'dummy.py' ) ;
710
8- //First thing to be executed
11+ //First thing to be executed.
912// tslint:disable-next-line:no-string-literal
1013process . env [ 'VSC_PYTHON_CI_TEST' ] = '1' ;
1114
12- // tslint:disable-next-line:no-any
13- let configSettings : any ;
14- let extensionActivated : boolean = false ;
15+ const PYTHON_PATH = getPythonPath ( ) ;
16+ // tslint:disable-next-line:no-string-literal prefer-template
17+ export const IS_TRAVIS = ( process . env [ 'TRAVIS' ] + '' ) === 'true' ;
18+ export const TEST_TIMEOUT = 25000 ;
19+ export const IS_MULTI_ROOT_TEST = isMultitrootTest ( ) ;
20+
21+ // Ability to use custom python environments for testing
22+ export async function initializePython ( ) {
23+ await clearPythonPathInWorkspaceFolder ( dummyPythonFile ) ;
24+ await setPythonPathInWorkspaceRoot ( PYTHON_PATH ) ;
25+ }
26+
1527// tslint:disable-next-line:no-any
1628export async function initialize ( ) : Promise < any > {
1729 await initializePython ( ) ;
1830 // Opening a python file activates the extension.
1931 await vscode . workspace . openTextDocument ( dummyPythonFile ) ;
20- if ( ! extensionActivated ) {
21- // tslint:disable-next-line:no-require-imports
22- const ext = require ( '../client/extension' ) ;
23- // tslint:disable-next-line:no-unsafe-any
24- await ext . activated ;
25- extensionActivated = true ;
26- }
27- if ( ! configSettings ) {
28- // tslint:disable-next-line:no-require-imports
29- configSettings = await require ( '../client/common/configSettings' ) ;
30- }
32+ await activated ;
3133 // Dispose any cached python settings (used only in test env).
32- // tslint:disable-next-line:no-unsafe-any)
33- configSettings . PythonSettings . dispose ( ) ;
34+ PythonSettings . dispose ( ) ;
3435}
3536// tslint:disable-next-line:no-any
3637export async function initializeTest ( ) : Promise < any > {
3738 await initializePython ( ) ;
3839 await closeActiveWindows ( ) ;
39- if ( ! configSettings ) {
40- // tslint:disable-next-line:no-require-imports no-unsafe-any
41- configSettings = await require ( '../client/common/configSettings' ) ;
42- }
43- // Dispose any cached python settings (used only in test env)
44- // tslint:disable-next-line:no-unsafe-any
45- configSettings . PythonSettings . dispose ( ) ;
40+ // Dispose any cached python settings (used only in test env).
41+ PythonSettings . dispose ( ) ;
4642}
4743
4844export async function wait ( timeoutMilliseconds : number ) {
@@ -101,27 +97,3 @@ function getPythonPath(): string {
10197function isMultitrootTest ( ) {
10298 return Array . isArray ( vscode . workspace . workspaceFolders ) && vscode . workspace . workspaceFolders . length > 1 ;
10399}
104-
105- const PYTHON_PATH = getPythonPath ( ) ;
106- // tslint:disable-next-line:no-string-literal prefer-template
107- export const IS_TRAVIS = ( process . env [ 'TRAVIS' ] + '' ) === 'true' ;
108- export const TEST_TIMEOUT = 25000 ;
109- export const IS_MULTI_ROOT_TEST = isMultitrootTest ( ) ;
110-
111- // Ability to use custom python environments for testing
112- export async function initializePython ( ) {
113- await clearPythonPathInWorkspaceFolder ( dummyPythonFile ) ;
114-
115- const pythonConfig = vscode . workspace . getConfiguration ( 'python' ) ;
116- const value = pythonConfig . inspect ( 'pythonPath' ) ;
117- if ( value && value . workspaceValue !== PYTHON_PATH ) {
118- await pythonConfig . update ( 'pythonPath' , PYTHON_PATH , vscode . ConfigurationTarget . Workspace ) ;
119- if ( ! configSettings ) {
120- // tslint:disable-next-line:no-require-imports no-unsafe-any
121- configSettings = await require ( '../client/common/configSettings' ) ;
122- }
123- // Dispose any cached python settings (used only in test env)
124- // tslint:disable-next-line:no-unsafe-any
125- configSettings . PythonSettings . dispose ( ) ;
126- }
127- }
0 commit comments