@@ -18,6 +18,10 @@ import { ServiceContainer } from '../../client/ioc/container';
1818import { ServiceManager } from '../../client/ioc/serviceManager' ;
1919import { MockAutoSelectionService } from '../mocks/autoSelector' ;
2020
21+ // tslint:disable-next-line:no-require-imports no-var-requires
22+ const untildify : ( value : string ) => string = require ( 'untildify' ) ;
23+
24+ // tslint:disable-next-line: max-func-body-length
2125suite ( 'Virtual environments' , ( ) => {
2226 let serviceManager : ServiceManager ;
2327 let serviceContainer : ServiceContainer ;
@@ -52,11 +56,16 @@ suite('Virtual environments', () => {
5256 const pathProvider = new GlobalVirtualEnvironmentsSearchPathProvider ( serviceContainer ) ;
5357
5458 const homedir = os . homedir ( ) ;
55- const folders = [ 'Envs' , '.virtualenvs ' ] ;
59+ const folders = [ 'Envs' , 'testpath ' ] ;
5660 settings . setup ( x => x . venvFolders ) . returns ( ( ) => folders ) ;
5761 virtualEnvMgr . setup ( v => v . getPyEnvRoot ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => Promise . resolve ( undefined ) ) ;
5862 let paths = await pathProvider . getSearchPaths ( ) ;
59- let expected = folders . map ( item => path . join ( homedir , item ) ) ;
63+ let expected = [
64+ 'envs' ,
65+ '.pyenv' ,
66+ '.direnv' ,
67+ '.virtualenvs' ,
68+ ...folders ] . map ( item => path . join ( homedir , item ) ) ;
6069
6170 virtualEnvMgr . verifyAll ( ) ;
6271 expect ( paths ) . to . deep . equal ( expected , 'Global search folder list is incorrect.' ) ;
@@ -70,6 +79,60 @@ suite('Virtual environments', () => {
7079 expect ( paths ) . to . deep . equal ( expected , 'pyenv path not resolved correctly.' ) ;
7180 } ) ;
7281
82+ test ( 'Global search paths with duplicates' , async ( ) => {
83+ const pathProvider = new GlobalVirtualEnvironmentsSearchPathProvider ( serviceContainer ) ;
84+
85+ const folders = [ '.virtualenvs' , '.direnv' ] ;
86+ settings . setup ( x => x . venvFolders ) . returns ( ( ) => folders ) ;
87+ const paths = await pathProvider . getSearchPaths ( ) ;
88+
89+ expect ( [ ...new Set ( paths ) ] ) . to . deep . equal ( paths , 'Duplicates are not removed from the list of global search paths' ) ;
90+ } ) ;
91+
92+ test ( 'Global search paths with tilde path in the WORKON_HOME environment variable' , async ( ) => {
93+ const pathProvider = new GlobalVirtualEnvironmentsSearchPathProvider ( serviceContainer ) ;
94+
95+ const homedir = os . homedir ( ) ;
96+ const workonFolder = path . join ( '~' , '.workonFolder' ) ;
97+ process . setup ( p => p . env ) . returns ( ( ) => {
98+ return { WORKON_HOME : workonFolder } ;
99+ } ) ;
100+ settings . setup ( x => x . venvFolders ) . returns ( ( ) => [ ] ) ;
101+
102+ const paths = await pathProvider . getSearchPaths ( ) ;
103+ const expected = [
104+ 'envs' ,
105+ '.pyenv' ,
106+ '.direnv' ,
107+ '.virtualenvs'
108+ ] . map ( item => path . join ( homedir , item ) ) ;
109+ expected . push ( untildify ( workonFolder ) ) ;
110+
111+ expect ( paths ) . to . deep . equal ( expected , 'WORKON_HOME environment variable not read.' ) ;
112+ } ) ;
113+
114+ test ( 'Global search paths with absolute path in the WORKON_HOME environment variable' , async ( ) => {
115+ const pathProvider = new GlobalVirtualEnvironmentsSearchPathProvider ( serviceContainer ) ;
116+
117+ const homedir = os . homedir ( ) ;
118+ const workonFolder = path . join ( 'path' , 'to' , '.workonFolder' ) ;
119+ process . setup ( p => p . env ) . returns ( ( ) => {
120+ return { WORKON_HOME : workonFolder } ;
121+ } ) ;
122+ settings . setup ( x => x . venvFolders ) . returns ( ( ) => [ ] ) ;
123+
124+ const paths = await pathProvider . getSearchPaths ( ) ;
125+ const expected = [
126+ 'envs' ,
127+ '.pyenv' ,
128+ '.direnv' ,
129+ '.virtualenvs'
130+ ] . map ( item => path . join ( homedir , item ) ) ;
131+ expected . push ( workonFolder ) ;
132+
133+ expect ( paths ) . to . deep . equal ( expected , 'WORKON_HOME environment variable not read.' ) ;
134+ } ) ;
135+
73136 test ( 'Workspace search paths' , async ( ) => {
74137 settings . setup ( x => x . venvPath ) . returns ( ( ) => path . join ( '~' , 'foo' ) ) ;
75138
0 commit comments