1+ // Copyright (c) Microsoft Corporation. All rights reserved.
2+ // Licensed under the MIT License.
3+
4+ import assert from 'node:assert' ;
5+ import { Uri } from 'vscode' ;
6+ import { PythonEnvironment } from '../../api' ;
7+
8+ /**
9+ * Test the logic used in environment pickers to include interpreter paths in descriptions
10+ */
11+ suite ( 'Environment Picker Description Logic' , ( ) => {
12+ const createMockEnvironment = (
13+ displayPath : string ,
14+ description ?: string ,
15+ name : string = 'Python 3.9.0' ,
16+ ) : PythonEnvironment => ( {
17+ envId : { id : 'test' , managerId : 'test-manager' } ,
18+ name,
19+ displayName : name ,
20+ displayPath,
21+ version : '3.9.0' ,
22+ environmentPath : Uri . file ( displayPath ) ,
23+ description,
24+ sysPrefix : '/path/to/prefix' ,
25+ execInfo : { run : { executable : displayPath } } ,
26+ } ) ;
27+
28+ suite ( 'Description formatting with interpreter path' , ( ) => {
29+ test ( 'should use displayPath as description when no original description exists' , ( ) => {
30+ const env = createMockEnvironment ( '/usr/local/bin/python' ) ;
31+
32+ // This is the logic from our updated picker
33+ const pathDescription = env . displayPath ;
34+ const description = env . description && env . description . trim ( )
35+ ? `${ env . description } (${ pathDescription } )`
36+ : pathDescription ;
37+
38+ assert . strictEqual ( description , '/usr/local/bin/python' ) ;
39+ } ) ;
40+
41+ test ( 'should append displayPath to existing description in parentheses' , ( ) => {
42+ const env = createMockEnvironment ( '/home/user/.venv/bin/python' , 'Virtual Environment' ) ;
43+
44+ // This is the logic from our updated picker
45+ const pathDescription = env . displayPath ;
46+ const description = env . description && env . description . trim ( )
47+ ? `${ env . description } (${ pathDescription } )`
48+ : pathDescription ;
49+
50+ assert . strictEqual ( description , 'Virtual Environment (/home/user/.venv/bin/python)' ) ;
51+ } ) ;
52+
53+ test ( 'should handle complex paths correctly' , ( ) => {
54+ const complexPath = '/usr/local/anaconda3/envs/my-project-env/bin/python' ;
55+ const env = createMockEnvironment ( complexPath , 'Conda Environment' ) ;
56+
57+ // This is the logic from our updated picker
58+ const pathDescription = env . displayPath ;
59+ const description = env . description && env . description . trim ( )
60+ ? `${ env . description } (${ pathDescription } )`
61+ : pathDescription ;
62+
63+ assert . strictEqual ( description , `Conda Environment (${ complexPath } )` ) ;
64+ } ) ;
65+
66+ test ( 'should handle empty description correctly' , ( ) => {
67+ const env = createMockEnvironment ( '/opt/python/bin/python' , '' ) ;
68+
69+ // This is the logic from our updated picker
70+ const pathDescription = env . displayPath ;
71+ const description = env . description && env . description . trim ( )
72+ ? `${ env . description } (${ pathDescription } )`
73+ : pathDescription ;
74+
75+ // Empty string should be treated like no description, so just use path
76+ assert . strictEqual ( description , '/opt/python/bin/python' ) ;
77+ } ) ;
78+
79+ test ( 'should handle Windows paths correctly' , ( ) => {
80+ const windowsPath = 'C:\\Python39\\python.exe' ;
81+ const env = createMockEnvironment ( windowsPath , 'System Python' ) ;
82+
83+ // This is the logic from our updated picker
84+ const pathDescription = env . displayPath ;
85+ const description = env . description && env . description . trim ( )
86+ ? `${ env . description } (${ pathDescription } )`
87+ : pathDescription ;
88+
89+ assert . strictEqual ( description , 'System Python (C:\\Python39\\python.exe)' ) ;
90+ } ) ;
91+ } ) ;
92+ } ) ;
0 commit comments