77
88import  {  expect ,  use  }  from  'chai' ; 
99import  *  as  chaiAsPromised  from  'chai-as-promised' ; 
10- import  {  EventEmitter  }  from  'events' ; 
1110import  {  Container  }  from  'inversify' ; 
1211import  *  as  path  from  'path' ; 
1312import  {  SemVer  }  from  'semver' ; 
@@ -17,7 +16,7 @@ import { IDocumentManager, IWorkspaceService } from '../../client/common/applica
1716import  {  getArchitectureDisplayName  }  from  '../../client/common/platform/registry' ; 
1817import  {  IFileSystem  }  from  '../../client/common/platform/types' ; 
1918import  {  IPythonExecutionFactory ,  IPythonExecutionService  }  from  '../../client/common/process/types' ; 
20- import  {  IConfigurationService ,  IDisposableRegistry ,  IPersistentStateFactory  }  from  '../../client/common/types' ; 
19+ import  {  IConfigurationService ,  IDisposableRegistry ,  IPersistentStateFactory ,   IPythonSettings  }  from  '../../client/common/types' ; 
2120import  *  as  EnumEx  from  '../../client/common/utils/enum' ; 
2221import  {  noop  }  from  '../../client/common/utils/misc' ; 
2322import  {  Architecture  }  from  '../../client/common/utils/platform' ; 
@@ -37,6 +36,7 @@ import { InterpreterService } from '../../client/interpreter/interpreterService'
3736import  {  IVirtualEnvironmentManager  }  from  '../../client/interpreter/virtualEnvs/types' ; 
3837import  {  ServiceContainer  }  from  '../../client/ioc/container' ; 
3938import  {  ServiceManager  }  from  '../../client/ioc/serviceManager' ; 
39+ import  {  PYTHON_PATH  }  from  '../common' ; 
4040
4141use ( chaiAsPromised ) ; 
4242
@@ -69,6 +69,8 @@ suite('Interpreters service', () => {
6969 let  persistentStateFactory : TypeMoq . IMock < IPersistentStateFactory > ; 
7070 let  pythonExecutionFactory : TypeMoq . IMock < IPythonExecutionFactory > ; 
7171 let  pythonExecutionService : TypeMoq . IMock < IPythonExecutionService > ; 
72+  let  configService : TypeMoq . IMock < IConfigurationService > ; 
73+  let  pythonSettings : TypeMoq . IMock < IPythonSettings > ; 
7274 type  ConfigValue < T >  =  {  key : string ;  defaultValue ?: T ;  globalValue ?: T ;  workspaceValue ?: T ;  workspaceFolderValue ?: T  } ; 
7375
7476 function  setupSuite ( )  { 
@@ -88,6 +90,11 @@ suite('Interpreters service', () => {
8890 persistentStateFactory  =  TypeMoq . Mock . ofType < IPersistentStateFactory > ( ) ; 
8991 pythonExecutionFactory  =  TypeMoq . Mock . ofType < IPythonExecutionFactory > ( ) ; 
9092 pythonExecutionService  =  TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ; 
93+  configService  =  TypeMoq . Mock . ofType < IConfigurationService > ( ) ; 
94+ 
95+  pythonSettings  =  TypeMoq . Mock . ofType < IPythonSettings > ( ) ; 
96+  pythonSettings . setup ( s  =>  s . pythonPath ) . returns ( ( )  =>  PYTHON_PATH ) ; 
97+  configService . setup ( c  =>  c . getSettings ( TypeMoq . It . isAny ( ) ) ) . returns ( ( )  =>  pythonSettings . object ) ; 
9198
9299 pythonExecutionService . setup ( ( p : any )  =>  p . then ) . returns ( ( )  =>  undefined ) ; 
93100 workspace . setup ( x  =>  x . getConfiguration ( 'python' ,  TypeMoq . It . isAny ( ) ) ) . returns ( ( )  =>  config . object ) ; 
@@ -113,6 +120,7 @@ suite('Interpreters service', () => {
113120 serviceManager . addSingletonInstance < IPersistentStateFactory > ( IPersistentStateFactory ,  persistentStateFactory . object ) ; 
114121 serviceManager . addSingletonInstance < IPythonExecutionFactory > ( IPythonExecutionFactory ,  pythonExecutionFactory . object ) ; 
115122 serviceManager . addSingletonInstance < IPythonExecutionService > ( IPythonExecutionService ,  pythonExecutionService . object ) ; 
123+  serviceManager . addSingletonInstance < IConfigurationService > ( IConfigurationService ,  configService . object ) ; 
116124
117125 pipenvLocator  =  TypeMoq . Mock . ofType < IInterpreterLocatorService > ( ) ; 
118126 wksLocator  =  TypeMoq . Mock . ofType < IInterpreterLocatorService > ( ) ; 
@@ -149,21 +157,18 @@ suite('Interpreters service', () => {
149157 } ) ; 
150158 } ) ; 
151159
152-  test ( 'Changes to active document should invoke intrepreter .refresh method' ,  async  ( )  =>  { 
160+  test ( 'Changes to active document should invoke interpreter .refresh method' ,  async  ( )  =>  { 
153161 const  service  =  new  InterpreterService ( serviceContainer ) ; 
154-  const  configService  =  TypeMoq . Mock . ofType < IConfigurationService > ( ) ; 
155162 const  documentManager  =  TypeMoq . Mock . ofType < IDocumentManager > ( ) ; 
156163
157164 let  activeTextEditorChangeHandler : Function  |  undefined ; 
158165 documentManager . setup ( d  =>  d . onDidChangeActiveTextEditor ( TypeMoq . It . isAny ( ) ,  TypeMoq . It . isAny ( ) ) ) . returns ( handler  =>  { 
159166 activeTextEditorChangeHandler  =  handler ; 
160167 return  {  dispose : noop  } ; 
161168 } ) ; 
162-  serviceManager . addSingletonInstance ( IConfigurationService ,  configService . object ) ; 
163169 serviceManager . addSingletonInstance ( IDocumentManager ,  documentManager . object ) ; 
164170
165171 // tslint:disable-next-line:no-any 
166-  configService . setup ( c  =>  c . getSettings ( TypeMoq . It . isAny ( ) ) ) . returns ( ( )  =>  new  EventEmitter ( )  as  any ) ; 
167172 service . initialize ( ) ; 
168173 const  textEditor  =  TypeMoq . Mock . ofType < TextEditor > ( ) ; 
169174 const  uri  =  Uri . file ( path . join ( 'usr' ,  'file.py' ) ) ; 
@@ -175,21 +180,18 @@ suite('Interpreters service', () => {
175180 interpreterDisplay . verify ( i  =>  i . refresh ( TypeMoq . It . isValue ( uri ) ) ,  TypeMoq . Times . once ( ) ) ; 
176181 } ) ; 
177182
178-  test ( 'If there is no active document then intrepreter .refresh should not be invoked' ,  async  ( )  =>  { 
183+  test ( 'If there is no active document then interpreter .refresh should not be invoked' ,  async  ( )  =>  { 
179184 const  service  =  new  InterpreterService ( serviceContainer ) ; 
180-  const  configService  =  TypeMoq . Mock . ofType < IConfigurationService > ( ) ; 
181185 const  documentManager  =  TypeMoq . Mock . ofType < IDocumentManager > ( ) ; 
182186
183187 let  activeTextEditorChangeHandler : Function  |  undefined ; 
184188 documentManager . setup ( d  =>  d . onDidChangeActiveTextEditor ( TypeMoq . It . isAny ( ) ,  TypeMoq . It . isAny ( ) ) ) . returns ( handler  =>  { 
185189 activeTextEditorChangeHandler  =  handler ; 
186190 return  {  dispose : noop  } ; 
187191 } ) ; 
188-  serviceManager . addSingletonInstance ( IConfigurationService ,  configService . object ) ; 
189192 serviceManager . addSingletonInstance ( IDocumentManager ,  documentManager . object ) ; 
190193
191194 // tslint:disable-next-line:no-any 
192-  configService . setup ( c  =>  c . getSettings ( TypeMoq . It . isAny ( ) ) ) . returns ( ( )  =>  new  EventEmitter ( )  as  any ) ; 
193195 service . initialize ( ) ; 
194196 activeTextEditorChangeHandler ! ( ) ; 
195197
0 commit comments