@@ -11,12 +11,10 @@ import * as typemoq from 'typemoq';
1111import { ConfigurationChangeEvent , FileSystemWatcher , Uri } from 'vscode' ;
1212import { IWorkspaceService } from '../../../client/common/application/types' ;
1313import { WorkspaceService } from '../../../client/common/application/workspace' ;
14- import { PythonSettings } from '../../../client/common/configSettings' ;
15- import { ConfigurationService } from '../../../client/common/configuration/service' ;
1614import { PlatformService } from '../../../client/common/platform/platformService' ;
1715import { IPlatformService } from '../../../client/common/platform/types' ;
1816import { CurrentProcess } from '../../../client/common/process/currentProcess' ;
19- import { IConfigurationService , ICurrentProcess , IPythonSettings } from '../../../client/common/types' ;
17+ import { ICurrentProcess } from '../../../client/common/types' ;
2018import { sleep } from '../../../client/common/utils/async' ;
2119import { EnvironmentVariablesService } from '../../../client/common/variables/environment' ;
2220import { EnvironmentVariablesProvider } from '../../../client/common/variables/environmentVariablesProvider' ;
@@ -29,26 +27,27 @@ suite('Multiroot Environment Variables Provider', () => {
2927 let envVarsService : IEnvironmentVariablesService ;
3028 let platform : IPlatformService ;
3129 let workspace : IWorkspaceService ;
32- let configuration : IConfigurationService ;
3330 let currentProcess : ICurrentProcess ;
34- let settings : IPythonSettings ;
31+ let envFile : string ;
3532
3633 setup ( ( ) => {
34+ envFile = '' ;
3735 envVarsService = mock ( EnvironmentVariablesService ) ;
3836 platform = mock ( PlatformService ) ;
3937 workspace = mock ( WorkspaceService ) ;
40- configuration = mock ( ConfigurationService ) ;
4138 currentProcess = mock ( CurrentProcess ) ;
42- settings = mock ( PythonSettings ) ;
4339
44- when ( configuration . getSettings ( anything ( ) ) ) . thenReturn ( instance ( settings ) ) ;
4540 when ( workspace . onDidChangeConfiguration ) . thenReturn ( noop as any ) ;
41+ when ( workspace . getConfiguration ( 'python' , anything ( ) ) ) . thenReturn ( {
42+ get : ( settingName : string ) => {
43+ return settingName === 'envFile' ? envFile : '' ;
44+ } ,
45+ } as any ) ;
4646 provider = new EnvironmentVariablesProvider (
4747 instance ( envVarsService ) ,
4848 [ ] ,
4949 instance ( platform ) ,
5050 instance ( workspace ) ,
51- instance ( configuration ) ,
5251 instance ( currentProcess ) ,
5352 ) ;
5453
@@ -198,62 +197,56 @@ suite('Multiroot Environment Variables Provider', () => {
198197 } ) ;
199198
200199 test ( `Getting environment variables (without an envfile, without PATH in current env, without PYTHONPATH in current env) & ${ workspaceTitle } ` , async ( ) => {
201- const envFile = path . join ( 'a' , 'b' , 'env.file' ) ;
200+ envFile = path . join ( 'a' , 'b' , 'env.file' ) ;
202201 const workspaceFolder = workspaceUri ? { name : '' , index : 0 , uri : workspaceUri } : undefined ;
203202 const currentProcEnv = { SOMETHING : 'wow' } ;
204203
205204 when ( currentProcess . env ) . thenReturn ( currentProcEnv ) ;
206- when ( settings . envFile ) . thenReturn ( envFile ) ;
207205 when ( workspace . getWorkspaceFolder ( workspaceUri ) ) . thenReturn ( workspaceFolder ) ;
208206 when ( envVarsService . parseFile ( envFile , currentProcEnv ) ) . thenResolve ( undefined ) ;
209207 when ( platform . pathVariableName ) . thenReturn ( 'PATH' ) ;
210208
211209 const vars = await provider . getEnvironmentVariables ( workspaceUri ) ;
212210
213211 verify ( currentProcess . env ) . atLeast ( 1 ) ;
214- verify ( settings . envFile ) . atLeast ( 1 ) ;
215212 verify ( envVarsService . parseFile ( envFile , currentProcEnv ) ) . atLeast ( 1 ) ;
216213 verify ( envVarsService . mergeVariables ( deepEqual ( currentProcEnv ) , deepEqual ( { } ) ) ) . once ( ) ;
217214 verify ( platform . pathVariableName ) . atLeast ( 1 ) ;
218215 assert . deepEqual ( vars , { } ) ;
219216 } ) ;
220217 test ( `Getting environment variables (with an envfile, without PATH in current env, without PYTHONPATH in current env) & ${ workspaceTitle } ` , async ( ) => {
221- const envFile = path . join ( 'a' , 'b' , 'env.file' ) ;
218+ envFile = path . join ( 'a' , 'b' , 'env.file' ) ;
222219 const workspaceFolder = workspaceUri ? { name : '' , index : 0 , uri : workspaceUri } : undefined ;
223220 const currentProcEnv = { SOMETHING : 'wow' } ;
224221 const envFileVars = { MY_FILE : '1234' } ;
225222
226223 when ( currentProcess . env ) . thenReturn ( currentProcEnv ) ;
227- when ( settings . envFile ) . thenReturn ( envFile ) ;
228224 when ( workspace . getWorkspaceFolder ( workspaceUri ) ) . thenReturn ( workspaceFolder ) ;
229225 when ( envVarsService . parseFile ( envFile , currentProcEnv ) ) . thenCall ( async ( ) => ( { ...envFileVars } ) ) ;
230226 when ( platform . pathVariableName ) . thenReturn ( 'PATH' ) ;
231227
232228 const vars = await provider . getEnvironmentVariables ( workspaceUri ) ;
233229
234230 verify ( currentProcess . env ) . atLeast ( 1 ) ;
235- verify ( settings . envFile ) . atLeast ( 1 ) ;
236231 verify ( envVarsService . parseFile ( envFile , currentProcEnv ) ) . atLeast ( 1 ) ;
237232 verify ( envVarsService . mergeVariables ( deepEqual ( currentProcEnv ) , deepEqual ( envFileVars ) ) ) . once ( ) ;
238233 verify ( platform . pathVariableName ) . atLeast ( 1 ) ;
239234 assert . deepEqual ( vars , envFileVars ) ;
240235 } ) ;
241236 test ( `Getting environment variables (with an envfile, with PATH in current env, with PYTHONPATH in current env) & ${ workspaceTitle } ` , async ( ) => {
242- const envFile = path . join ( 'a' , 'b' , 'env.file' ) ;
237+ envFile = path . join ( 'a' , 'b' , 'env.file' ) ;
243238 const workspaceFolder = workspaceUri ? { name : '' , index : 0 , uri : workspaceUri } : undefined ;
244239 const currentProcEnv = { SOMETHING : 'wow' , PATH : 'some path value' , PYTHONPATH : 'some python path value' } ;
245240 const envFileVars = { MY_FILE : '1234' } ;
246241
247242 when ( currentProcess . env ) . thenReturn ( currentProcEnv ) ;
248- when ( settings . envFile ) . thenReturn ( envFile ) ;
249243 when ( workspace . getWorkspaceFolder ( workspaceUri ) ) . thenReturn ( workspaceFolder ) ;
250244 when ( envVarsService . parseFile ( envFile , currentProcEnv ) ) . thenCall ( async ( ) => ( { ...envFileVars } ) ) ;
251245 when ( platform . pathVariableName ) . thenReturn ( 'PATH' ) ;
252246
253247 const vars = await provider . getEnvironmentVariables ( workspaceUri ) ;
254248
255249 verify ( currentProcess . env ) . atLeast ( 1 ) ;
256- verify ( settings . envFile ) . atLeast ( 1 ) ;
257250 verify ( envVarsService . parseFile ( envFile , currentProcEnv ) ) . atLeast ( 1 ) ;
258251 verify ( envVarsService . mergeVariables ( deepEqual ( currentProcEnv ) , deepEqual ( envFileVars ) ) ) . once ( ) ;
259252 verify ( envVarsService . appendPath ( deepEqual ( envFileVars ) , currentProcEnv . PATH ) ) . once ( ) ;
@@ -263,12 +256,11 @@ suite('Multiroot Environment Variables Provider', () => {
263256 } ) ;
264257
265258 test ( `Getting environment variables which are already cached does not reinvoke the method ${ workspaceTitle } ` , async ( ) => {
266- const envFile = path . join ( 'a' , 'b' , 'env.file' ) ;
259+ envFile = path . join ( 'a' , 'b' , 'env.file' ) ;
267260 const workspaceFolder = workspaceUri ? { name : '' , index : 0 , uri : workspaceUri } : undefined ;
268261 const currentProcEnv = { SOMETHING : 'wow' } ;
269262
270263 when ( currentProcess . env ) . thenReturn ( currentProcEnv ) ;
271- when ( settings . envFile ) . thenReturn ( envFile ) ;
272264 when ( workspace . getWorkspaceFolder ( workspaceUri ) ) . thenReturn ( workspaceFolder ) ;
273265 when ( envVarsService . parseFile ( envFile , currentProcEnv ) ) . thenResolve ( undefined ) ;
274266 when ( platform . pathVariableName ) . thenReturn ( 'PATH' ) ;
@@ -280,7 +272,7 @@ suite('Multiroot Environment Variables Provider', () => {
280272 await provider . getEnvironmentVariables ( workspaceUri ) ;
281273
282274 // Verify that the contents of `_getEnvironmentVariables()` method are only invoked once
283- verify ( configuration . getSettings ( anything ( ) ) ) . once ( ) ;
275+ verify ( workspace . getConfiguration ( 'python' , anything ( ) ) ) . once ( ) ;
284276 assert . deepEqual ( vars , { } ) ;
285277 } ) ;
286278
@@ -290,7 +282,6 @@ suite('Multiroot Environment Variables Provider', () => {
290282 const currentProcEnv = { SOMETHING : 'wow' } ;
291283
292284 when ( currentProcess . env ) . thenReturn ( currentProcEnv ) ;
293- when ( settings . envFile ) . thenReturn ( envFile ) ;
294285 when ( workspace . getWorkspaceFolder ( workspaceUri ) ) . thenReturn ( workspaceFolder ) ;
295286 when ( envVarsService . parseFile ( envFile , currentProcEnv ) ) . thenResolve ( undefined ) ;
296287 when ( platform . pathVariableName ) . thenReturn ( 'PATH' ) ;
@@ -300,7 +291,6 @@ suite('Multiroot Environment Variables Provider', () => {
300291 [ ] ,
301292 instance ( platform ) ,
302293 instance ( workspace ) ,
303- instance ( configuration ) ,
304294 instance ( currentProcess ) ,
305295 100 ,
306296 ) ;
@@ -312,14 +302,14 @@ suite('Multiroot Environment Variables Provider', () => {
312302 await provider . getEnvironmentVariables ( workspaceUri ) ;
313303
314304 // Verify that the contents of `_getEnvironmentVariables()` method are invoked twice
315- verify ( configuration . getSettings ( anything ( ) ) ) . twice ( ) ;
305+ verify ( workspace . getConfiguration ( 'python' , anything ( ) ) ) . twice ( ) ;
316306 assert . deepEqual ( vars , { } ) ;
317307 } ) ;
318308
319309 test ( `Environment variables are updated when env file changes ${ workspaceTitle } ` , async ( ) => {
320310 const root = workspaceUri ?. fsPath ?? '' ;
321311 const sourceDir = path . join ( root , 'a' , 'b' ) ;
322- const envFile = path . join ( sourceDir , 'env.file' ) ;
312+ envFile = path . join ( sourceDir , 'env.file' ) ;
323313 const sourceFile = path . join ( sourceDir , 'main.py' ) ;
324314
325315 const workspaceFolder = workspaceUri ? { name : '' , index : 0 , uri : workspaceUri } : undefined ;
@@ -339,7 +329,6 @@ suite('Multiroot Environment Variables Provider', () => {
339329 when ( workspace . createFileSystemWatcher ( envFile ) ) . thenReturn ( fileSystemWatcher . object ) ;
340330
341331 when ( currentProcess . env ) . thenReturn ( currentProcEnv ) ;
342- when ( settings . envFile ) . thenReturn ( envFile ) ;
343332 when ( workspace . getWorkspaceFolder ( anything ( ) ) ) . thenReturn ( workspaceFolder ) ;
344333 when ( envVarsService . parseFile ( envFile , currentProcEnv ) ) . thenCall ( async ( ) => ( { ...envFileVars } ) ) ;
345334 when ( platform . pathVariableName ) . thenReturn ( 'PATH' ) ;
0 commit comments