@@ -12,11 +12,13 @@ import {
12
12
IDocumentManager ,
13
13
IWorkspaceService
14
14
} from '../../client/common/application/types' ;
15
+ import { DeprecatePythonPath } from '../../client/common/experimentGroups' ;
15
16
import { PathUtils } from '../../client/common/platform/pathUtils' ;
16
17
import { IFileSystem } from '../../client/common/platform/types' ;
17
- import { IConfigurationService , IPythonSettings } from '../../client/common/types' ;
18
+ import { IConfigurationService , IExperimentsManager , IPythonSettings } from '../../client/common/types' ;
18
19
import { Interpreters } from '../../client/common/utils/localize' ;
19
20
import { Architecture } from '../../client/common/utils/platform' ;
21
+ import { IInterpreterSecurityService } from '../../client/interpreter/autoSelection/types' ;
20
22
import { InterpreterSelector } from '../../client/interpreter/configuration/interpreterSelector' ;
21
23
import {
22
24
IInterpreterComparer ,
@@ -66,6 +68,8 @@ suite('Interpreters - selector', () => {
66
68
let comparer : TypeMoq . IMock < IInterpreterComparer > ;
67
69
let pythonPathUpdater : TypeMoq . IMock < IPythonPathUpdaterServiceManager > ;
68
70
let shebangProvider : TypeMoq . IMock < IShebangCodeLensProvider > ;
71
+ let experimentsManager : TypeMoq . IMock < IExperimentsManager > ;
72
+ let interpreterSecurityService : TypeMoq . IMock < IInterpreterSecurityService > ;
69
73
let configurationService : TypeMoq . IMock < IConfigurationService > ;
70
74
let pythonSettings : TypeMoq . IMock < IPythonSettings > ;
71
75
const folder1 = { name : 'one' , uri : Uri . parse ( 'one' ) , index : 1 } ;
@@ -96,6 +100,12 @@ suite('Interpreters - selector', () => {
96
100
let selector : TestInterpreterSelector ;
97
101
98
102
setup ( ( ) => {
103
+ experimentsManager = TypeMoq . Mock . ofType < IExperimentsManager > ( ) ;
104
+ experimentsManager . setup ( ( e ) => e . inExperiment ( DeprecatePythonPath . experiment ) ) . returns ( ( ) => false ) ;
105
+ experimentsManager
106
+ . setup ( ( e ) => e . sendTelemetryIfInExperiment ( DeprecatePythonPath . control ) )
107
+ . returns ( ( ) => undefined ) ;
108
+ interpreterSecurityService = TypeMoq . Mock . ofType < IInterpreterSecurityService > ( ) ;
99
109
commandManager = TypeMoq . Mock . ofType < ICommandManager > ( ) ;
100
110
comparer = TypeMoq . Mock . ofType < IInterpreterComparer > ( ) ;
101
111
appShell = TypeMoq . Mock . ofType < IApplicationShell > ( ) ;
@@ -124,7 +134,9 @@ suite('Interpreters - selector', () => {
124
134
pythonPathUpdater . object ,
125
135
shebangProvider . object ,
126
136
configurationService . object ,
127
- commandManager . object
137
+ commandManager . object ,
138
+ experimentsManager . object ,
139
+ interpreterSecurityService . object
128
140
) ;
129
141
} ) ;
130
142
@@ -140,7 +152,9 @@ suite('Interpreters - selector', () => {
140
152
pythonPathUpdater . object ,
141
153
shebangProvider . object ,
142
154
configurationService . object ,
143
- commandManager . object
155
+ commandManager . object ,
156
+ experimentsManager . object ,
157
+ interpreterSecurityService . object
144
158
) ;
145
159
146
160
const initial : PythonInterpreter [ ] = [
@@ -184,6 +198,27 @@ suite('Interpreters - selector', () => {
184
198
} ) ;
185
199
} ) ;
186
200
201
+ test ( 'When in Deprecate PythonPath experiment, remove unsafe interpreters from the suggested interpreters list' , async ( ) => {
202
+ // tslint:disable-next-line: no-any
203
+ const interpreterList = [ 'interpreter1' , 'interpreter2' , 'interpreter3' ] as any ;
204
+ interpreterService . setup ( ( i ) => i . getInterpreters ( folder1 . uri ) ) . returns ( ( ) => interpreterList ) ;
205
+ // tslint:disable-next-line: no-any
206
+ interpreterSecurityService . setup ( ( i ) => i . isSafe ( 'interpreter1' as any ) ) . returns ( ( ) => true ) ;
207
+ // tslint:disable-next-line: no-any
208
+ interpreterSecurityService . setup ( ( i ) => i . isSafe ( 'interpreter2' as any ) ) . returns ( ( ) => false ) ;
209
+ // tslint:disable-next-line: no-any
210
+ interpreterSecurityService . setup ( ( i ) => i . isSafe ( 'interpreter3' as any ) ) . returns ( ( ) => undefined ) ;
211
+ experimentsManager . reset ( ) ;
212
+ experimentsManager . setup ( ( e ) => e . inExperiment ( DeprecatePythonPath . experiment ) ) . returns ( ( ) => true ) ;
213
+ experimentsManager
214
+ . setup ( ( e ) => e . sendTelemetryIfInExperiment ( DeprecatePythonPath . control ) )
215
+ . returns ( ( ) => undefined ) ;
216
+ // tslint:disable-next-line: no-any
217
+ selector . suggestionToQuickPickItem = ( item , _ ) => Promise . resolve ( item as any ) ;
218
+ const suggestion = await selector . getSuggestions ( folder1 . uri ) ;
219
+ assert . deepEqual ( suggestion , [ 'interpreter1' , 'interpreter3' ] ) ;
220
+ } ) ;
221
+
187
222
// tslint:disable-next-line: max-func-body-length
188
223
suite ( 'Test method setInterpreter()' , async ( ) => {
189
224
test ( 'Update Global settings when there are no workspaces' , async ( ) => {
0 commit comments