Skip to content

Commit 303d763

Browse files
committed
Add workspace selection tests.
1 parent 04c054e commit 303d763

File tree

4 files changed

+167
-2
lines changed

4 files changed

+167
-2
lines changed

src/client/pythonEnvironments/creation/provider/workspaceSelection.ts renamed to src/client/pythonEnvironments/creation/common/workspaceSelection.ts

File renamed without changes.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { showQuickPick } from '../../../common/vscodeApis/windowApis';
99
import { traceError, traceLog } from '../../../logging';
1010
import { Conda } from '../../common/environmentManagers/conda';
1111
import { CreateEnvironmentOptions, CreateEnvironmentProgress, CreateEnvironmentProvider } from '../types';
12-
import { pickWorkspaceFolder } from './workspaceSelection';
12+
import { pickWorkspaceFolder } from '../common/workspaceSelection';
1313
import { execObservable } from '../../../common/process/rawProcessApis';
1414
import { createDeferred } from '../../../common/utils/async';
1515
import { getEnvironmentVariable, getOSType, OSType } from '../../../common/utils/platform';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { traceError, traceLog } from '../../../logging';
1212
import { PythonEnvKind } from '../../base/info';
1313
import { IDiscoveryAPI } from '../../base/locator';
1414
import { CreateEnvironmentOptions, CreateEnvironmentProgress, CreateEnvironmentProvider } from '../types';
15-
import { pickWorkspaceFolder } from './workspaceSelection';
15+
import { pickWorkspaceFolder } from '../common/workspaceSelection';
1616

1717
const VENV_CREATED_MARKER = 'CREATED_VENV:';
1818
const INSTALLING_REQUIREMENTS = 'VENV_INSTALLING_REQUIREMENTS:';
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
import * as path from 'path';
5+
import { assert } from 'chai';
6+
import * as sinon from 'sinon';
7+
// import * as typemoq from 'typemoq';
8+
import { Uri, WorkspaceFolder } from 'vscode';
9+
import * as workspaceApis from '../../../../client/common/vscodeApis/workspaceApis';
10+
import { pickWorkspaceFolder } from '../../../../client/pythonEnvironments/creation/common/workspaceSelection';
11+
import * as windowApis from '../../../../client/common/vscodeApis/windowApis';
12+
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../constants';
13+
14+
suite('Create environment workspace selection tests', () => {
15+
let showQuickPickStub: sinon.SinonStub;
16+
let getWorkspaceFoldersStub: sinon.SinonStub;
17+
18+
setup(() => {
19+
showQuickPickStub = sinon.stub(windowApis, 'showQuickPick');
20+
getWorkspaceFoldersStub = sinon.stub(workspaceApis, 'getWorkspaceFolders');
21+
});
22+
23+
teardown(() => {
24+
sinon.restore();
25+
});
26+
27+
test('No workspaces (undefined)', async () => {
28+
getWorkspaceFoldersStub.returns(undefined);
29+
assert.isUndefined(await pickWorkspaceFolder());
30+
});
31+
32+
test('No workspaces (empty array)', async () => {
33+
getWorkspaceFoldersStub.returns([]);
34+
assert.isUndefined(await pickWorkspaceFolder());
35+
});
36+
37+
test('User did not select workspace.', async () => {
38+
const workspaces: WorkspaceFolder[] = [
39+
{
40+
uri: Uri.file('some_folder'),
41+
name: 'some_folder',
42+
index: 0,
43+
},
44+
{
45+
uri: Uri.file('some_folder2'),
46+
name: 'some_folder2',
47+
index: 1,
48+
},
49+
];
50+
51+
getWorkspaceFoldersStub.returns(workspaces);
52+
showQuickPickStub.returns(undefined);
53+
assert.isUndefined(await pickWorkspaceFolder());
54+
});
55+
56+
test('single workspace scenario.', async () => {
57+
const workspaces: WorkspaceFolder[] = [
58+
{
59+
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace1')),
60+
name: 'workspace1',
61+
index: 0,
62+
},
63+
];
64+
65+
getWorkspaceFoldersStub.returns(workspaces);
66+
showQuickPickStub.returns({
67+
label: workspaces[0].name,
68+
detail: workspaces[0].uri.fsPath,
69+
description: undefined,
70+
});
71+
72+
const workspace = await pickWorkspaceFolder();
73+
assert.deepEqual(workspace, workspaces[0]);
74+
assert(showQuickPickStub.notCalled);
75+
});
76+
77+
test('Multi-workspace scenario with single workspace selected.', async () => {
78+
const workspaces: WorkspaceFolder[] = [
79+
{
80+
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace1')),
81+
name: 'workspace1',
82+
index: 0,
83+
},
84+
{
85+
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace2')),
86+
name: 'workspace2',
87+
index: 1,
88+
},
89+
{
90+
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace3')),
91+
name: 'workspace3',
92+
index: 2,
93+
},
94+
{
95+
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace4')),
96+
name: 'workspace4',
97+
index: 3,
98+
},
99+
{
100+
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace5')),
101+
name: 'workspace5',
102+
index: 4,
103+
},
104+
];
105+
106+
getWorkspaceFoldersStub.returns(workspaces);
107+
showQuickPickStub.returns({
108+
label: workspaces[1].name,
109+
detail: workspaces[1].uri.fsPath,
110+
description: undefined,
111+
});
112+
113+
const workspace = await pickWorkspaceFolder();
114+
assert.deepEqual(workspace, workspaces[1]);
115+
assert(showQuickPickStub.calledOnce);
116+
});
117+
118+
test('Multi-workspace scenario with multiple workspaces selected.', async () => {
119+
const workspaces: WorkspaceFolder[] = [
120+
{
121+
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace1')),
122+
name: 'workspace1',
123+
index: 0,
124+
},
125+
{
126+
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace2')),
127+
name: 'workspace2',
128+
index: 1,
129+
},
130+
{
131+
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace3')),
132+
name: 'workspace3',
133+
index: 2,
134+
},
135+
{
136+
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace4')),
137+
name: 'workspace4',
138+
index: 3,
139+
},
140+
{
141+
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace5')),
142+
name: 'workspace5',
143+
index: 4,
144+
},
145+
];
146+
147+
getWorkspaceFoldersStub.returns(workspaces);
148+
showQuickPickStub.returns([
149+
{
150+
label: workspaces[1].name,
151+
detail: workspaces[1].uri.fsPath,
152+
description: undefined,
153+
},
154+
{
155+
label: workspaces[3].name,
156+
detail: workspaces[3].uri.fsPath,
157+
description: undefined,
158+
},
159+
]);
160+
161+
const workspace = await pickWorkspaceFolder({ allowMultiSelect: true });
162+
assert.deepEqual(workspace, [workspaces[1], workspaces[3]]);
163+
assert(showQuickPickStub.calledOnce);
164+
});
165+
});

0 commit comments

Comments
 (0)