forked from microsoft/vscode-python-environments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcondaUtils.pythonExePath.unit.test.ts
More file actions
67 lines (58 loc) · 3.01 KB
/
condaUtils.pythonExePath.unit.test.ts
File metadata and controls
67 lines (58 loc) · 3.01 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
/* eslint-disable @typescript-eslint/no-explicit-any */
import assert from 'assert';
import * as path from 'path';
import * as sinon from 'sinon';
import { EnvironmentManager } from '../../../api';
import { CondaEnvManager } from '../../../managers/conda/condaEnvManager';
import { getNamedCondaPythonInfo, getPrefixesCondaPythonInfo } from '../../../managers/conda/condaUtils';
import { NativePythonFinder } from '../../../managers/common/nativePythonFinder';
import * as platformUtils from '../../../common/utils/platformUtils';
suite('Conda Python executable path construction', () => {
let isWindowsStub: sinon.SinonStub;
let mockManager: EnvironmentManager;
setup(() => {
mockManager = new CondaEnvManager(
{} as NativePythonFinder,
{} as any,
{ info: sinon.stub(), error: sinon.stub(), warn: sinon.stub() } as any,
);
});
teardown(() => {
sinon.restore();
});
test('getNamedCondaPythonInfo: executable path uses bin/python on non-Windows', async () => {
isWindowsStub = sinon.stub(platformUtils, 'isWindows').returns(false);
const prefix = '/home/user/miniconda3/envs/myenv';
const executable = path.posix.join(prefix, 'bin', 'python');
const info = await getNamedCondaPythonInfo('myenv', prefix, executable, '3.12.0', '/usr/bin/conda', mockManager);
assert.ok(
info.execInfo.run.executable.includes(path.join('bin', 'python')) ||
info.execInfo.run.executable.endsWith('python'),
`executable should contain bin/python, got: ${info.execInfo.run.executable}`,
);
isWindowsStub.restore();
});
test('getPrefixesCondaPythonInfo: executable path uses bin/python on non-Windows', async () => {
isWindowsStub = sinon.stub(platformUtils, 'isWindows').returns(false);
const prefix = '/home/user/projects/.conda';
const executable = path.posix.join(prefix, 'bin', 'python');
const info = await getPrefixesCondaPythonInfo(prefix, executable, '3.12.0', '/usr/bin/conda', mockManager);
assert.ok(
info.execInfo.run.executable.includes(path.join('bin', 'python')) ||
info.execInfo.run.executable.endsWith('python'),
`executable should contain bin/python, got: ${info.execInfo.run.executable}`,
);
isWindowsStub.restore();
});
test('getNamedCondaPythonInfo: executable path uses python.exe on Windows', async () => {
isWindowsStub = sinon.stub(platformUtils, 'isWindows').returns(true);
const prefix = 'C:\\Users\\user\\miniconda3\\envs\\myenv';
const executable = path.win32.join(prefix, 'python.exe');
const info = await getNamedCondaPythonInfo('myenv', prefix, executable, '3.12.0', 'C:\\conda\\conda.exe', mockManager);
assert.ok(
info.execInfo.run.executable.endsWith('python.exe'),
`executable should end with python.exe, got: ${info.execInfo.run.executable}`,
);
isWindowsStub.restore();
});
});