5
5
6
6
// tslint:disable:no-any max-func-body-length
7
7
8
- import { expect } from 'chai' ;
8
+ import { assert , expect } from 'chai' ;
9
9
import * as path from 'path' ;
10
10
import { anyString , instance , mock , when } from 'ts-mockito' ;
11
+ import { Uri } from 'vscode' ;
11
12
import { buildApi } from '../client/api' ;
13
+ import { ConfigurationService } from '../client/common/configuration/service' ;
12
14
import { EXTENSION_ROOT_DIR } from '../client/common/constants' ;
13
15
import { ExperimentsManager } from '../client/common/experiments' ;
14
- import { IExperimentsManager } from '../client/common/types' ;
16
+ import { IConfigurationService , IExperimentsManager } from '../client/common/types' ;
15
17
import { ServiceContainer } from '../client/ioc/container' ;
16
18
import { ServiceManager } from '../client/ioc/serviceManager' ;
17
19
import { IServiceContainer , IServiceManager } from '../client/ioc/types' ;
18
20
19
- suite ( 'Extension API - Debugger ' , ( ) => {
21
+ suite ( 'Extension API' , ( ) => {
20
22
const expectedLauncherPath = `${ EXTENSION_ROOT_DIR . fileToCommandArgument ( ) } /pythonFiles/ptvsd_launcher.py` ;
21
23
const ptvsdPath = path . join ( EXTENSION_ROOT_DIR , 'pythonFiles' , 'lib' , 'python' , 'debugpy' , 'no_wheels' , 'debugpy' ) ;
22
24
const ptvsdHost = 'somehost' ;
@@ -25,15 +27,46 @@ suite('Extension API - Debugger', () => {
25
27
let serviceContainer : IServiceContainer ;
26
28
let serviceManager : IServiceManager ;
27
29
let experimentsManager : IExperimentsManager ;
30
+ let configurationService : IConfigurationService ;
28
31
29
32
setup ( ( ) => {
30
33
serviceContainer = mock ( ServiceContainer ) ;
31
34
serviceManager = mock ( ServiceManager ) ;
32
35
experimentsManager = mock ( ExperimentsManager ) ;
36
+ configurationService = mock ( ConfigurationService ) ;
33
37
38
+ when ( serviceContainer . get < IConfigurationService > ( IConfigurationService ) ) . thenReturn (
39
+ instance ( configurationService )
40
+ ) ;
34
41
when ( serviceContainer . get < IExperimentsManager > ( IExperimentsManager ) ) . thenReturn ( instance ( experimentsManager ) ) ;
35
42
} ) ;
36
43
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
+
37
70
test ( 'Test debug launcher args (no-wait and not in experiment)' , async ( ) => {
38
71
const waitForAttach = false ;
39
72
when ( experimentsManager . inExperiment ( anyString ( ) ) ) . thenReturn ( false ) ;
0 commit comments