@@ -189,6 +189,18 @@ suite('Terminal Environment Activation conda', () => {
189
189
envName : environmentNameHasSpaces ,
190
190
expectedResult : [ 'source path/to/activate' , 'conda activate "Env with spaces"' ] ,
191
191
isWindows : false
192
+ } ,
193
+ {
194
+ testName : 'Activation provides correct activation commands (windows) after 4.4.0 given interpreter path is provided, and no env name' ,
195
+ envName : '' ,
196
+ expectedResult : [ 'path/to/activate' , `conda activate .` ] ,
197
+ isWindows : true
198
+ } ,
199
+ {
200
+ testName : 'Activation provides correct activation commands (non-windows) after 4.4.0 given interpreter path is provided, and no env name' ,
201
+ envName : '' ,
202
+ expectedResult : [ 'source path/to/activate' , `conda activate .` ] ,
203
+ isWindows : false
192
204
}
193
205
] ;
194
206
@@ -215,79 +227,93 @@ suite('Terminal Environment Activation conda', () => {
215
227
} ) ;
216
228
} ) ;
217
229
218
- async function testCondaActivationCommands (
219
- isWindows : boolean ,
220
- isOsx : boolean ,
221
- isLinux : boolean ,
222
- pythonPath : string ,
223
- shellType : TerminalShellType ,
224
- hasSpaceInEnvironmentName = false
225
- ) {
230
+ async function testCondaActivationCommands ( isWindows : boolean , isOsx : boolean , isLinux : boolean , pythonPath : string , shellType : TerminalShellType , envName : string ) {
226
231
terminalSettings . setup ( t => t . activateEnvironment ) . returns ( ( ) => true ) ;
227
232
platformService . setup ( p => p . isLinux ) . returns ( ( ) => isLinux ) ;
228
233
platformService . setup ( p => p . isWindows ) . returns ( ( ) => isWindows ) ;
229
234
platformService . setup ( p => p . isMac ) . returns ( ( ) => isOsx ) ;
230
235
condaService . setup ( c => c . isCondaEnvironment ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => Promise . resolve ( true ) ) ;
231
236
pythonSettings . setup ( s => s . pythonPath ) . returns ( ( ) => pythonPath ) ;
232
- const envName = hasSpaceInEnvironmentName ? 'EnvA' : 'Env A' ;
233
237
condaService . setup ( c => c . getCondaEnvironment ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => Promise . resolve ( { name : envName , path : path . dirname ( pythonPath ) } ) ) ;
234
238
235
239
const activationCommands = await new CondaActivationCommandProvider ( condaService . object , platformService . object , configService . object ) . getActivationCommands (
236
240
undefined ,
237
241
shellType
238
242
) ;
239
- let expectedActivationCommamnd : string [ ] | undefined ;
243
+ let expectedActivationCommand : string [ ] | undefined ;
244
+ const expectEnvActivatePath = path . dirname ( pythonPath ) ;
240
245
switch ( shellType ) {
241
246
case TerminalShellType . powershell :
242
- case TerminalShellType . powershellCore : {
243
- expectedActivationCommamnd = [ `conda activate ${ envName . toCommandArgument ( ) } ` ] ;
244
- break ;
245
- }
247
+ case TerminalShellType . powershellCore :
246
248
case TerminalShellType . fish : {
247
- expectedActivationCommamnd = [ `conda activate ${ envName . toCommandArgument ( ) } ` ] ;
249
+ if ( envName !== '' ) {
250
+ expectedActivationCommand = [ `conda activate ${ envName . toCommandArgument ( ) } ` ] ;
251
+ } else {
252
+ expectedActivationCommand = [ `conda activate ${ expectEnvActivatePath } ` ] ;
253
+ }
248
254
break ;
249
255
}
250
256
default : {
251
- expectedActivationCommamnd = isWindows ? [ `activate ${ envName . toCommandArgument ( ) } ` ] : [ `source activate ${ envName . toCommandArgument ( ) } ` ] ;
257
+ if ( envName !== '' ) {
258
+ expectedActivationCommand = isWindows ? [ `activate ${ envName . toCommandArgument ( ) } ` ] : [ `source activate ${ envName . toCommandArgument ( ) } ` ] ;
259
+ } else {
260
+ expectedActivationCommand = isWindows ? [ `activate ${ expectEnvActivatePath } ` ] : [ `source activate ${ expectEnvActivatePath } ` ] ;
261
+ }
252
262
break ;
253
263
}
254
264
}
255
- if ( expectedActivationCommamnd ) {
256
- expect ( activationCommands ) . to . deep . equal ( expectedActivationCommamnd , 'Incorrect Activation command' ) ;
265
+ if ( expectedActivationCommand ) {
266
+ expect ( activationCommands ) . to . deep . equal ( expectedActivationCommand , 'Incorrect Activation command' ) ;
257
267
} else {
258
268
expect ( activationCommands ) . to . equal ( undefined , 'Incorrect Activation command' ) ;
259
269
}
260
270
}
261
271
getNamesAndValues < TerminalShellType > ( TerminalShellType ) . forEach ( shellType => {
262
272
test ( `Conda activation command for shell ${ shellType . name } on (windows)` , async ( ) => {
263
273
const pythonPath = path . join ( 'c' , 'users' , 'xyz' , '.conda' , 'envs' , 'enva' , 'python.exe' ) ;
264
- await testCondaActivationCommands ( true , false , false , pythonPath , shellType . value ) ;
274
+ await testCondaActivationCommands ( true , false , false , pythonPath , shellType . value , 'Env' ) ;
265
275
} ) ;
266
276
267
277
test ( `Conda activation command for shell ${ shellType . name } on (linux)` , async ( ) => {
268
278
const pythonPath = path . join ( 'users' , 'xyz' , '.conda' , 'envs' , 'enva' , 'bin' , 'python' ) ;
269
- await testCondaActivationCommands ( false , false , true , pythonPath , shellType . value ) ;
279
+ await testCondaActivationCommands ( false , false , true , pythonPath , shellType . value , 'Env' ) ;
270
280
} ) ;
271
281
272
282
test ( `Conda activation command for shell ${ shellType . name } on (mac)` , async ( ) => {
273
283
const pythonPath = path . join ( 'users' , 'xyz' , '.conda' , 'envs' , 'enva' , 'bin' , 'python' ) ;
274
- await testCondaActivationCommands ( false , true , false , pythonPath , shellType . value ) ;
284
+ await testCondaActivationCommands ( false , true , false , pythonPath , shellType . value , 'Env' ) ;
275
285
} ) ;
276
286
} ) ;
277
287
getNamesAndValues < TerminalShellType > ( TerminalShellType ) . forEach ( shellType => {
278
288
test ( `Conda activation command for shell ${ shellType . name } on (windows), containing spaces in environment name` , async ( ) => {
279
289
const pythonPath = path . join ( 'c' , 'users' , 'xyz' , '.conda' , 'envs' , 'enva' , 'python.exe' ) ;
280
- await testCondaActivationCommands ( true , false , false , pythonPath , shellType . value , true ) ;
290
+ await testCondaActivationCommands ( true , false , false , pythonPath , shellType . value , 'Env A' ) ;
281
291
} ) ;
282
292
283
293
test ( `Conda activation command for shell ${ shellType . name } on (linux), containing spaces in environment name` , async ( ) => {
284
294
const pythonPath = path . join ( 'users' , 'xyz' , '.conda' , 'envs' , 'enva' , 'bin' , 'python' ) ;
285
- await testCondaActivationCommands ( false , false , true , pythonPath , shellType . value , true ) ;
295
+ await testCondaActivationCommands ( false , false , true , pythonPath , shellType . value , 'Env A' ) ;
286
296
} ) ;
287
297
288
298
test ( `Conda activation command for shell ${ shellType . name } on (mac), containing spaces in environment name` , async ( ) => {
289
299
const pythonPath = path . join ( 'users' , 'xyz' , '.conda' , 'envs' , 'enva' , 'bin' , 'python' ) ;
290
- await testCondaActivationCommands ( false , true , false , pythonPath , shellType . value , true ) ;
300
+ await testCondaActivationCommands ( false , true , false , pythonPath , shellType . value , 'Env A' ) ;
301
+ } ) ;
302
+ } ) ;
303
+ getNamesAndValues < TerminalShellType > ( TerminalShellType ) . forEach ( shellType => {
304
+ test ( `Conda activation command for shell ${ shellType . name } on (windows), containing no environment name` , async ( ) => {
305
+ const pythonPath = path . join ( 'c' , 'users' , 'xyz' , '.conda' , 'envs' , 'enva' , 'python.exe' ) ;
306
+ await testCondaActivationCommands ( true , false , false , pythonPath , shellType . value , '' ) ;
307
+ } ) ;
308
+
309
+ test ( `Conda activation command for shell ${ shellType . name } on (linux), containing no environment name` , async ( ) => {
310
+ const pythonPath = path . join ( 'users' , 'xyz' , '.conda' , 'envs' , 'enva' , 'bin' , 'python' ) ;
311
+ await testCondaActivationCommands ( false , false , true , pythonPath , shellType . value , '' ) ;
312
+ } ) ;
313
+
314
+ test ( `Conda activation command for shell ${ shellType . name } on (mac), containing no environment name` , async ( ) => {
315
+ const pythonPath = path . join ( 'users' , 'xyz' , '.conda' , 'envs' , 'enva' , 'bin' , 'python' ) ;
316
+ await testCondaActivationCommands ( false , true , false , pythonPath , shellType . value , '' ) ;
291
317
} ) ;
292
318
} ) ;
293
319
async function expectCondaActivationCommand ( isWindows : boolean , isOsx : boolean , isLinux : boolean , pythonPath : string ) {
0 commit comments