@@ -12,7 +12,7 @@ import * as TypeMoq from 'typemoq';
1212import { OutputChannel , Uri } from 'vscode' ;
1313import '../../../client/common/extensions' ;
1414import { ProductInstaller } from '../../../client/common/installer/productInstaller' ;
15- import { CTagsProductPathService , DataScienceProductPathService , FormatterProductPathService , LinterProductPathService , RefactoringLibraryProductPathService , TestFrameworkProductPathService } from '../../../client/common/installer/productPath' ;
15+ import { BaseProductPathsService , CTagsProductPathService , DataScienceProductPathService , FormatterProductPathService , LinterProductPathService , RefactoringLibraryProductPathService , TestFrameworkProductPathService } from '../../../client/common/installer/productPath' ;
1616import { ProductService } from '../../../client/common/installer/productService' ;
1717import { IProductService } from '../../../client/common/installer/types' ;
1818import { IConfigurationService , IFormattingSettings , IInstaller , IPythonSettings , ITestingSettings , IWorkspaceSymbolSettings , ModuleNamePurpose , Product , ProductType } from '../../../client/common/types' ;
@@ -27,6 +27,11 @@ use(chaiAsPromised);
2727suite ( 'Product Path' , ( ) => {
2828 [ undefined , Uri . file ( 'resource' ) ] . forEach ( resource => {
2929 getNamesAndValues < Product > ( Product ) . forEach ( product => {
30+ class TestBaseProductPathsService extends BaseProductPathsService {
31+ public getExecutableNameFromSettings ( _ : Product , _resource ?: Uri ) : string {
32+ return '' ;
33+ }
34+ }
3035 let serviceContainer : TypeMoq . IMock < IServiceContainer > ;
3136 let formattingSettings : TypeMoq . IMock < IFormattingSettings > ;
3237 let unitTestSettings : TypeMoq . IMock < ITestingSettings > ;
@@ -58,6 +63,34 @@ suite('Product Path', () => {
5863 if ( product . value === Product . isort ) {
5964 return ;
6065 }
66+ suite ( 'Method isExecutableAModule()' , ( ) => {
67+ if ( product . value === Product . ipykernel ) {
68+ test ( 'Returns true if product is ipykernel' , ( ) => {
69+ const productPathService = new TestBaseProductPathsService ( serviceContainer . object ) ;
70+ expect ( productPathService . isExecutableAModule ( product . value ) ) . to . equal ( true , 'Should be true' ) ;
71+ } ) ;
72+ } else {
73+ test ( 'Returns true if User has customized the executable name' , ( ) => {
74+ productInstaller . translateProductToModuleName = ( ) => 'moduleName' ;
75+ const productPathService = new TestBaseProductPathsService ( serviceContainer . object ) ;
76+ productPathService . getExecutableNameFromSettings = ( ) => 'executableName' ;
77+ expect ( productPathService . isExecutableAModule ( product . value ) ) . to . equal ( true , 'Should be true' ) ;
78+ } ) ;
79+ test ( 'Returns false if User has customized the full path to executable' , ( ) => {
80+ productInstaller . translateProductToModuleName = ( ) => 'moduleName' ;
81+ const productPathService = new TestBaseProductPathsService ( serviceContainer . object ) ;
82+ productPathService . getExecutableNameFromSettings = ( ) => 'path/to/executable' ;
83+ expect ( productPathService . isExecutableAModule ( product . value ) ) . to . equal ( false , 'Should be false' ) ;
84+ } ) ;
85+ test ( 'Returns false if translating product to module name fails with error' , ( ) => {
86+ // tslint:disable-next-line: no-any
87+ productInstaller . translateProductToModuleName = ( ) => { return new Error ( 'Kaboom' ) as any ; } ;
88+ const productPathService = new TestBaseProductPathsService ( serviceContainer . object ) ;
89+ productPathService . getExecutableNameFromSettings = ( ) => 'executableName' ;
90+ expect ( productPathService . isExecutableAModule ( product . value ) ) . to . equal ( false , 'Should be false' ) ;
91+ } ) ;
92+ }
93+ } ) ;
6194 const productType = new ProductService ( ) . getProductType ( product . value ) ;
6295 switch ( productType ) {
6396 case ProductType . Formatter : {
0 commit comments