@@ -18,6 +18,10 @@ import { ServiceContainer } from '../../client/ioc/container';
18
18
import { ServiceManager } from '../../client/ioc/serviceManager' ;
19
19
import { MockAutoSelectionService } from '../mocks/autoSelector' ;
20
20
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
21
25
suite ( 'Virtual environments' , ( ) => {
22
26
let serviceManager : ServiceManager ;
23
27
let serviceContainer : ServiceContainer ;
@@ -52,11 +56,16 @@ suite('Virtual environments', () => {
52
56
const pathProvider = new GlobalVirtualEnvironmentsSearchPathProvider ( serviceContainer ) ;
53
57
54
58
const homedir = os . homedir ( ) ;
55
- const folders = [ 'Envs' , '.virtualenvs ' ] ;
59
+ const folders = [ 'Envs' , 'testpath ' ] ;
56
60
settings . setup ( x => x . venvFolders ) . returns ( ( ) => folders ) ;
57
61
virtualEnvMgr . setup ( v => v . getPyEnvRoot ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => Promise . resolve ( undefined ) ) ;
58
62
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 ) ) ;
60
69
61
70
virtualEnvMgr . verifyAll ( ) ;
62
71
expect ( paths ) . to . deep . equal ( expected , 'Global search folder list is incorrect.' ) ;
@@ -70,6 +79,60 @@ suite('Virtual environments', () => {
70
79
expect ( paths ) . to . deep . equal ( expected , 'pyenv path not resolved correctly.' ) ;
71
80
} ) ;
72
81
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
+
73
136
test ( 'Workspace search paths' , async ( ) => {
74
137
settings . setup ( x => x . venvPath ) . returns ( ( ) => path . join ( '~' , 'foo' ) ) ;
75
138
0 commit comments