|
| 1 | +/* eslint-disable @typescript-eslint/no-explicit-any */ |
| 2 | +import assert from 'assert'; |
| 3 | +import * as path from 'path'; |
| 4 | +import * as sinon from 'sinon'; |
| 5 | +import { EnvironmentManager } from '../../../api'; |
| 6 | +import { CondaEnvManager } from '../../../managers/conda/condaEnvManager'; |
| 7 | +import { getNamedCondaPythonInfo, getPrefixesCondaPythonInfo } from '../../../managers/conda/condaUtils'; |
| 8 | +import { NativePythonFinder } from '../../../managers/common/nativePythonFinder'; |
| 9 | +import * as platformUtils from '../../../common/utils/platformUtils'; |
| 10 | + |
| 11 | +suite('Conda Python executable path construction', () => { |
| 12 | + let isWindowsStub: sinon.SinonStub; |
| 13 | + let mockManager: EnvironmentManager; |
| 14 | + |
| 15 | + setup(() => { |
| 16 | + mockManager = new CondaEnvManager( |
| 17 | + {} as NativePythonFinder, |
| 18 | + {} as any, |
| 19 | + { info: sinon.stub(), error: sinon.stub(), warn: sinon.stub() } as any, |
| 20 | + ); |
| 21 | + }); |
| 22 | + |
| 23 | + teardown(() => { |
| 24 | + sinon.restore(); |
| 25 | + }); |
| 26 | + |
| 27 | + test('getNamedCondaPythonInfo: executable path uses bin/python on non-Windows', async () => { |
| 28 | + isWindowsStub = sinon.stub(platformUtils, 'isWindows').returns(false); |
| 29 | + const prefix = '/home/user/miniconda3/envs/myenv'; |
| 30 | + const executable = path.posix.join(prefix, 'bin', 'python'); |
| 31 | + const info = await getNamedCondaPythonInfo('myenv', prefix, executable, '3.12.0', '/usr/bin/conda', mockManager); |
| 32 | + |
| 33 | + assert.ok( |
| 34 | + info.execInfo.run.executable.includes(path.join('bin', 'python')) || |
| 35 | + info.execInfo.run.executable.endsWith('python'), |
| 36 | + `executable should contain bin/python, got: ${info.execInfo.run.executable}`, |
| 37 | + ); |
| 38 | + isWindowsStub.restore(); |
| 39 | + }); |
| 40 | + |
| 41 | + test('getPrefixesCondaPythonInfo: executable path uses bin/python on non-Windows', async () => { |
| 42 | + isWindowsStub = sinon.stub(platformUtils, 'isWindows').returns(false); |
| 43 | + const prefix = '/home/user/projects/.conda'; |
| 44 | + const executable = path.posix.join(prefix, 'bin', 'python'); |
| 45 | + const info = await getPrefixesCondaPythonInfo(prefix, executable, '3.12.0', '/usr/bin/conda', mockManager); |
| 46 | + |
| 47 | + assert.ok( |
| 48 | + info.execInfo.run.executable.includes(path.join('bin', 'python')) || |
| 49 | + info.execInfo.run.executable.endsWith('python'), |
| 50 | + `executable should contain bin/python, got: ${info.execInfo.run.executable}`, |
| 51 | + ); |
| 52 | + isWindowsStub.restore(); |
| 53 | + }); |
| 54 | + |
| 55 | + test('getNamedCondaPythonInfo: executable path uses python.exe on Windows', async () => { |
| 56 | + isWindowsStub = sinon.stub(platformUtils, 'isWindows').returns(true); |
| 57 | + const prefix = 'C:\\Users\\user\\miniconda3\\envs\\myenv'; |
| 58 | + const executable = path.win32.join(prefix, 'python.exe'); |
| 59 | + const info = await getNamedCondaPythonInfo('myenv', prefix, executable, '3.12.0', 'C:\\conda\\conda.exe', mockManager); |
| 60 | + |
| 61 | + assert.ok( |
| 62 | + info.execInfo.run.executable.endsWith('python.exe'), |
| 63 | + `executable should end with python.exe, got: ${info.execInfo.run.executable}`, |
| 64 | + ); |
| 65 | + isWindowsStub.restore(); |
| 66 | + }); |
| 67 | +}); |
0 commit comments