|
1 | 1 | import assert from 'node:assert'; |
2 | 2 | import * as path from 'path'; |
3 | 3 | import * as sinon from 'sinon'; |
4 | | -import * as platformUtils from '../../../common/utils/platformUtils'; |
5 | 4 | import { getPyenvDir } from '../../../managers/pyenv/pyenvUtils'; |
6 | 5 |
|
7 | 6 | suite('pyenvUtils - getPyenvDir', () => { |
8 | | - let isWindowsStub: sinon.SinonStub; |
| 7 | + let originalPyenvRoot: string | undefined; |
9 | 8 |
|
10 | 9 | setup(() => { |
11 | | - isWindowsStub = sinon.stub(platformUtils, 'isWindows'); |
| 10 | + originalPyenvRoot = process.env.PYENV_ROOT; |
| 11 | + delete process.env.PYENV_ROOT; |
12 | 12 | }); |
13 | 13 |
|
14 | 14 | teardown(() => { |
15 | 15 | sinon.restore(); |
| 16 | + if (originalPyenvRoot !== undefined) { |
| 17 | + process.env.PYENV_ROOT = originalPyenvRoot; |
| 18 | + } else { |
| 19 | + delete process.env.PYENV_ROOT; |
| 20 | + } |
16 | 21 | }); |
17 | 22 |
|
18 | | - test('should go up 2 levels on POSIX (bin/pyenv -> pyenv root)', () => { |
19 | | - isWindowsStub.returns(false); |
| 23 | + test('should use PYENV_ROOT when set', () => { |
| 24 | + const pyenvRoot = path.join(path.sep, 'custom', 'pyenv', 'root'); |
| 25 | + process.env.PYENV_ROOT = pyenvRoot; |
| 26 | + const pyenvBin = path.join(path.sep, 'other', 'bin', 'pyenv'); |
| 27 | + const result = getPyenvDir(pyenvBin); |
| 28 | + assert.strictEqual(result, pyenvRoot); |
| 29 | + }); |
| 30 | + |
| 31 | + test('should go up 2 levels on POSIX when PYENV_ROOT is not set (bin/pyenv -> pyenv root)', () => { |
20 | 32 | // e.g. /home/user/.pyenv/bin/pyenv |
21 | | - const pyenvBin = path.join('home', 'user', '.pyenv', 'bin', 'pyenv'); |
| 33 | + const pyenvBin = path.join(path.sep, 'home', 'user', '.pyenv', 'bin', 'pyenv'); |
22 | 34 | const result = getPyenvDir(pyenvBin); |
23 | | - assert.strictEqual(result, path.join('home', 'user', '.pyenv')); |
| 35 | + assert.strictEqual(result, path.join(path.sep, 'home', 'user', '.pyenv')); |
24 | 36 | }); |
25 | 37 |
|
26 | | - test('should go up 3 levels on Windows (pyenv-win/bin/pyenv.bat -> pyenv root)', () => { |
27 | | - isWindowsStub.returns(true); |
28 | | - // e.g. C:\Users\user\.pyenv\pyenv-win\bin\pyenv.bat |
| 38 | + test('should go up 2 levels on Windows when PYENV_ROOT is not set (pyenv-win/bin/pyenv.bat -> pyenv-win)', () => { |
| 39 | + // e.g. C:\Users\user\.pyenv\pyenv-win\bin\pyenv.bat -> C:\Users\user\.pyenv\pyenv-win |
29 | 40 | const pyenvBin = path.join('C:', 'Users', 'user', '.pyenv', 'pyenv-win', 'bin', 'pyenv.bat'); |
30 | 41 | const result = getPyenvDir(pyenvBin); |
31 | | - assert.strictEqual(result, path.join('C:', 'Users', 'user', '.pyenv')); |
| 42 | + assert.strictEqual(result, path.join('C:', 'Users', 'user', '.pyenv', 'pyenv-win')); |
32 | 43 | }); |
33 | 44 | }); |
0 commit comments