2
2
// Licensed under the MIT License.
3
3
4
4
import * as assert from 'assert' ;
5
+ import { Uri } from 'vscode' ;
5
6
import { Architecture } from '../../../../client/common/utils/platform' ;
6
7
import { parseVersionInfo } from '../../../../client/common/utils/version' ;
7
8
import { PythonEnvInfo , PythonDistroInfo , PythonEnvKind } from '../../../../client/pythonEnvironments/base/info' ;
@@ -11,6 +12,7 @@ import { createLocatedEnv } from '../common';
11
12
suite ( 'Environment helpers' , ( ) => {
12
13
const name = 'my-env' ;
13
14
const location = 'x/y/z/spam/' ;
15
+ const searchLocation = 'x/y/z' ;
14
16
const arch = Architecture . x64 ;
15
17
const version = '3.8.1' ;
16
18
const kind = PythonEnvKind . Venv ;
@@ -28,44 +30,50 @@ suite('Environment helpers', () => {
28
30
distro ?: PythonDistroInfo ;
29
31
display ?: string ;
30
32
location ?: string ;
33
+ searchLocation ?: string ;
31
34
} ) : PythonEnvInfo {
32
35
const env = createLocatedEnv (
33
36
info . location || '' ,
34
37
info . version || '' ,
35
38
info . kind || PythonEnvKind . Unknown ,
36
39
'python' , // exec
37
40
info . distro ,
41
+ info . searchLocation ? Uri . file ( info . searchLocation ) : undefined ,
38
42
) ;
39
43
env . name = info . name || '' ;
40
44
env . arch = info . arch || Architecture . Unknown ;
41
45
env . display = info . display ;
42
46
return env ;
43
47
}
44
- const tests : [ PythonEnvInfo , string , string ] [ ] = [
45
- [ getEnv ( { } ) , 'Python' , 'Python' ] ,
46
- [ getEnv ( { version, arch, name, kind, distro } ) , "Python 3.8.1 ('my-env')" , "Python 3.8.1 ('my-env': venv)" ] ,
47
- // without "suffix" info
48
- [ getEnv ( { version } ) , 'Python 3.8.1' , 'Python 3.8.1' ] ,
49
- [ getEnv ( { arch } ) , 'Python 64-bit' , 'Python 64-bit' ] ,
50
- [ getEnv ( { version, arch } ) , 'Python 3.8.1 64-bit' , 'Python 3.8.1 64-bit' ] ,
51
- // with "suffix" info
52
- [ getEnv ( { name } ) , "Python ('my-env')" , "Python ('my-env')" ] ,
53
- [ getEnv ( { kind } ) , 'Python' , 'Python (venv)' ] ,
54
- [ getEnv ( { name, kind } ) , "Python ('my-env')" , "Python ('my-env': venv)" ] ,
55
- // env.location is ignored.
56
- [ getEnv ( { location } ) , 'Python' , 'Python' ] ,
57
- [ getEnv ( { name, location } ) , "Python ('my-env')" , "Python ('my-env')" ] ,
58
- ] ;
59
- tests . forEach ( ( [ env , expectedDisplay , expectedDetailedDisplay ] ) => {
48
+ function testGenerator ( ) {
49
+ const tests : [ PythonEnvInfo , string , string ] [ ] = [
50
+ [ getEnv ( { } ) , 'Python' , 'Python' ] ,
51
+ [ getEnv ( { version, arch, name, kind, distro } ) , "Python 3.8.1 ('my-env')" , "Python 3.8.1 ('my-env': venv)" ] ,
52
+ // without "suffix" info
53
+ [ getEnv ( { version } ) , 'Python 3.8.1' , 'Python 3.8.1' ] ,
54
+ [ getEnv ( { arch } ) , 'Python 64-bit' , 'Python 64-bit' ] ,
55
+ [ getEnv ( { version, arch } ) , 'Python 3.8.1 64-bit' , 'Python 3.8.1 64-bit' ] ,
56
+ // with "suffix" info
57
+ [ getEnv ( { name } ) , "Python ('my-env')" , "Python ('my-env')" ] ,
58
+ [ getEnv ( { kind } ) , 'Python' , 'Python (venv)' ] ,
59
+ [ getEnv ( { name, kind } ) , "Python ('my-env')" , "Python ('my-env': venv)" ] ,
60
+ // env.location is ignored.
61
+ [ getEnv ( { location } ) , 'Python' , 'Python' ] ,
62
+ [ getEnv ( { name, location } ) , "Python ('my-env')" , "Python ('my-env')" ] ,
63
+ [ getEnv ( { name, location, searchLocation } ) , "Python ('my-env')" , "Python ('my-env')" ] ,
64
+ ] ;
65
+ return tests ;
66
+ }
67
+ testGenerator ( ) . forEach ( ( [ env , expectedDisplay , expectedDetailedDisplay ] ) => {
60
68
test ( `"${ expectedDisplay } "` , ( ) => {
61
69
setEnvDisplayString ( env ) ;
62
70
63
71
assert . equal ( env . display , expectedDisplay ) ;
64
72
assert . equal ( env . detailedDisplayName , expectedDetailedDisplay ) ;
65
73
} ) ;
66
74
} ) ;
67
- tests . forEach ( ( [ env1 , _d1 , display1 ] , index1 ) => {
68
- tests . forEach ( ( [ env2 , _d2 , display2 ] , index2 ) => {
75
+ testGenerator ( ) . forEach ( ( [ env1 , _d1 , display1 ] , index1 ) => {
76
+ testGenerator ( ) . forEach ( ( [ env2 , _d2 , display2 ] , index2 ) => {
69
77
if ( index1 === index2 ) {
70
78
test ( `"${ display1 } " === "${ display2 } "` , ( ) => {
71
79
assert . strictEqual ( areEnvsDeepEqual ( env1 , env2 ) , true ) ;
0 commit comments