33
44import { expect , use } from 'chai' ;
55import * as chaiAsPromised from 'chai-as-promised' ;
6+ import * as sinon from 'sinon' ;
67import { SemVer } from 'semver' ;
78import * as TypeMoq from 'typemoq' ;
89import { IFileSystem } from '../../../client/common/platform/types' ;
@@ -13,6 +14,8 @@ import {
1314} from '../../../client/common/process/pythonEnvironment' ;
1415import { IProcessService , StdErrError } from '../../../client/common/process/types' ;
1516import { Architecture } from '../../../client/common/utils/platform' ;
17+ import { Conda } from '../../../client/pythonEnvironments/common/environmentManagers/conda' ;
18+ import { OUTPUT_MARKER_SCRIPT } from '../../../client/common/process/internal/scripts' ;
1619
1720use ( chaiAsPromised ) ;
1821
@@ -275,64 +278,67 @@ suite('CondaEnvironment', () => {
275278 const condaFile = 'path/to/conda' ;
276279
277280 setup ( ( ) => {
281+ sinon . stub ( Conda , 'getConda' ) . resolves ( new Conda ( condaFile ) ) ;
278282 processService = TypeMoq . Mock . ofType < IProcessService > ( undefined , TypeMoq . MockBehavior . Strict ) ;
279283 fileSystem = TypeMoq . Mock . ofType < IFileSystem > ( undefined , TypeMoq . MockBehavior . Strict ) ;
280284 } ) ;
281285
282- test ( 'getExecutionInfo with a named environment should return execution info using the environment name' , ( ) => {
286+ teardown ( ( ) => sinon . restore ( ) ) ;
287+
288+ test ( 'getExecutionInfo with a named environment should return execution info using the environment name' , async ( ) => {
283289 const condaInfo = { name : 'foo' , path : 'bar' } ;
284- const env = createCondaEnv ( condaFile , condaInfo , pythonPath , processService . object , fileSystem . object ) ;
290+ const env = await createCondaEnv ( condaInfo , pythonPath , processService . object , fileSystem . object ) ;
285291
286- const result = env . getExecutionInfo ( args ) ;
292+ const result = env ? .getExecutionInfo ( args , pythonPath ) ;
287293
288294 expect ( result ) . to . deep . equal ( {
289295 command : condaFile ,
290- args : [ 'run' , '-n' , condaInfo . name , '--no-capture-output' , 'python' , ...args ] ,
291- python : [ condaFile , 'run' , '-n' , condaInfo . name , '--no-capture-output' , 'python' ] ,
292- pythonExecutable : 'python' ,
296+ args : [ 'run' , '-n' , condaInfo . name , '--no-capture-output' , 'python' , OUTPUT_MARKER_SCRIPT , ...args ] ,
297+ python : [ condaFile , 'run' , '-n' , condaInfo . name , '--no-capture-output' , 'python' , OUTPUT_MARKER_SCRIPT ] ,
298+ pythonExecutable : pythonPath ,
293299 } ) ;
294300 } ) ;
295301
296- test ( 'getExecutionInfo with a non-named environment should return execution info using the environment path' , ( ) => {
302+ test ( 'getExecutionInfo with a non-named environment should return execution info using the environment path' , async ( ) => {
297303 const condaInfo = { name : '' , path : 'bar' } ;
298- const env = createCondaEnv ( condaFile , condaInfo , pythonPath , processService . object , fileSystem . object ) ;
304+ const env = await createCondaEnv ( condaInfo , pythonPath , processService . object , fileSystem . object ) ;
299305
300- const result = env . getExecutionInfo ( args ) ;
306+ const result = env ? .getExecutionInfo ( args , pythonPath ) ;
301307
302308 expect ( result ) . to . deep . equal ( {
303309 command : condaFile ,
304- args : [ 'run' , '-p' , condaInfo . path , '--no-capture-output' , 'python' , ...args ] ,
305- python : [ condaFile , 'run' , '-p' , condaInfo . path , '--no-capture-output' , 'python' ] ,
306- pythonExecutable : 'python' ,
310+ args : [ 'run' , '-p' , condaInfo . path , '--no-capture-output' , 'python' , OUTPUT_MARKER_SCRIPT , ...args ] ,
311+ python : [ condaFile , 'run' , '-p' , condaInfo . path , '--no-capture-output' , 'python' , OUTPUT_MARKER_SCRIPT ] ,
312+ pythonExecutable : pythonPath ,
307313 } ) ;
308314 } ) ;
309315
310- test ( 'getExecutionObservableInfo with a named environment should return execution info using conda full path with the name' , ( ) => {
316+ test ( 'getExecutionObservableInfo with a named environment should return execution info using conda full path with the name' , async ( ) => {
311317 const condaInfo = { name : 'foo' , path : 'bar' } ;
312318 const expected = {
313319 command : condaFile ,
314- args : [ 'run' , '-n' , condaInfo . name , '--no-capture-output' , 'python' , ...args ] ,
315- python : [ condaFile , 'run' , '-n' , condaInfo . name , '--no-capture-output' , 'python' ] ,
316- pythonExecutable : 'python' ,
320+ args : [ 'run' , '-n' , condaInfo . name , '--no-capture-output' , 'python' , OUTPUT_MARKER_SCRIPT , ...args ] ,
321+ python : [ condaFile , 'run' , '-n' , condaInfo . name , '--no-capture-output' , 'python' , OUTPUT_MARKER_SCRIPT ] ,
322+ pythonExecutable : pythonPath ,
317323 } ;
318- const env = createCondaEnv ( condaFile , condaInfo , pythonPath , processService . object , fileSystem . object ) ;
324+ const env = await createCondaEnv ( condaInfo , pythonPath , processService . object , fileSystem . object ) ;
319325
320- const result = env . getExecutionObservableInfo ( args ) ;
326+ const result = env ? .getExecutionObservableInfo ( args , pythonPath ) ;
321327
322328 expect ( result ) . to . deep . equal ( expected ) ;
323329 } ) ;
324330
325- test ( 'getExecutionObservableInfo with a non-named environment should return execution info using conda full path' , ( ) => {
331+ test ( 'getExecutionObservableInfo with a non-named environment should return execution info using conda full path' , async ( ) => {
326332 const condaInfo = { name : '' , path : 'bar' } ;
327333 const expected = {
328334 command : condaFile ,
329- args : [ 'run' , '-p' , condaInfo . path , '--no-capture-output' , 'python' , ...args ] ,
330- python : [ condaFile , 'run' , '-p' , condaInfo . path , '--no-capture-output' , 'python' ] ,
331- pythonExecutable : 'python' ,
335+ args : [ 'run' , '-p' , condaInfo . path , '--no-capture-output' , 'python' , OUTPUT_MARKER_SCRIPT , ...args ] ,
336+ python : [ condaFile , 'run' , '-p' , condaInfo . path , '--no-capture-output' , 'python' , OUTPUT_MARKER_SCRIPT ] ,
337+ pythonExecutable : pythonPath ,
332338 } ;
333- const env = createCondaEnv ( condaFile , condaInfo , pythonPath , processService . object , fileSystem . object ) ;
339+ const env = await createCondaEnv ( condaInfo , pythonPath , processService . object , fileSystem . object ) ;
334340
335- const result = env . getExecutionObservableInfo ( args ) ;
341+ const result = env ? .getExecutionObservableInfo ( args , pythonPath ) ;
336342
337343 expect ( result ) . to . deep . equal ( expected ) ;
338344 } ) ;
0 commit comments