55
66// tslint:disable:no-any max-func-body-length
77
8- import { expect } from 'chai' ;
8+ import { assert , expect } from 'chai' ;
99import * as path from 'path' ;
1010import { anyString , instance , mock , when } from 'ts-mockito' ;
11+ import { Uri } from 'vscode' ;
1112import { buildApi } from '../client/api' ;
13+ import { ConfigurationService } from '../client/common/configuration/service' ;
1214import { EXTENSION_ROOT_DIR } from '../client/common/constants' ;
1315import { ExperimentsManager } from '../client/common/experiments' ;
14- import { IExperimentsManager } from '../client/common/types' ;
16+ import { IConfigurationService , IExperimentsManager } from '../client/common/types' ;
1517import { ServiceContainer } from '../client/ioc/container' ;
1618import { ServiceManager } from '../client/ioc/serviceManager' ;
1719import { IServiceContainer , IServiceManager } from '../client/ioc/types' ;
1820
19- suite ( 'Extension API - Debugger ' , ( ) => {
21+ suite ( 'Extension API' , ( ) => {
2022 const expectedLauncherPath = `${ EXTENSION_ROOT_DIR . fileToCommandArgument ( ) } /pythonFiles/ptvsd_launcher.py` ;
2123 const ptvsdPath = path . join ( EXTENSION_ROOT_DIR , 'pythonFiles' , 'lib' , 'python' , 'debugpy' , 'no_wheels' , 'debugpy' ) ;
2224 const ptvsdHost = 'somehost' ;
@@ -25,15 +27,46 @@ suite('Extension API - Debugger', () => {
2527 let serviceContainer : IServiceContainer ;
2628 let serviceManager : IServiceManager ;
2729 let experimentsManager : IExperimentsManager ;
30+ let configurationService : IConfigurationService ;
2831
2932 setup ( ( ) => {
3033 serviceContainer = mock ( ServiceContainer ) ;
3134 serviceManager = mock ( ServiceManager ) ;
3235 experimentsManager = mock ( ExperimentsManager ) ;
36+ configurationService = mock ( ConfigurationService ) ;
3337
38+ when ( serviceContainer . get < IConfigurationService > ( IConfigurationService ) ) . thenReturn (
39+ instance ( configurationService )
40+ ) ;
3441 when ( serviceContainer . get < IExperimentsManager > ( IExperimentsManager ) ) . thenReturn ( instance ( experimentsManager ) ) ;
3542 } ) ;
3643
44+ test ( 'Execution command settings API returns expected array if interpreter is set' , async ( ) => {
45+ const resource = Uri . parse ( 'a' ) ;
46+ when ( configurationService . getSettings ( resource ) ) . thenReturn ( { pythonPath : 'settingValue' } as any ) ;
47+
48+ const interpreterPath = buildApi (
49+ Promise . resolve ( ) ,
50+ instance ( serviceManager ) ,
51+ instance ( serviceContainer )
52+ ) . settings . getExecutionCommand ( resource ) ;
53+
54+ assert . deepEqual ( interpreterPath , [ 'settingValue' ] ) ;
55+ } ) ;
56+
57+ test ( 'Execution command settings API returns `undefined` if interpreter is set' , async ( ) => {
58+ const resource = Uri . parse ( 'a' ) ;
59+ when ( configurationService . getSettings ( resource ) ) . thenReturn ( { pythonPath : '' } as any ) ;
60+
61+ const interpreterPath = buildApi (
62+ Promise . resolve ( ) ,
63+ instance ( serviceManager ) ,
64+ instance ( serviceContainer )
65+ ) . settings . getExecutionCommand ( resource ) ;
66+
67+ expect ( interpreterPath ) . to . equal ( undefined , '' ) ;
68+ } ) ;
69+
3770 test ( 'Test debug launcher args (no-wait and not in experiment)' , async ( ) => {
3871 const waitForAttach = false ;
3972 when ( experimentsManager . inExperiment ( anyString ( ) ) ) . thenReturn ( false ) ;
0 commit comments