Skip to content

Commit ccf0d45

Browse files
committed
Ensure conda version picker handles array response.
1 parent c5e6378 commit ccf0d45

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/client/pythonEnvironments/creation/provider/condaUtils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
import { isArray } from 'lodash';
45
import { CancellationToken, QuickPickItem, Uri } from 'vscode';
56
import { Common } from '../../../browser/localize';
67
import { Octicons } from '../../../common/constants';
@@ -51,6 +52,9 @@ export async function pickPythonVersion(token?: CancellationToken): Promise<stri
5152
token,
5253
);
5354

55+
if (isArray(selection) && selection.length > 0) {
56+
return (selection[0] as QuickPickItem).description;
57+
}
5458
if (selection) {
5559
return (selection as QuickPickItem).description;
5660
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)