@@ -7,7 +7,7 @@ import * as TypeMoq from 'typemoq';
77import { FileSystem } from '../../client/common/platform/fileSystem' ;
88import { IFileSystem , IPlatformService } from '../../client/common/platform/types' ;
99import { IProcessService , IProcessServiceFactory } from '../../client/common/process/types' ;
10- import { ILogger , IPersistentStateFactory } from '../../client/common/types' ;
10+ import { IConfigurationService , ILogger , IPersistentStateFactory , IPythonSettings } from '../../client/common/types' ;
1111import { IInterpreterLocatorService , InterpreterType , PythonInterpreter } from '../../client/interpreter/contracts' ;
1212import { CondaService } from '../../client/interpreter/locators/services/condaService' ;
1313import { IServiceContainer } from '../../client/ioc/types' ;
@@ -35,16 +35,22 @@ suite('Interpreters Conda Service', () => {
3535 let platformService : TypeMoq . IMock < IPlatformService > ;
3636 let condaService : CondaService ;
3737 let fileSystem : TypeMoq . IMock < IFileSystem > ;
38+ let config : TypeMoq . IMock < IConfigurationService > ;
39+ let settings : TypeMoq . IMock < IPythonSettings > ;
3840 let registryInterpreterLocatorService : TypeMoq . IMock < IInterpreterLocatorService > ;
3941 let serviceContainer : TypeMoq . IMock < IServiceContainer > ;
4042 let procServiceFactory : TypeMoq . IMock < IProcessServiceFactory > ;
4143 let logger : TypeMoq . IMock < ILogger > ;
44+ let condaPathSetting : string ;
4245 setup ( async ( ) => {
46+ condaPathSetting = '' ;
4347 logger = TypeMoq . Mock . ofType < ILogger > ( ) ;
4448 processService = TypeMoq . Mock . ofType < IProcessService > ( ) ;
4549 platformService = TypeMoq . Mock . ofType < IPlatformService > ( ) ;
4650 registryInterpreterLocatorService = TypeMoq . Mock . ofType < IInterpreterLocatorService > ( ) ;
4751 fileSystem = TypeMoq . Mock . ofType < IFileSystem > ( ) ;
52+ config = TypeMoq . Mock . ofType < IConfigurationService > ( ) ;
53+ settings = TypeMoq . Mock . ofType < IPythonSettings > ( ) ;
4854 procServiceFactory = TypeMoq . Mock . ofType < IProcessServiceFactory > ( ) ;
4955 processService . setup ( ( x : any ) => x . then ) . returns ( ( ) => undefined ) ;
5056 procServiceFactory . setup ( p => p . create ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => Promise . resolve ( processService . object ) ) ;
@@ -54,6 +60,9 @@ suite('Interpreters Conda Service', () => {
5460 serviceContainer . setup ( c => c . get ( TypeMoq . It . isValue ( IPlatformService ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => platformService . object ) ;
5561 serviceContainer . setup ( c => c . get ( TypeMoq . It . isValue ( ILogger ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => logger . object ) ;
5662 serviceContainer . setup ( c => c . get ( TypeMoq . It . isValue ( IFileSystem ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => fileSystem . object ) ;
63+ serviceContainer . setup ( c => c . get ( TypeMoq . It . isValue ( IConfigurationService ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => config . object ) ;
64+ config . setup ( c => c . getSettings ( TypeMoq . It . isValue ( undefined ) ) ) . returns ( ( ) => settings . object ) ;
65+ settings . setup ( p => p . condaPath ) . returns ( ( ) => condaPathSetting ) ;
5766 condaService = new CondaService ( serviceContainer . object , registryInterpreterLocatorService . object ) ;
5867
5968 fileSystem . setup ( fs => fs . arePathsSame ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( p1 , p2 ) => {
@@ -331,6 +340,22 @@ suite('Interpreters Conda Service', () => {
331340 assert . equal ( condaExe , 'conda' , 'Failed to identify conda.exe' ) ;
332341 } ) ;
333342
343+ test ( 'Must use \'python.condaPath\' setting if set' , async ( ) => {
344+ condaPathSetting = 'spam-spam-conda-spam-spam' ;
345+ // We ensure that conda would otherwise be found.
346+ processService . setup ( p => p . exec ( TypeMoq . It . isValue ( 'conda' ) , TypeMoq . It . isValue ( [ '--version' ] ) ) )
347+ . returns ( ( ) => Promise . resolve ( { stdout : 'xyz' } ) )
348+ . verifiable ( TypeMoq . Times . never ( ) ) ;
349+
350+ const condaExe = await condaService . getCondaFile ( ) ;
351+ assert . equal ( condaExe , 'spam-spam-conda-spam-spam' , 'Failed to identify conda.exe' ) ;
352+
353+ // We should not try to call other unwanted methods.
354+ processService . verifyAll ( ) ;
355+ platformService . verify ( p => p . isWindows , TypeMoq . Times . never ( ) ) ;
356+ registryInterpreterLocatorService . verify ( r => r . getInterpreters ( TypeMoq . It . isAny ( ) ) , TypeMoq . Times . never ( ) ) ;
357+ } ) ;
358+
334359 test ( 'Must use \'conda\' if is available in the current path' , async ( ) => {
335360 processService . setup ( p => p . exec ( TypeMoq . It . isValue ( 'conda' ) , TypeMoq . It . isValue ( [ '--version' ] ) ) ) . returns ( ( ) => Promise . resolve ( { stdout : 'xyz' } ) ) ;
336361
0 commit comments