@@ -5,10 +5,12 @@ import * as assert from 'assert';
5
5
import * as sinon from 'sinon' ;
6
6
import { CompleteEnvInfoFunction , PythonEnvInfoCache } from '../../../client/pythonEnvironments/base/envsCache' ;
7
7
import { PythonEnvInfo , PythonEnvKind } from '../../../client/pythonEnvironments/base/info' ;
8
- import * as externalDeps from '../../../client/pythonEnvironments/common/externalDependencies' ;
8
+ import * as externalDependencies from '../../../client/pythonEnvironments/common/externalDependencies' ;
9
+ import * as envInfo from '../../../client/pythonEnvironments/info' ;
9
10
10
11
suite ( 'Environment Info cache' , ( ) => {
11
12
let createGlobalPersistentStoreStub : sinon . SinonStub ;
13
+ let areSameEnvironmentStub : sinon . SinonStub ;
12
14
let updatedValues : PythonEnvInfo [ ] | undefined ;
13
15
14
16
const allEnvsComplete : CompleteEnvInfoFunction = ( ) => true ;
@@ -25,7 +27,12 @@ suite('Environment Info cache', () => {
25
27
] as PythonEnvInfo [ ] ;
26
28
27
29
setup ( ( ) => {
28
- createGlobalPersistentStoreStub = sinon . stub ( externalDeps , 'createGlobalPersistentStore' ) ;
30
+ areSameEnvironmentStub = sinon . stub ( envInfo , 'areSameEnvironment' ) ;
31
+ areSameEnvironmentStub . callsFake (
32
+ ( env1 : PythonEnvInfo , env2 :PythonEnvInfo ) => env1 . name === env2 . name ,
33
+ ) ;
34
+
35
+ createGlobalPersistentStoreStub = sinon . stub ( externalDependencies , 'createGlobalPersistentStore' ) ;
29
36
createGlobalPersistentStoreStub . returns ( {
30
37
value : envInfoArray ,
31
38
updateValue : async ( envs : PythonEnvInfo [ ] ) => {
@@ -37,6 +44,7 @@ suite('Environment Info cache', () => {
37
44
38
45
teardown ( ( ) => {
39
46
createGlobalPersistentStoreStub . restore ( ) ;
47
+ areSameEnvironmentStub . restore ( ) ;
40
48
updatedValues = undefined ;
41
49
} ) ;
42
50
@@ -78,9 +86,11 @@ suite('Environment Info cache', () => {
78
86
79
87
test ( '`getEnv` should return an environment that matches all non-undefined properties of its argument' , ( ) => {
80
88
const envsCache = new PythonEnvInfoCache ( allEnvsComplete ) ;
89
+ const env :PythonEnvInfo = { name : 'my-venv-env' } as unknown as PythonEnvInfo ;
90
+
81
91
envsCache . initialize ( ) ;
82
92
83
- const result = envsCache . getEnv ( { name : 'my-venv- env' } ) ;
93
+ const result = envsCache . getEnv ( env ) ;
84
94
85
95
assert . deepStrictEqual ( result , {
86
96
id : 'someid2' , kind : PythonEnvKind . Venv , name : 'my-venv-env' , defaultDisplayName : 'env-two' ,
@@ -89,9 +99,11 @@ suite('Environment Info cache', () => {
89
99
90
100
test ( '`getEnv` should return undefined if no environment matches the properties of its argument' , ( ) => {
91
101
const envsCache = new PythonEnvInfoCache ( allEnvsComplete ) ;
102
+ const env :PythonEnvInfo = { name : 'my-nonexistent-env' } as unknown as PythonEnvInfo ;
103
+
92
104
envsCache . initialize ( ) ;
93
105
94
- const result = envsCache . getEnv ( { name : 'my-nonexistent- env' } ) ;
106
+ const result = envsCache . getEnv ( env ) ;
95
107
96
108
assert . strictEqual ( result , undefined ) ;
97
109
} ) ;
0 commit comments