|
1 | 1 | import assert from 'node:assert'; |
2 | 2 | import * as sinon from 'sinon'; |
3 | | -import { isPoetryVirtualenvsInProject, nativeToPythonEnv } from '../../../managers/poetry/poetryUtils'; |
4 | | -import * as utils from '../../../managers/common/utils'; |
5 | 3 | import { EnvironmentManager, PythonEnvironment, PythonEnvironmentApi, PythonEnvironmentInfo } from '../../../api'; |
| 4 | +import * as childProcessApis from '../../../common/childProcess.apis'; |
6 | 5 | import { NativeEnvInfo } from '../../../managers/common/nativePythonFinder'; |
| 6 | +import * as utils from '../../../managers/common/utils'; |
| 7 | +import { |
| 8 | + getPoetryVersion, |
| 9 | + isPoetryVirtualenvsInProject, |
| 10 | + nativeToPythonEnv, |
| 11 | +} from '../../../managers/poetry/poetryUtils'; |
7 | 12 |
|
8 | 13 | suite('isPoetryVirtualenvsInProject', () => { |
9 | 14 | test('should return false when env var is not set', () => { |
@@ -157,3 +162,49 @@ suite('nativeToPythonEnv - POETRY_VIRTUALENVS_IN_PROJECT integration', () => { |
157 | 162 | assert.strictEqual(capturedInfo!.group, undefined, 'Non-global path should not be global'); |
158 | 163 | }); |
159 | 164 | }); |
| 165 | + |
| 166 | +suite('getPoetryVersion - childProcess.apis mocking pattern', () => { |
| 167 | + let execProcessStub: sinon.SinonStub; |
| 168 | + |
| 169 | + setup(() => { |
| 170 | + execProcessStub = sinon.stub(childProcessApis, 'execProcess'); |
| 171 | + }); |
| 172 | + |
| 173 | + teardown(() => { |
| 174 | + sinon.restore(); |
| 175 | + }); |
| 176 | + |
| 177 | + test('should parse Poetry 1.x version format', async () => { |
| 178 | + execProcessStub.resolves({ stdout: 'Poetry version 1.5.1\n', stderr: '' }); |
| 179 | + |
| 180 | + const version = await getPoetryVersion('/usr/bin/poetry'); |
| 181 | + |
| 182 | + assert.strictEqual(version, '1.5.1'); |
| 183 | + assert.ok(execProcessStub.calledOnce); |
| 184 | + assert.ok(execProcessStub.calledWith('"/usr/bin/poetry" --version')); |
| 185 | + }); |
| 186 | + |
| 187 | + test('should parse Poetry 2.x version format', async () => { |
| 188 | + execProcessStub.resolves({ stdout: 'Poetry (version 2.1.3)\n', stderr: '' }); |
| 189 | + |
| 190 | + const version = await getPoetryVersion('/usr/bin/poetry'); |
| 191 | + |
| 192 | + assert.strictEqual(version, '2.1.3'); |
| 193 | + }); |
| 194 | + |
| 195 | + test('should return undefined when command fails', async () => { |
| 196 | + execProcessStub.rejects(new Error('Command not found')); |
| 197 | + |
| 198 | + const version = await getPoetryVersion('/nonexistent/poetry'); |
| 199 | + |
| 200 | + assert.strictEqual(version, undefined); |
| 201 | + }); |
| 202 | + |
| 203 | + test('should return undefined when output does not match expected format', async () => { |
| 204 | + execProcessStub.resolves({ stdout: 'unexpected output', stderr: '' }); |
| 205 | + |
| 206 | + const version = await getPoetryVersion('/usr/bin/poetry'); |
| 207 | + |
| 208 | + assert.strictEqual(version, undefined); |
| 209 | + }); |
| 210 | +}); |
0 commit comments