@@ -7,16 +7,18 @@ import { expect } from 'chai';
7
7
import * as fs from 'fs-extra' ;
8
8
import { EOL } from 'os' ;
9
9
import * as path from 'path' ;
10
+ import { SemVer } from 'semver' ;
10
11
import * as TypeMoq from 'typemoq' ;
11
12
import { Range , Selection , TextDocument , TextEditor , TextLine , Uri } from 'vscode' ;
12
13
import { IApplicationShell , IDocumentManager } from '../../../client/common/application/types' ;
13
14
import { EXTENSION_ROOT_DIR , PYTHON_LANGUAGE } from '../../../client/common/constants' ;
14
15
import '../../../client/common/extensions' ;
15
16
import { BufferDecoder } from '../../../client/common/process/decoder' ;
16
17
import { ProcessService } from '../../../client/common/process/proc' ;
17
- import { IPythonExecutionFactory , IPythonExecutionService } from '../../../client/common/process/types' ;
18
- import { OSType } from '../../../client/common/utils/platform' ;
18
+ import { IProcessService , IProcessServiceFactory } from '../../../client/common/process/types' ;
19
+ import { Architecture , OSType } from '../../../client/common/utils/platform' ;
19
20
import { IEnvironmentVariablesProvider } from '../../../client/common/variables/types' ;
21
+ import { IInterpreterService , InterpreterType , PythonInterpreter } from '../../../client/interpreter/contracts' ;
20
22
import { IServiceContainer } from '../../../client/ioc/types' ;
21
23
import { CodeExecutionHelper } from '../../../client/terminals/codeExecution/helper' ;
22
24
import { ICodeExecutionHelper } from '../../../client/terminals/types' ;
@@ -31,19 +33,33 @@ suite('Terminal - Code Execution Helper', () => {
31
33
let helper : ICodeExecutionHelper ;
32
34
let document : TypeMoq . IMock < TextDocument > ;
33
35
let editor : TypeMoq . IMock < TextEditor > ;
34
- let pythonService : TypeMoq . IMock < IPythonExecutionService > ;
36
+ let processService : TypeMoq . IMock < IProcessService > ;
37
+ let interpreterService : TypeMoq . IMock < IInterpreterService > ;
38
+ const workingPython : PythonInterpreter = {
39
+ path : PYTHON_PATH ,
40
+ version : new SemVer ( '3.6.6-final' ) ,
41
+ sysVersion : '1.0.0.0' ,
42
+ sysPrefix : 'Python' ,
43
+ displayName : 'Python' ,
44
+ type : InterpreterType . Unknown ,
45
+ architecture : Architecture . x64
46
+ } ;
47
+
35
48
setup ( ( ) => {
36
49
const serviceContainer = TypeMoq . Mock . ofType < IServiceContainer > ( ) ;
37
50
documentManager = TypeMoq . Mock . ofType < IDocumentManager > ( ) ;
38
51
applicationShell = TypeMoq . Mock . ofType < IApplicationShell > ( ) ;
39
52
const envVariablesProvider = TypeMoq . Mock . ofType < IEnvironmentVariablesProvider > ( ) ;
40
- pythonService = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
53
+ processService = TypeMoq . Mock . ofType < IProcessService > ( ) ;
54
+ interpreterService = TypeMoq . Mock . ofType < IInterpreterService > ( ) ;
41
55
// tslint:disable-next-line:no-any
42
- pythonService . setup ( ( x : any ) => x . then ) . returns ( ( ) => undefined ) ;
56
+ processService . setup ( ( x : any ) => x . then ) . returns ( ( ) => undefined ) ;
57
+ interpreterService . setup ( i => i . getActiveInterpreter ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => Promise . resolve ( workingPython ) ) ;
58
+ const processServiceFactory = TypeMoq . Mock . ofType < IProcessServiceFactory > ( ) ;
59
+ processServiceFactory . setup ( p => p . create ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => Promise . resolve ( processService . object ) ) ;
43
60
envVariablesProvider . setup ( e => e . getEnvironmentVariables ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => Promise . resolve ( { } ) ) ;
44
- const pythonExecFactory = TypeMoq . Mock . ofType < IPythonExecutionFactory > ( ) ;
45
- pythonExecFactory . setup ( p => p . create ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => Promise . resolve ( pythonService . object ) ) ;
46
- serviceContainer . setup ( c => c . get ( TypeMoq . It . isValue ( IPythonExecutionFactory ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => pythonExecFactory . object ) ;
61
+ serviceContainer . setup ( c => c . get ( TypeMoq . It . isValue ( IProcessServiceFactory ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => processServiceFactory . object ) ;
62
+ serviceContainer . setup ( c => c . get ( TypeMoq . It . isValue ( IInterpreterService ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => interpreterService . object ) ;
47
63
serviceContainer . setup ( c => c . get ( TypeMoq . It . isValue ( IDocumentManager ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => documentManager . object ) ;
48
64
serviceContainer . setup ( c => c . get ( TypeMoq . It . isValue ( IApplicationShell ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => applicationShell . object ) ;
49
65
serviceContainer . setup ( c => c . get ( TypeMoq . It . isValue ( IEnvironmentVariablesProvider ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => envVariablesProvider . object ) ;
@@ -56,10 +72,10 @@ suite('Terminal - Code Execution Helper', () => {
56
72
57
73
async function ensureBlankLinesAreRemoved ( source : string , expectedSource : string ) {
58
74
const actualProcessService = new ProcessService ( new BufferDecoder ( ) ) ;
59
- pythonService
60
- . setup ( p => p . exec ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
61
- . returns ( ( args , options ) => {
62
- return actualProcessService . exec . apply ( actualProcessService , [ PYTHON_PATH , args , options ] ) ;
75
+ processService
76
+ . setup ( p => p . exec ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
77
+ . returns ( ( file , args , options ) => {
78
+ return actualProcessService . exec . apply ( actualProcessService , [ file , args , options ] ) ;
63
79
} ) ;
64
80
const normalizedZCode = await helper . normalizeLines ( source ) ;
65
81
// In case file has been saved with different line endings.
@@ -81,9 +97,9 @@ suite('Terminal - Code Execution Helper', () => {
81
97
test ( 'Ensure there are no multiple-CR elements in the normalized code.' , async ( ) => {
82
98
const code = [ 'import sys' , '' , '' , '' , 'print(sys.executable)' , '' , 'print("1234")' , '' , '' , 'print(1)' , 'print(2)' ] ;
83
99
const actualProcessService = new ProcessService ( new BufferDecoder ( ) ) ;
84
- pythonService
85
- . setup ( p => p . exec ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
86
- . returns ( ( args , options ) => {
100
+ processService
101
+ . setup ( p => p . exec ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
102
+ . returns ( ( _file , args , options ) => {
87
103
return actualProcessService . exec . apply ( actualProcessService , [ PYTHON_PATH , args , options ] ) ;
88
104
} ) ;
89
105
const normalizedCode = await helper . normalizeLines ( code . join ( EOL ) ) ;
0 commit comments