@@ -12,13 +12,15 @@ import {
1212} from '../../client/interpreter/configuration/environmentTypeComparer' ;
1313import { IInterpreterHelper } from '../../client/interpreter/contracts' ;
1414import { PythonEnvType } from '../../client/pythonEnvironments/base/info' ;
15+ import * as pyenv from '../../client/pythonEnvironments/common/environmentManagers/pyenv' ;
1516import { EnvironmentType , PythonEnvironment } from '../../client/pythonEnvironments/info' ;
1617
1718suite ( 'Environment sorting' , ( ) => {
1819 const workspacePath = path . join ( 'path' , 'to' , 'workspace' ) ;
1920 let interpreterHelper : IInterpreterHelper ;
2021 let getActiveWorkspaceUriStub : sinon . SinonStub ;
2122 let getInterpreterTypeDisplayNameStub : sinon . SinonStub ;
23+ const preferredPyenv = path . join ( 'path' , 'to' , 'preferred' , 'pyenv' ) ;
2224
2325 setup ( ( ) => {
2426 getActiveWorkspaceUriStub = sinon . stub ( ) . returns ( { folderUri : { fsPath : workspacePath } } ) ;
@@ -28,6 +30,8 @@ suite('Environment sorting', () => {
2830 getActiveWorkspaceUri : getActiveWorkspaceUriStub ,
2931 getInterpreterTypeDisplayName : getInterpreterTypeDisplayNameStub ,
3032 } as unknown ) as IInterpreterHelper ;
33+ const getActivePyenvForDirectory = sinon . stub ( pyenv , 'getActivePyenvForDirectory' ) ;
34+ getActivePyenvForDirectory . resolves ( preferredPyenv ) ;
3135 } ) ;
3236
3337 teardown ( ( ) => {
@@ -147,6 +151,33 @@ suite('Environment sorting', () => {
147151 } as PythonEnvironment ,
148152 expected : 1 ,
149153 } ,
154+ {
155+ title : 'Preferred Pyenv interpreter should come before any global interpreter' ,
156+ envA : {
157+ envType : EnvironmentType . Pyenv ,
158+ version : { major : 3 , minor : 12 , patch : 2 } ,
159+ path : preferredPyenv ,
160+ } as PythonEnvironment ,
161+ envB : {
162+ envType : EnvironmentType . Pyenv ,
163+ version : { major : 3 , minor : 10 , patch : 2 } ,
164+ path : path . join ( 'path' , 'to' , 'normal' , 'pyenv' ) ,
165+ } as PythonEnvironment ,
166+ expected : - 1 ,
167+ } ,
168+ {
169+ title : 'Pyenv interpreters should come first when there are global interpreters' ,
170+ envA : {
171+ envType : EnvironmentType . Global ,
172+ version : { major : 3 , minor : 10 , patch : 2 } ,
173+ } as PythonEnvironment ,
174+ envB : {
175+ envType : EnvironmentType . Pyenv ,
176+ version : { major : 3 , minor : 7 , patch : 2 } ,
177+ path : path . join ( 'path' , 'to' , 'normal' , 'pyenv' ) ,
178+ } as PythonEnvironment ,
179+ expected : 1 ,
180+ } ,
150181 {
151182 title : 'Global environment should not come first when there are global envs' ,
152183 envA : {
@@ -283,8 +314,9 @@ suite('Environment sorting', () => {
283314 ] ;
284315
285316 testcases . forEach ( ( { title, envA, envB, expected } ) => {
286- test ( title , ( ) => {
317+ test ( title , async ( ) => {
287318 const envTypeComparer = new EnvironmentTypeComparer ( interpreterHelper ) ;
319+ await envTypeComparer . initialize ( undefined ) ;
288320 const result = envTypeComparer . compare ( envA , envB ) ;
289321
290322 assert . strictEqual ( result , expected ) ;
0 commit comments