3
3
4
4
'use strict' ;
5
5
6
- import { anything , deepEqual , instance , mock , verify , when } from 'ts-mockito' ;
6
+ import { anything , deepEqual , instance , mock , reset , verify , when } from 'ts-mockito' ;
7
7
import * as TypeMoq from 'typemoq' ;
8
8
import { ConfigurationTarget , Disposable , Uri } from 'vscode' ;
9
9
import { ApplicationShell } from '../../../client/common/application/applicationShell' ;
@@ -13,7 +13,7 @@ import { IPersistentState, IPersistentStateFactory } from '../../../client/commo
13
13
import { Common } from '../../../client/common/utils/localize' ;
14
14
import { PythonPathUpdaterService } from '../../../client/interpreter/configuration/pythonPathUpdaterService' ;
15
15
import { IPythonPathUpdaterServiceManager } from '../../../client/interpreter/configuration/types' ;
16
- import { IComponentAdapter , IInterpreterHelper } from '../../../client/interpreter/contracts' ;
16
+ import { IComponentAdapter , IInterpreterHelper , IInterpreterService } from '../../../client/interpreter/contracts' ;
17
17
import { InterpreterHelper } from '../../../client/interpreter/helpers' ;
18
18
import { VirtualEnvironmentPrompt } from '../../../client/interpreter/virtualEnvs/virtualEnvPrompt' ;
19
19
import { PythonEnvironment } from '../../../client/pythonEnvironments/info' ;
@@ -34,12 +34,18 @@ suite('Virtual Environment Prompt', () => {
34
34
let disposable : Disposable ;
35
35
let appShell : IApplicationShell ;
36
36
let componentAdapter : IComponentAdapter ;
37
+ let interpreterService : IInterpreterService ;
37
38
let environmentPrompt : VirtualEnvironmentPromptTest ;
38
39
setup ( ( ) => {
39
40
persistentStateFactory = mock ( PersistentStateFactory ) ;
40
41
helper = mock ( InterpreterHelper ) ;
41
42
pythonPathUpdaterService = mock ( PythonPathUpdaterService ) ;
42
43
componentAdapter = mock < IComponentAdapter > ( ) ;
44
+ interpreterService = mock < IInterpreterService > ( ) ;
45
+ when ( interpreterService . getActiveInterpreter ( anything ( ) ) ) . thenResolve ( ( {
46
+ id : 'selected' ,
47
+ path : 'path/to/selected' ,
48
+ } as unknown ) as PythonEnvironment ) ;
43
49
disposable = mock ( Disposable ) ;
44
50
appShell = mock ( ApplicationShell ) ;
45
51
environmentPrompt = new VirtualEnvironmentPromptTest (
@@ -49,6 +55,7 @@ suite('Virtual Environment Prompt', () => {
49
55
[ instance ( disposable ) ] ,
50
56
instance ( appShell ) ,
51
57
instance ( componentAdapter ) ,
58
+ instance ( interpreterService ) ,
52
59
) ;
53
60
} ) ;
54
61
@@ -77,7 +84,36 @@ suite('Virtual Environment Prompt', () => {
77
84
verify ( appShell . showInformationMessage ( anything ( ) , ...prompts ) ) . once ( ) ;
78
85
} ) ;
79
86
80
- test ( 'When in experiment, user is notified if interpreter exists and only python path to global interpreter is specified in settings' , async ( ) => {
87
+ test ( 'User is not notified if currently selected interpreter is the same as new interpreter' , async ( ) => {
88
+ const resource = Uri . file ( 'a' ) ;
89
+ const interpreter1 = { path : 'path/to/interpreter1' } ;
90
+ const interpreter2 = { path : 'path/to/interpreter2' } ;
91
+ const prompts = [ Common . bannerLabelYes ( ) , Common . bannerLabelNo ( ) , Common . doNotShowAgain ( ) ] ;
92
+ const notificationPromptEnabled = TypeMoq . Mock . ofType < IPersistentState < boolean > > ( ) ;
93
+
94
+ // Return interpreters using the component adapter instead
95
+ when ( componentAdapter . getWorkspaceVirtualEnvInterpreters ( resource ) ) . thenResolve ( [
96
+ interpreter1 ,
97
+ interpreter2 ,
98
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
+ ] as any ) ;
100
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
+ when ( helper . getBestInterpreter ( deepEqual ( [ interpreter1 , interpreter2 ] as any ) ) ) . thenReturn ( interpreter2 as any ) ;
102
+ reset ( interpreterService ) ;
103
+ when ( interpreterService . getActiveInterpreter ( anything ( ) ) ) . thenResolve (
104
+ ( interpreter2 as unknown ) as PythonEnvironment ,
105
+ ) ;
106
+ when ( persistentStateFactory . createWorkspacePersistentState ( anything ( ) , true ) ) . thenReturn (
107
+ notificationPromptEnabled . object ,
108
+ ) ;
109
+ notificationPromptEnabled . setup ( ( n ) => n . value ) . returns ( ( ) => true ) ;
110
+ when ( appShell . showInformationMessage ( anything ( ) , ...prompts ) ) . thenResolve ( ) ;
111
+
112
+ await environmentPrompt . handleNewEnvironment ( resource ) ;
113
+
114
+ verify ( appShell . showInformationMessage ( anything ( ) , ...prompts ) ) . never ( ) ;
115
+ } ) ;
116
+ test ( 'User is notified if interpreter exists and only python path to global interpreter is specified in settings' , async ( ) => {
81
117
const resource = Uri . file ( 'a' ) ;
82
118
const interpreter1 = { path : 'path/to/interpreter1' } ;
83
119
const interpreter2 = { path : 'path/to/interpreter2' } ;
0 commit comments