@@ -12,9 +12,7 @@ import { IApplicationShell } from '../../client/common/application/types';
1212import { IPythonSettings } from '../../client/common/configSettings' ;
1313import { STANDARD_OUTPUT_CHANNEL } from '../../client/common/constants' ;
1414import { PythonInstaller } from '../../client/common/installer/pythonInstallation' ;
15- import { IFileSystem , IPlatformService } from '../../client/common/platform/types' ;
16- import { IProcessService , ObservableExecutionResult , Output } from '../../client/common/process/types' ;
17- import { IOutputChannel } from '../../client/common/types' ;
15+ import { IPlatformService } from '../../client/common/platform/types' ;
1816import { IInterpreterLocatorService } from '../../client/interpreter/contracts' ;
1917import { InterpreterType , PythonInterpreter } from '../../client/interpreter/contracts' ;
2018import { ServiceContainer } from '../../client/ioc/container' ;
@@ -26,12 +24,9 @@ class TestContext {
2624 public serviceManager : ServiceManager ;
2725 public serviceContainer : IServiceContainer ;
2826 public platform : TypeMoq . IMock < IPlatformService > ;
29- public fileSystem : TypeMoq . IMock < IFileSystem > ;
3027 public appShell : TypeMoq . IMock < IApplicationShell > ;
3128 public locator : TypeMoq . IMock < IInterpreterLocatorService > ;
3229 public settings : TypeMoq . IMock < IPythonSettings > ;
33- public process : TypeMoq . IMock < IProcessService > ;
34- public output : TypeMoq . IMock < vscode . OutputChannel > ;
3530 public pythonInstaller : PythonInstaller ;
3631
3732 constructor ( isMac : boolean ) {
@@ -40,19 +35,13 @@ class TestContext {
4035 this . serviceContainer = new ServiceContainer ( cont ) ;
4136
4237 this . platform = TypeMoq . Mock . ofType < IPlatformService > ( ) ;
43- this . fileSystem = TypeMoq . Mock . ofType < IFileSystem > ( ) ;
4438 this . appShell = TypeMoq . Mock . ofType < IApplicationShell > ( ) ;
4539 this . locator = TypeMoq . Mock . ofType < IInterpreterLocatorService > ( ) ;
4640 this . settings = TypeMoq . Mock . ofType < IPythonSettings > ( ) ;
47- this . process = TypeMoq . Mock . ofType < IProcessService > ( ) ;
48- this . output = TypeMoq . Mock . ofType < vscode . OutputChannel > ( ) ;
4941
5042 this . serviceManager . addSingletonInstance < IPlatformService > ( IPlatformService , this . platform . object ) ;
51- this . serviceManager . addSingletonInstance < IFileSystem > ( IFileSystem , this . fileSystem . object ) ;
5243 this . serviceManager . addSingletonInstance < IApplicationShell > ( IApplicationShell , this . appShell . object ) ;
5344 this . serviceManager . addSingletonInstance < IInterpreterLocatorService > ( IInterpreterLocatorService , this . locator . object ) ;
54- this . serviceManager . addSingletonInstance < IProcessService > ( IProcessService , this . process . object ) ;
55- this . serviceManager . addSingletonInstance < vscode . OutputChannel > ( IOutputChannel , this . output . object , STANDARD_OUTPUT_CHANNEL ) ;
5645 this . pythonInstaller = new PythonInstaller ( this . serviceContainer ) ;
5746
5847 this . platform . setup ( x => x . isMac ) . returns ( ( ) => isMac ) ;
@@ -80,7 +69,7 @@ suite('Installation', () => {
8069 assert . equal ( showErrorMessageCalled , false , 'Disabling checks has no effect' ) ;
8170 } ) ;
8271
83- test ( 'Windows: Python missing' , async ( ) => {
72+ test ( 'Python missing' , async ( ) => {
8473 const c = new TestContext ( false ) ;
8574 let showErrorMessageCalled = false ;
8675 let openUrlCalled = false ;
@@ -100,7 +89,7 @@ suite('Installation', () => {
10089 assert . equal ( url , 'https://www.python.org/downloads' , 'Python download page is incorrect' ) ;
10190 } ) ;
10291
103- test ( 'Mac: Python missing ' , async ( ) => {
92+ test ( 'Mac: Default Python warning ' , async ( ) => {
10493 const c = new TestContext ( true ) ;
10594 let called = false ;
10695 c . appShell . setup ( x => x . showWarningMessage ( TypeMoq . It . isAnyString ( ) ) ) . callback ( ( ) => called = true ) ;
@@ -115,89 +104,4 @@ suite('Installation', () => {
115104 assert . equal ( passed , true , 'Default MacOS Python not accepted' ) ;
116105 assert . equal ( called , true , 'Warning not shown' ) ;
117106 } ) ;
118-
119- test ( 'Mac: Default Python, user refused install' , async ( ) => {
120- const c = new TestContext ( true ) ;
121- let errorMessage = '' ;
122-
123- c . appShell
124- . setup ( x => x . showErrorMessage ( TypeMoq . It . isAnyString ( ) , TypeMoq . It . isAnyString ( ) , TypeMoq . It . isAnyString ( ) ) )
125- . callback ( ( m : string , a1 : string , a2 : string ) => errorMessage = m )
126- . returns ( ( ) => Promise . resolve ( 'No' ) ) ;
127- c . locator . setup ( x => x . getInterpreters ( ) ) . returns ( ( ) => Promise . resolve ( [ ] ) ) ;
128-
129- const passed = await c . pythonInstaller . checkPythonInstallation ( c . settings . object ) ;
130- assert . equal ( passed , false , 'Default MacOS Python accepted' ) ;
131- assert . equal ( errorMessage . startsWith ( 'Python that comes with MacOS is not supported' ) , true , 'Error message that MacOS Python not supported not shown' ) ;
132- } ) ;
133-
134- test ( 'Mac: Default Python, Brew installation' , async ( ) => {
135- const c = new TestContext ( true ) ;
136- let errorMessage = '' ;
137- let processName = '' ;
138- let args ;
139- let brewPath ;
140- let outputShown = false ;
141-
142- c . appShell
143- . setup ( x => x . showErrorMessage ( TypeMoq . It . isAnyString ( ) , TypeMoq . It . isAnyString ( ) , TypeMoq . It . isAnyString ( ) ) )
144- . returns ( ( ) => Promise . resolve ( 'Yes' ) ) ;
145- c . appShell
146- . setup ( x => x . showErrorMessage ( TypeMoq . It . isAnyString ( ) ) )
147- . callback ( ( m : string ) => errorMessage = m ) ;
148- c . locator . setup ( x => x . getInterpreters ( ) ) . returns ( ( ) => Promise . resolve ( [ ] ) ) ;
149- c . fileSystem
150- . setup ( x => x . fileExistsAsync ( TypeMoq . It . isAnyString ( ) ) )
151- . returns ( ( p : string ) => {
152- brewPath = p ;
153- return Promise . resolve ( false ) ;
154- } ) ;
155-
156- const childProcess = TypeMoq . Mock . ofType < ChildProcess > ( ) ;
157- childProcess
158- . setup ( p => p . on ( 'exit' , TypeMoq . It . isAny ( ) ) )
159- . callback ( ( e : string , listener : ( code , signal ) => void ) => {
160- listener . call ( 0 , undefined ) ;
161- } ) ;
162- const processOutput : Output < string > = {
163- source : 'stdout' ,
164- out : 'started'
165- } ;
166- const observable = new Rx . Observable < Output < string > > ( subscriber => subscriber . next ( processOutput ) ) ;
167- const brewInstallProcess : ObservableExecutionResult < string > = {
168- proc : childProcess . object ,
169- out : observable
170- } ;
171-
172- c . output . setup ( x => x . show ( ) ) . callback ( ( ) => outputShown = true ) ;
173- c . process
174- . setup ( x => x . execObservable ( TypeMoq . It . isAnyString ( ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
175- . callback ( ( p : string , a : string [ ] , o : SpawnOptions ) => {
176- processName = p ;
177- args = a ;
178- } )
179- . returns ( ( ) => brewInstallProcess ) ;
180-
181- await c . pythonInstaller . checkPythonInstallation ( c . settings . object ) ;
182-
183- assert . notEqual ( brewPath , undefined , 'Brew installer location not checked' ) ;
184- assert . equal ( brewPath , '/usr/local/bin/brew' , 'Brew installer location is incorrect' ) ;
185- assert . notEqual ( processName , undefined , 'Brew installer not invoked' ) ;
186- assert . equal ( processName , '/usr/bin/ruby' , 'Brew installer name is incorrect' ) ;
187- assert . equal ( args [ 0 ] , '-e' , 'Brew installer argument is incorrect' ) ;
188- assert . equal ( args [ 1 ] , '"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"' , 'Homebrew installer argument is incorrect' ) ;
189- assert . equal ( outputShown , true , 'Output panel not shown' ) ;
190- assert . equal ( errorMessage . startsWith ( 'Unable to install Homebrew' ) , true , 'Homebrew install failed message no shown' ) ;
191-
192- c . fileSystem
193- . setup ( x => x . fileExistsAsync ( TypeMoq . It . isAnyString ( ) ) )
194- . returns ( ( ) => Promise . resolve ( true ) ) ;
195- errorMessage = '' ;
196-
197- await c . pythonInstaller . checkPythonInstallation ( c . settings . object ) ;
198- assert . equal ( errorMessage , '' , `Unexpected error message ${ errorMessage } ` ) ;
199- assert . equal ( processName , 'brew' , 'Brew installer name is incorrect' ) ;
200- assert . equal ( args [ 0 ] , 'install' , 'Brew "install" argument is incorrect' ) ;
201- assert . equal ( args [ 1 ] , 'python' , 'Brew "python" argument is incorrect' ) ;
202- } ) ;
203107} ) ;
0 commit comments