|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import { assert } from 'chai'; |
| 5 | +import * as sinon from 'sinon'; |
| 6 | +import { CancellationTokenSource } from 'vscode'; |
| 7 | +import * as windowApis from '../../../../client/common/vscodeApis/windowApis'; |
| 8 | +import { pickPythonVersion } from '../../../../client/pythonEnvironments/creation/provider/condaUtils'; |
| 9 | + |
| 10 | +suite('Venv Utils test', () => { |
| 11 | + let showQuickPickWithBackStub: sinon.SinonStub; |
| 12 | + |
| 13 | + setup(() => { |
| 14 | + showQuickPickWithBackStub = sinon.stub(windowApis, 'showQuickPickWithBack'); |
| 15 | + }); |
| 16 | + |
| 17 | + teardown(() => { |
| 18 | + sinon.restore(); |
| 19 | + }); |
| 20 | + |
| 21 | + test('No version selected or user pressed escape', async () => { |
| 22 | + showQuickPickWithBackStub.resolves(undefined); |
| 23 | + |
| 24 | + const actual = await pickPythonVersion(); |
| 25 | + assert.isUndefined(actual); |
| 26 | + }); |
| 27 | + |
| 28 | + test('User selected a version', async () => { |
| 29 | + showQuickPickWithBackStub.resolves({ label: 'Python', description: '3.10' }); |
| 30 | + |
| 31 | + const actual = await pickPythonVersion(); |
| 32 | + assert.equal(actual, '3.10'); |
| 33 | + }); |
| 34 | + |
| 35 | + test('User selected a version (array)', async () => { |
| 36 | + showQuickPickWithBackStub.resolves([{ label: 'Python', description: '3.10' }]); |
| 37 | + |
| 38 | + const actual = await pickPythonVersion(); |
| 39 | + assert.equal(actual, '3.10'); |
| 40 | + }); |
| 41 | + |
| 42 | + test('With cancellation', async () => { |
| 43 | + const source = new CancellationTokenSource(); |
| 44 | + |
| 45 | + showQuickPickWithBackStub.callsFake(() => { |
| 46 | + source.cancel(); |
| 47 | + }); |
| 48 | + |
| 49 | + const actual = await pickPythonVersion(source.token); |
| 50 | + assert.isUndefined(actual); |
| 51 | + }); |
| 52 | +}); |
0 commit comments