@@ -10,7 +10,11 @@ import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../../c
1010import { IFileSystem , IPlatformService } from '../../../client/common/platform/types' ;
1111import { createCondaEnv } from '../../../client/common/process/pythonEnvironment' ;
1212import { 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' ;
1418import {
1519 ITerminalService ,
1620 ITerminalServiceFactory ,
@@ -26,6 +30,7 @@ import { ICodeExecutionService } from '../../../client/terminals/types';
2630import { PYTHON_PATH } from '../../common' ;
2731import * as sinon from 'sinon' ;
2832import assert from 'assert' ;
33+ import { PythonExecInfo } from '../../../client/pythonEnvironments/exec' ;
2934
3035suite ( 'Terminal - Code Execution' , ( ) => {
3136 [ 'Terminal Execution' , 'Repl Execution' , 'Django Execution' ] . forEach ( ( testSuiteName ) => {
@@ -143,7 +148,14 @@ suite('Terminal - Code Execution', () => {
143148 platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => isWindows ) ;
144149 platform . setup ( ( p ) => p . isMac ) . returns ( ( ) => isOsx ) ;
145150 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 ) ) ;
147159 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
148160
149161 await executor . initializeRepl ( ) ;
@@ -176,7 +188,14 @@ suite('Terminal - Code Execution', () => {
176188 workspace . setup ( ( w ) => w . rootPath ) . returns ( ( ) => path . join ( 'c:' , 'path' , 'to' ) ) ;
177189 workspaceFolder . setup ( ( w ) => w . uri ) . returns ( ( ) => Uri . file ( path . join ( 'c:' , 'path' , 'to' ) ) ) ;
178190 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 ) ) ;
180199 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
181200
182201 await executor . executeFile ( file ) ;
@@ -201,7 +220,14 @@ suite('Terminal - Code Execution', () => {
201220 workspace . setup ( ( w ) => w . rootPath ) . returns ( ( ) => path . join ( 'c:' , 'path' , 'to' ) ) ;
202221 workspaceFolder . setup ( ( w ) => w . uri ) . returns ( ( ) => Uri . file ( path . join ( 'c:' , 'path' , 'to' ) ) ) ;
203222 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 ) ) ;
205231 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
206232
207233 await executor . executeFile ( file ) ;
@@ -217,7 +243,14 @@ suite('Terminal - Code Execution', () => {
217243 workspace . setup ( ( w ) => w . getWorkspaceFolder ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => workspaceFolder . object ) ;
218244 workspaceFolder . setup ( ( w ) => w . uri ) . returns ( ( ) => Uri . file ( path . join ( 'c' , 'path' , 'to' ) ) ) ;
219245 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 ) ) ;
221254 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
222255
223256 await executor . executeFile ( file ) ;
@@ -241,7 +274,14 @@ suite('Terminal - Code Execution', () => {
241274 workspace . setup ( ( w ) => w . getWorkspaceFolder ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => workspaceFolder . object ) ;
242275 workspaceFolder . setup ( ( w ) => w . uri ) . returns ( ( ) => Uri . file ( path . join ( 'c' , 'path' , 'to' ) ) ) ;
243276 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 ) ) ;
245285 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
246286
247287 await executor . executeFile ( file ) ;
@@ -267,7 +307,14 @@ suite('Terminal - Code Execution', () => {
267307 . setup ( ( w ) => w . uri )
268308 . returns ( ( ) => Uri . file ( path . join ( 'c' , 'path' , 'to' , 'file with spaces in path' ) ) ) ;
269309 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 ) ) ;
271318 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
272319
273320 await executor . executeFile ( file ) ;
@@ -288,7 +335,14 @@ suite('Terminal - Code Execution', () => {
288335 terminalSettings . setup ( ( t ) => t . executeInFileDir ) . returns ( ( ) => true ) ;
289336 workspace . setup ( ( w ) => w . getWorkspaceFolder ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => undefined ) ;
290337 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 ) ) ;
292346 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
293347
294348 await executor . executeFile ( file ) ;
@@ -309,7 +363,14 @@ suite('Terminal - Code Execution', () => {
309363 file : Uri ,
310364 ) : Promise < void > {
311365 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 ) ) ;
313374 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
314375 terminalSettings . setup ( ( t ) => t . executeInFileDir ) . returns ( ( ) => false ) ;
315376 workspace . setup ( ( w ) => w . getWorkspaceFolder ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => undefined ) ;
@@ -353,7 +414,15 @@ suite('Terminal - Code Execution', () => {
353414 file : Uri ,
354415 condaEnv : { name : string ; path : string } ,
355416 ) : 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 ) ) ;
357426 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
358427 terminalSettings . setup ( ( t ) => t . executeInFileDir ) . returns ( ( ) => false ) ;
359428 workspace . setup ( ( w ) => w . getWorkspaceFolder ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => undefined ) ;
@@ -385,7 +454,7 @@ suite('Terminal - Code Execution', () => {
385454
386455 await executor . executeFile ( file ) ;
387456
388- const expectedArgs = [ ...terminalArgs , file . fsPath . fileToCommandArgument ( ) ] ;
457+ const expectedArgs = [ ...condaRunArgs , ... terminalArgs , file . fsPath . fileToCommandArgument ( ) ] ;
389458
390459 terminalService . verify (
391460 async ( t ) => t . sendCommand ( TypeMoq . It . isValue ( pythonPath ) , TypeMoq . It . isValue ( expectedArgs ) ) ,
@@ -419,7 +488,14 @@ suite('Terminal - Code Execution', () => {
419488 . setup ( ( p ) => p . createCondaExecutionService ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
420489 . returns ( ( ) => Promise . resolve ( undefined ) ) ;
421490 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 ) ) ;
423499 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
424500 const expectedTerminalArgs = isDjangoRepl ? terminalArgs . concat ( [ 'manage.py' , 'shell' ] ) : terminalArgs ;
425501
@@ -469,7 +545,14 @@ suite('Terminal - Code Execution', () => {
469545 terminalArgs : string [ ] ,
470546 condaEnv : { name : string ; path : string } ,
471547 ) {
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 ) ) ;
473556 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
474557
475558 const condaFile = 'conda' ;
@@ -539,7 +622,14 @@ suite('Terminal - Code Execution', () => {
539622 const terminalArgs = [ '-a' , 'b' , 'c' ] ;
540623
541624 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 ) ) ;
543633 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
544634
545635 await executor . execute ( 'cmd1' ) ;
@@ -558,7 +648,14 @@ suite('Terminal - Code Execution', () => {
558648 const pythonPath = 'usr/bin/python1234' ;
559649 const terminalArgs = [ '-a' , 'b' , 'c' ] ;
560650 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 ) ) ;
562659 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
563660
564661 let closeTerminalCallback : undefined | ( ( ) => void ) ;
@@ -605,7 +702,14 @@ suite('Terminal - Code Execution', () => {
605702 const pythonPath = 'usr/bin/python1234' ;
606703 const terminalArgs = [ '-a' , 'b' , 'c' ] ;
607704 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 ) ) ;
609713 terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => terminalArgs ) ;
610714
611715 await executor . execute ( 'cmd1' ) ;
0 commit comments