-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathenvironmentPicker.unit.test.ts
More file actions
105 lines (85 loc) · 4.46 KB
/
environmentPicker.unit.test.ts
File metadata and controls
105 lines (85 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import assert from 'node:assert';
import { Uri } from 'vscode';
import { PythonEnvironment } from '../../api';
import { Interpreter } from '../../common/localize';
/**
* Test the logic used in environment pickers to include interpreter paths in descriptions
*/
suite('Environment Picker Description Logic', () => {
const createMockEnvironment = (
displayPath: string,
description?: string,
name: string = 'Python 3.9.0',
): PythonEnvironment => ({
envId: { id: 'test', managerId: 'test-manager' },
name,
displayName: name,
displayPath,
version: '3.9.0',
environmentPath: Uri.file(displayPath),
description,
sysPrefix: '/path/to/prefix',
execInfo: { run: { executable: displayPath } },
});
suite('Description formatting with interpreter path', () => {
test('should use displayPath as description when no original description exists', () => {
const env = createMockEnvironment('/usr/local/bin/python');
// This is the logic from our updated picker
const pathDescription = env.displayPath;
const description =
env.description && env.description.trim() ? `${env.description} (${pathDescription})` : pathDescription;
assert.strictEqual(description, '/usr/local/bin/python');
});
test('should append displayPath to existing description in parentheses', () => {
const env = createMockEnvironment('/home/user/.venv/bin/python', 'Virtual Environment');
// This is the logic from our updated picker
const pathDescription = env.displayPath;
const description =
env.description && env.description.trim() ? `${env.description} (${pathDescription})` : pathDescription;
assert.strictEqual(description, 'Virtual Environment (/home/user/.venv/bin/python)');
});
test('should handle complex paths correctly', () => {
const complexPath = '/usr/local/anaconda3/envs/my-project-env/bin/python';
const env = createMockEnvironment(complexPath, 'Conda Environment');
// This is the logic from our updated picker
const pathDescription = env.displayPath;
const description =
env.description && env.description.trim() ? `${env.description} (${pathDescription})` : pathDescription;
assert.strictEqual(description, `Conda Environment (${complexPath})`);
});
test('should handle empty description correctly', () => {
const env = createMockEnvironment('/opt/python/bin/python', '');
// This is the logic from our updated picker
const pathDescription = env.displayPath;
const description =
env.description && env.description.trim() ? `${env.description} (${pathDescription})` : pathDescription;
// Empty string should be treated like no description, so just use path
assert.strictEqual(description, '/opt/python/bin/python');
});
test('should handle Windows paths correctly', () => {
const windowsPath = 'C:\\Python39\\python.exe';
const env = createMockEnvironment(windowsPath, 'System Python');
// This is the logic from our updated picker
const pathDescription = env.displayPath;
const description =
env.description && env.description.trim() ? `${env.description} (${pathDescription})` : pathDescription;
assert.strictEqual(description, 'System Python (C:\\Python39\\python.exe)');
});
});
suite('Picker options availability', () => {
test('should have Browse option available', () => {
assert.strictEqual(typeof Interpreter.browsePath, 'string');
assert.strictEqual(Interpreter.browsePath, 'Browse...');
});
test('should have Enter Path option available', () => {
assert.strictEqual(typeof Interpreter.enterPath, 'string');
assert.strictEqual(Interpreter.enterPath, 'Enter Path...');
});
test('should have Create Virtual Environment option available', () => {
assert.strictEqual(typeof Interpreter.createVirtualEnvironment, 'string');
assert.strictEqual(Interpreter.createVirtualEnvironment, 'Create Virtual Environment...');
});
});
});