@@ -10,6 +10,7 @@ import * as TypeMoq from 'typemoq';
10
10
import { ConfigurationTarget , Uri , WorkspaceConfiguration } from 'vscode' ;
11
11
import { IApplicationShell , IWorkspaceService } from '../../../client/common/application/types' ;
12
12
import { PersistentStateFactory } from '../../../client/common/persistentState' ;
13
+ import { IPlatformService } from '../../../client/common/platform/types' ;
13
14
import { IBrowserService , IPersistentState , IPersistentStateFactory } from '../../../client/common/types' ;
14
15
import { createDeferred , createDeferredFromPromise , sleep } from '../../../client/common/utils/async' ;
15
16
import { Common , InteractiveShiftEnterBanner , Interpreters } from '../../../client/common/utils/localize' ;
@@ -24,6 +25,7 @@ suite('Conda Inherit Env Prompt', async () => {
24
25
let workspaceService : TypeMoq . IMock < IWorkspaceService > ;
25
26
let appShell : TypeMoq . IMock < IApplicationShell > ;
26
27
let interpreterService : TypeMoq . IMock < IInterpreterService > ;
28
+ let platformService : TypeMoq . IMock < IPlatformService > ;
27
29
let browserService : TypeMoq . IMock < IBrowserService > ;
28
30
let persistentStateFactory : IPersistentStateFactory ;
29
31
let notificationPromptEnabled : TypeMoq . IMock < IPersistentState < any > > ;
@@ -41,10 +43,26 @@ suite('Conda Inherit Env Prompt', async () => {
41
43
browserService = TypeMoq . Mock . ofType < IBrowserService > ( ) ;
42
44
interpreterService = TypeMoq . Mock . ofType < IInterpreterService > ( ) ;
43
45
persistentStateFactory = mock ( PersistentStateFactory ) ;
44
- condaInheritEnvPrompt = new CondaInheritEnvPrompt ( interpreterService . object , workspaceService . object , browserService . object , appShell . object , instance ( persistentStateFactory ) ) ;
46
+ platformService = TypeMoq . Mock . ofType < IPlatformService > ( ) ;
47
+ condaInheritEnvPrompt = new CondaInheritEnvPrompt (
48
+ interpreterService . object ,
49
+ workspaceService . object ,
50
+ browserService . object ,
51
+ appShell . object ,
52
+ instance ( persistentStateFactory ) ,
53
+ platformService . object
54
+ ) ;
45
55
} ) ;
46
56
test ( 'Returns false if prompt has already been shown in the current session' , async ( ) => {
47
- condaInheritEnvPrompt = new CondaInheritEnvPrompt ( interpreterService . object , workspaceService . object , browserService . object , appShell . object , instance ( persistentStateFactory ) , true ) ;
57
+ condaInheritEnvPrompt = new CondaInheritEnvPrompt (
58
+ interpreterService . object ,
59
+ workspaceService . object ,
60
+ browserService . object ,
61
+ appShell . object ,
62
+ instance ( persistentStateFactory ) ,
63
+ platformService . object ,
64
+ true
65
+ ) ;
48
66
const workspaceConfig = TypeMoq . Mock . ofType < WorkspaceConfiguration > ( ) ;
49
67
interpreterService
50
68
. setup ( is => is . getActiveInterpreter ( resource ) )
@@ -59,11 +77,25 @@ suite('Conda Inherit Env Prompt', async () => {
59
77
expect ( condaInheritEnvPrompt . hasPromptBeenShownInCurrentSession ) . to . equal ( true , 'Should be true' ) ;
60
78
verifyAll ( ) ;
61
79
} ) ;
80
+ test ( 'Returns false if on Windows' , async ( ) => {
81
+ platformService
82
+ . setup ( ps => ps . isWindows )
83
+ . returns ( ( ) => true )
84
+ . verifiable ( TypeMoq . Times . once ( ) ) ;
85
+ const result = await condaInheritEnvPrompt . shouldShowPrompt ( resource ) ;
86
+ expect ( result ) . to . equal ( false , 'Prompt should not be shown' ) ;
87
+ expect ( condaInheritEnvPrompt . hasPromptBeenShownInCurrentSession ) . to . equal ( false , 'Should be false' ) ;
88
+ verifyAll ( ) ;
89
+ } ) ;
62
90
test ( 'Returns false if active interpreter is not of type Conda' , async ( ) => {
63
91
const interpreter = {
64
92
type : InterpreterType . Pipenv
65
93
} ;
66
94
const workspaceConfig = TypeMoq . Mock . ofType < WorkspaceConfiguration > ( ) ;
95
+ platformService
96
+ . setup ( ps => ps . isWindows )
97
+ . returns ( ( ) => false )
98
+ . verifiable ( TypeMoq . Times . once ( ) ) ;
67
99
interpreterService
68
100
. setup ( is => is . getActiveInterpreter ( resource ) )
69
101
. returns ( ( ) => Promise . resolve ( interpreter ) as any )
@@ -79,6 +111,10 @@ suite('Conda Inherit Env Prompt', async () => {
79
111
} ) ;
80
112
test ( 'Returns false if no active interpreter is present' , async ( ) => {
81
113
const workspaceConfig = TypeMoq . Mock . ofType < WorkspaceConfiguration > ( ) ;
114
+ platformService
115
+ . setup ( ps => ps . isWindows )
116
+ . returns ( ( ) => false )
117
+ . verifiable ( TypeMoq . Times . once ( ) ) ;
82
118
interpreterService
83
119
. setup ( is => is . getActiveInterpreter ( resource ) )
84
120
. returns ( ( ) => Promise . resolve ( undefined ) )
@@ -97,6 +133,10 @@ suite('Conda Inherit Env Prompt', async () => {
97
133
type : InterpreterType . Conda
98
134
} ;
99
135
const workspaceConfig = TypeMoq . Mock . ofType < WorkspaceConfiguration > ( ) ;
136
+ platformService
137
+ . setup ( ps => ps . isWindows )
138
+ . returns ( ( ) => false )
139
+ . verifiable ( TypeMoq . Times . once ( ) ) ;
100
140
interpreterService
101
141
. setup ( is => is . getActiveInterpreter ( resource ) )
102
142
. returns ( ( ) => Promise . resolve ( interpreter ) as any )
@@ -107,7 +147,8 @@ suite('Conda Inherit Env Prompt', async () => {
107
147
. verifiable ( TypeMoq . Times . once ( ) ) ;
108
148
workspaceConfig
109
149
. setup ( ws => ws . inspect < boolean > ( 'integrated.inheritEnv' ) )
110
- . returns ( ( ) => undefined ) ;
150
+ . returns ( ( ) => undefined )
151
+ . verifiable ( TypeMoq . Times . once ( ) ) ;
111
152
const result = await condaInheritEnvPrompt . shouldShowPrompt ( resource ) ;
112
153
expect ( result ) . to . equal ( false , 'Prompt should not be shown' ) ;
113
154
expect ( condaInheritEnvPrompt . hasPromptBeenShownInCurrentSession ) . to . equal ( false , 'Should be false' ) ;
@@ -144,6 +185,10 @@ suite('Conda Inherit Env Prompt', async () => {
144
185
type : InterpreterType . Conda
145
186
} ;
146
187
const workspaceConfig = TypeMoq . Mock . ofType < WorkspaceConfiguration > ( ) ;
188
+ platformService
189
+ . setup ( ps => ps . isWindows )
190
+ . returns ( ( ) => false )
191
+ . verifiable ( TypeMoq . Times . once ( ) ) ;
147
192
interpreterService
148
193
. setup ( is => is . getActiveInterpreter ( resource ) )
149
194
. returns ( ( ) => Promise . resolve ( interpreter ) as any )
@@ -171,6 +216,10 @@ suite('Conda Inherit Env Prompt', async () => {
171
216
workspaceFolderValue : undefined
172
217
} ;
173
218
const workspaceConfig = TypeMoq . Mock . ofType < WorkspaceConfiguration > ( ) ;
219
+ platformService
220
+ . setup ( ps => ps . isWindows )
221
+ . returns ( ( ) => false )
222
+ . verifiable ( TypeMoq . Times . once ( ) ) ;
174
223
interpreterService
175
224
. setup ( is => is . getActiveInterpreter ( resource ) )
176
225
. returns ( ( ) => Promise . resolve ( interpreter ) as any )
@@ -196,6 +245,7 @@ suite('Conda Inherit Env Prompt', async () => {
196
245
browserService = TypeMoq . Mock . ofType < IBrowserService > ( ) ;
197
246
interpreterService = TypeMoq . Mock . ofType < IInterpreterService > ( ) ;
198
247
persistentStateFactory = mock ( PersistentStateFactory ) ;
248
+ platformService = TypeMoq . Mock . ofType < IPlatformService > ( ) ;
199
249
} ) ;
200
250
201
251
teardown ( ( ) => {
@@ -206,7 +256,14 @@ suite('Conda Inherit Env Prompt', async () => {
206
256
const initializeInBackgroundDeferred = createDeferred < void > ( ) ;
207
257
initializeInBackground = sinon . stub ( CondaInheritEnvPrompt . prototype , 'initializeInBackground' ) ;
208
258
initializeInBackground . callsFake ( ( ) => initializeInBackgroundDeferred . promise ) ;
209
- condaInheritEnvPrompt = new CondaInheritEnvPrompt ( interpreterService . object , workspaceService . object , browserService . object , appShell . object , instance ( persistentStateFactory ) ) ;
259
+ condaInheritEnvPrompt = new CondaInheritEnvPrompt (
260
+ interpreterService . object ,
261
+ workspaceService . object ,
262
+ browserService . object ,
263
+ appShell . object ,
264
+ instance ( persistentStateFactory ) ,
265
+ platformService . object
266
+ ) ;
210
267
211
268
const promise = condaInheritEnvPrompt . activate ( resource ) ;
212
269
const deferred = createDeferredFromPromise ( promise ) ;
@@ -223,7 +280,14 @@ suite('Conda Inherit Env Prompt', async () => {
223
280
test ( 'Ignores errors raised by initializeInBackground()' , async ( ) => {
224
281
initializeInBackground = sinon . stub ( CondaInheritEnvPrompt . prototype , 'initializeInBackground' ) ;
225
282
initializeInBackground . rejects ( new Error ( 'Kaboom' ) ) ;
226
- condaInheritEnvPrompt = new CondaInheritEnvPrompt ( interpreterService . object , workspaceService . object , browserService . object , appShell . object , instance ( persistentStateFactory ) ) ;
283
+ condaInheritEnvPrompt = new CondaInheritEnvPrompt (
284
+ interpreterService . object ,
285
+ workspaceService . object ,
286
+ browserService . object ,
287
+ appShell . object ,
288
+ instance ( persistentStateFactory ) ,
289
+ platformService . object
290
+ ) ;
227
291
await condaInheritEnvPrompt . activate ( resource ) ;
228
292
assert . ok ( initializeInBackground . calledOnce ) ;
229
293
} ) ;
@@ -238,6 +302,7 @@ suite('Conda Inherit Env Prompt', async () => {
238
302
browserService = TypeMoq . Mock . ofType < IBrowserService > ( ) ;
239
303
interpreterService = TypeMoq . Mock . ofType < IInterpreterService > ( ) ;
240
304
persistentStateFactory = mock ( PersistentStateFactory ) ;
305
+ platformService = TypeMoq . Mock . ofType < IPlatformService > ( ) ;
241
306
} ) ;
242
307
243
308
teardown ( ( ) => {
@@ -249,7 +314,14 @@ suite('Conda Inherit Env Prompt', async () => {
249
314
shouldShowPrompt . callsFake ( ( ) => Promise . resolve ( true ) ) ;
250
315
promptAndUpdate = sinon . stub ( CondaInheritEnvPrompt . prototype , 'promptAndUpdate' ) ;
251
316
promptAndUpdate . callsFake ( ( ) => Promise . resolve ( undefined ) ) ;
252
- condaInheritEnvPrompt = new CondaInheritEnvPrompt ( interpreterService . object , workspaceService . object , browserService . object , appShell . object , instance ( persistentStateFactory ) ) ;
317
+ condaInheritEnvPrompt = new CondaInheritEnvPrompt (
318
+ interpreterService . object ,
319
+ workspaceService . object ,
320
+ browserService . object ,
321
+ appShell . object ,
322
+ instance ( persistentStateFactory ) ,
323
+ platformService . object
324
+ ) ;
253
325
await condaInheritEnvPrompt . initializeInBackground ( resource ) ;
254
326
assert . ok ( shouldShowPrompt . calledOnce ) ;
255
327
assert . ok ( promptAndUpdate . calledOnce ) ;
@@ -260,7 +332,14 @@ suite('Conda Inherit Env Prompt', async () => {
260
332
shouldShowPrompt . callsFake ( ( ) => Promise . resolve ( false ) ) ;
261
333
promptAndUpdate = sinon . stub ( CondaInheritEnvPrompt . prototype , 'promptAndUpdate' ) ;
262
334
promptAndUpdate . callsFake ( ( ) => Promise . resolve ( undefined ) ) ;
263
- condaInheritEnvPrompt = new CondaInheritEnvPrompt ( interpreterService . object , workspaceService . object , browserService . object , appShell . object , instance ( persistentStateFactory ) ) ;
335
+ condaInheritEnvPrompt = new CondaInheritEnvPrompt (
336
+ interpreterService . object ,
337
+ workspaceService . object ,
338
+ browserService . object ,
339
+ appShell . object ,
340
+ instance ( persistentStateFactory ) ,
341
+ platformService . object
342
+ ) ;
264
343
await condaInheritEnvPrompt . initializeInBackground ( resource ) ;
265
344
assert . ok ( shouldShowPrompt . calledOnce ) ;
266
345
assert . ok ( promptAndUpdate . notCalled ) ;
@@ -276,8 +355,16 @@ suite('Conda Inherit Env Prompt', async () => {
276
355
persistentStateFactory = mock ( PersistentStateFactory ) ;
277
356
browserService = TypeMoq . Mock . ofType < IBrowserService > ( ) ;
278
357
notificationPromptEnabled = TypeMoq . Mock . ofType < IPersistentState < any > > ( ) ;
358
+ platformService = TypeMoq . Mock . ofType < IPlatformService > ( ) ;
279
359
when ( persistentStateFactory . createGlobalPersistentState ( condaInheritEnvPromptKey , true ) ) . thenReturn ( notificationPromptEnabled . object ) ;
280
- condaInheritEnvPrompt = new CondaInheritEnvPrompt ( interpreterService . object , workspaceService . object , browserService . object , appShell . object , instance ( persistentStateFactory ) ) ;
360
+ condaInheritEnvPrompt = new CondaInheritEnvPrompt (
361
+ interpreterService . object ,
362
+ workspaceService . object ,
363
+ browserService . object ,
364
+ appShell . object ,
365
+ instance ( persistentStateFactory ) ,
366
+ platformService . object
367
+ ) ;
281
368
} ) ;
282
369
283
370
test ( 'Does not display prompt if it is disabled' , async ( ) => {
0 commit comments