@@ -10,7 +10,11 @@ import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../../c
10
10
import { IFileSystem , IPlatformService } from '../../../client/common/platform/types' ;
11
11
import { createCondaEnv } from '../../../client/common/process/pythonEnvironment' ;
12
12
import { createPythonProcessService } from '../../../client/common/process/pythonProcess' ;
13
- import { IProcessService , IPythonExecutionFactory } from '../../../client/common/process/types' ;
13
+ import {
14
+ IProcessService ,
15
+ IPythonExecutionFactory ,
16
+ IPythonExecutionService ,
17
+ } from '../../../client/common/process/types' ;
14
18
import {
15
19
ITerminalService ,
16
20
ITerminalServiceFactory ,
@@ -26,6 +30,7 @@ import { ICodeExecutionService } from '../../../client/terminals/types';
26
30
import { PYTHON_PATH } from '../../common' ;
27
31
import * as sinon from 'sinon' ;
28
32
import assert from 'assert' ;
33
+ import { PythonExecInfo } from '../../../client/pythonEnvironments/exec' ;
29
34
30
35
suite ( 'Terminal - Code Execution' , ( ) => {
31
36
[ 'Terminal Execution' , 'Repl Execution' , 'Django Execution' ] . forEach ( ( testSuiteName ) => {
@@ -143,7 +148,14 @@ suite('Terminal - Code Execution', () => {
143
148
platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => isWindows ) ;
144
149
platform . setup ( ( p ) => p . isMac ) . returns ( ( ) => isOsx ) ;
145
150
platform . setup ( ( p ) => p . isLinux ) . returns ( ( ) => isLinux ) ;
146
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => PYTHON_PATH ) ;
151
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
152
+ pythonExecutionFactory
153
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
154
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
155
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
156
+ executionService
157
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
158
+ . returns ( ( ) => ( ( { command : PYTHON_PATH , args : [ ] } as unknown ) as PythonExecInfo ) ) ;
147
159
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
148
160
149
161
await executor . initializeRepl ( ) ;
@@ -176,7 +188,14 @@ suite('Terminal - Code Execution', () => {
176
188
workspace . setup ( ( w ) => w . rootPath ) . returns ( ( ) => path . join ( 'c:' , 'path' , 'to' ) ) ;
177
189
workspaceFolder . setup ( ( w ) => w . uri ) . returns ( ( ) => Uri . file ( path . join ( 'c:' , 'path' , 'to' ) ) ) ;
178
190
platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => true ) ;
179
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => PYTHON_PATH ) ;
191
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
192
+ pythonExecutionFactory
193
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
194
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
195
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
196
+ executionService
197
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
198
+ . returns ( ( ) => ( ( { command : PYTHON_PATH , args : [ ] } as unknown ) as PythonExecInfo ) ) ;
180
199
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
181
200
182
201
await executor . executeFile ( file ) ;
@@ -201,7 +220,14 @@ suite('Terminal - Code Execution', () => {
201
220
workspace . setup ( ( w ) => w . rootPath ) . returns ( ( ) => path . join ( 'c:' , 'path' , 'to' ) ) ;
202
221
workspaceFolder . setup ( ( w ) => w . uri ) . returns ( ( ) => Uri . file ( path . join ( 'c:' , 'path' , 'to' ) ) ) ;
203
222
platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => true ) ;
204
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => PYTHON_PATH ) ;
223
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
224
+ pythonExecutionFactory
225
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
226
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
227
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
228
+ executionService
229
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
230
+ . returns ( ( ) => ( ( { command : PYTHON_PATH , args : [ ] } as unknown ) as PythonExecInfo ) ) ;
205
231
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
206
232
207
233
await executor . executeFile ( file ) ;
@@ -217,7 +243,14 @@ suite('Terminal - Code Execution', () => {
217
243
workspace . setup ( ( w ) => w . getWorkspaceFolder ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => workspaceFolder . object ) ;
218
244
workspaceFolder . setup ( ( w ) => w . uri ) . returns ( ( ) => Uri . file ( path . join ( 'c' , 'path' , 'to' ) ) ) ;
219
245
platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => false ) ;
220
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => PYTHON_PATH ) ;
246
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
247
+ pythonExecutionFactory
248
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
249
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
250
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
251
+ executionService
252
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
253
+ . returns ( ( ) => ( ( { command : PYTHON_PATH , args : [ ] } as unknown ) as PythonExecInfo ) ) ;
221
254
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
222
255
223
256
await executor . executeFile ( file ) ;
@@ -241,7 +274,14 @@ suite('Terminal - Code Execution', () => {
241
274
workspace . setup ( ( w ) => w . getWorkspaceFolder ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => workspaceFolder . object ) ;
242
275
workspaceFolder . setup ( ( w ) => w . uri ) . returns ( ( ) => Uri . file ( path . join ( 'c' , 'path' , 'to' ) ) ) ;
243
276
platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => isWindows ) ;
244
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => PYTHON_PATH ) ;
277
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
278
+ pythonExecutionFactory
279
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
280
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
281
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
282
+ executionService
283
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
284
+ . returns ( ( ) => ( ( { command : PYTHON_PATH , args : [ ] } as unknown ) as PythonExecInfo ) ) ;
245
285
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
246
286
247
287
await executor . executeFile ( file ) ;
@@ -267,7 +307,14 @@ suite('Terminal - Code Execution', () => {
267
307
. setup ( ( w ) => w . uri )
268
308
. returns ( ( ) => Uri . file ( path . join ( 'c' , 'path' , 'to' , 'file with spaces in path' ) ) ) ;
269
309
platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => isWindows ) ;
270
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => PYTHON_PATH ) ;
310
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
311
+ pythonExecutionFactory
312
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
313
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
314
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
315
+ executionService
316
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
317
+ . returns ( ( ) => ( ( { command : PYTHON_PATH , args : [ ] } as unknown ) as PythonExecInfo ) ) ;
271
318
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
272
319
273
320
await executor . executeFile ( file ) ;
@@ -288,7 +335,14 @@ suite('Terminal - Code Execution', () => {
288
335
terminalSettings . setup ( ( t ) => t . executeInFileDir ) . returns ( ( ) => true ) ;
289
336
workspace . setup ( ( w ) => w . getWorkspaceFolder ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => undefined ) ;
290
337
platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => isWindows ) ;
291
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => PYTHON_PATH ) ;
338
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
339
+ pythonExecutionFactory
340
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
341
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
342
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
343
+ executionService
344
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
345
+ . returns ( ( ) => ( ( { command : PYTHON_PATH , args : [ ] } as unknown ) as PythonExecInfo ) ) ;
292
346
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
293
347
294
348
await executor . executeFile ( file ) ;
@@ -309,7 +363,14 @@ suite('Terminal - Code Execution', () => {
309
363
file : Uri ,
310
364
) : Promise < void > {
311
365
platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => isWindows ) ;
312
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => pythonPath ) ;
366
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
367
+ pythonExecutionFactory
368
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
369
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
370
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
371
+ executionService
372
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
373
+ . returns ( ( ) => ( ( { command : pythonPath , args : [ ] } as unknown ) as PythonExecInfo ) ) ;
313
374
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
314
375
terminalSettings . setup ( ( t ) => t . executeInFileDir ) . returns ( ( ) => false ) ;
315
376
workspace . setup ( ( w ) => w . getWorkspaceFolder ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => undefined ) ;
@@ -353,7 +414,15 @@ suite('Terminal - Code Execution', () => {
353
414
file : Uri ,
354
415
condaEnv : { name : string ; path : string } ,
355
416
) : Promise < void > {
356
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => pythonPath ) ;
417
+ const condaRunArgs = 'conda run args' ;
418
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
419
+ pythonExecutionFactory
420
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
421
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
422
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
423
+ executionService
424
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
425
+ . returns ( ( ) => ( ( { command : pythonPath , args : condaRunArgs } as unknown ) as PythonExecInfo ) ) ;
357
426
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
358
427
terminalSettings . setup ( ( t ) => t . executeInFileDir ) . returns ( ( ) => false ) ;
359
428
workspace . setup ( ( w ) => w . getWorkspaceFolder ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => undefined ) ;
@@ -385,7 +454,7 @@ suite('Terminal - Code Execution', () => {
385
454
386
455
await executor . executeFile ( file ) ;
387
456
388
- const expectedArgs = [ ...terminalArgs , file . fsPath . fileToCommandArgument ( ) ] ;
457
+ const expectedArgs = [ ...condaRunArgs , ... terminalArgs , file . fsPath . fileToCommandArgument ( ) ] ;
389
458
390
459
terminalService . verify (
391
460
async ( t ) => t . sendCommand ( TypeMoq . It . isValue ( pythonPath ) , TypeMoq . It . isValue ( expectedArgs ) ) ,
@@ -419,7 +488,14 @@ suite('Terminal - Code Execution', () => {
419
488
. setup ( ( p ) => p . createCondaExecutionService ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
420
489
. returns ( ( ) => Promise . resolve ( undefined ) ) ;
421
490
platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => isWindows ) ;
422
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => pythonPath ) ;
491
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
492
+ pythonExecutionFactory
493
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
494
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
495
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
496
+ executionService
497
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
498
+ . returns ( ( ) => ( ( { command : pythonPath , args : [ ] } as unknown ) as PythonExecInfo ) ) ;
423
499
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
424
500
const expectedTerminalArgs = isDjangoRepl ? terminalArgs . concat ( [ 'manage.py' , 'shell' ] ) : terminalArgs ;
425
501
@@ -469,7 +545,14 @@ suite('Terminal - Code Execution', () => {
469
545
terminalArgs : string [ ] ,
470
546
condaEnv : { name : string ; path : string } ,
471
547
) {
472
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => pythonPath ) ;
548
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
549
+ pythonExecutionFactory
550
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
551
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
552
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
553
+ executionService
554
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
555
+ . returns ( ( ) => ( ( { command : pythonPath , args : [ ] } as unknown ) as PythonExecInfo ) ) ;
473
556
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
474
557
475
558
const condaFile = 'conda' ;
@@ -539,7 +622,14 @@ suite('Terminal - Code Execution', () => {
539
622
const terminalArgs = [ '-a' , 'b' , 'c' ] ;
540
623
541
624
platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => false ) ;
542
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => pythonPath ) ;
625
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
626
+ pythonExecutionFactory
627
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
628
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
629
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
630
+ executionService
631
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
632
+ . returns ( ( ) => ( ( { command : pythonPath , args : [ ] } as unknown ) as PythonExecInfo ) ) ;
543
633
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
544
634
545
635
await executor . execute ( 'cmd1' ) ;
@@ -558,7 +648,14 @@ suite('Terminal - Code Execution', () => {
558
648
const pythonPath = 'usr/bin/python1234' ;
559
649
const terminalArgs = [ '-a' , 'b' , 'c' ] ;
560
650
platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => false ) ;
561
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => pythonPath ) ;
651
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
652
+ pythonExecutionFactory
653
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
654
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
655
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
656
+ executionService
657
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
658
+ . returns ( ( ) => ( ( { command : pythonPath , args : [ ] } as unknown ) as PythonExecInfo ) ) ;
562
659
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
563
660
564
661
let closeTerminalCallback : undefined | ( ( ) => void ) ;
@@ -605,7 +702,14 @@ suite('Terminal - Code Execution', () => {
605
702
const pythonPath = 'usr/bin/python1234' ;
606
703
const terminalArgs = [ '-a' , 'b' , 'c' ] ;
607
704
platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => false ) ;
608
- settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => pythonPath ) ;
705
+ const executionService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
706
+ pythonExecutionFactory
707
+ . setup ( ( p ) => p . create ( TypeMoq . It . isAny ( ) ) )
708
+ . returns ( ( ) => Promise . resolve ( executionService . object ) ) ;
709
+ executionService . setup ( ( p ) => ( p as any ) . then ) . returns ( ( ) => undefined ) ;
710
+ executionService
711
+ . setup ( ( e ) => e . getExecutionInfo ( ) )
712
+ . returns ( ( ) => ( ( { command : pythonPath , args : [ ] } as unknown ) as PythonExecInfo ) ) ;
609
713
terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
610
714
611
715
await executor . execute ( 'cmd1' ) ;
0 commit comments