forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to control if environment is selected after creation (#20738)
For: #20270 @DonJayamanne This PR adds a field to the options that should allow you to skip environment selection.
- v2024.22.0
- v2024.20.0
- v2024.18.1
- v2024.18.0
- v2024.16.1
- v2024.16.0
- v2024.14.1
- v2024.14.0
- v2024.12.3
- v2024.12.2
- v2024.12.1
- v2024.12.0
- v2024.10.0
- v2024.8.1
- v2024.8.0
- v2024.6.0
- v2024.4.1
- v2024.4.0
- v2024.2.1
- v2024.2.0
- v2024.0.1
- v2024.0.0
- v2023.22.1
- v2023.22.0
- v2023.20.0
- v2023.18.0
- v2023.16.0
- v2023.14.0
- v2023.13.11862047
- v2023.12.0
- v2023.11.11841013
- v2023.11.11811010
- v2023.11.11802201
- v2023.11.11801006
- v2023.11.11791005
- v2023.11.11781018
- v2023.11.11771009
- v2023.11.11741005
- v2023.11.11731012
- v2023.11.11721014
- v2023.11.11671008
- v2023.11.11661013
- v2023.11.11651007
- v2023.11.11581008
- v2023.10.1
- v2023.10.0
- v2023.9.11571010
- v2023.9.11561008
- v2023.9.11521013
- v2023.9.11491011
- v2023.9.11461009
- release/pythonExtensionApi/1.0.5
- release/pythonExtensionApi/1.0.4
- release/pythonExtensionApi/1.0.3
- release/pythonExtensionApi/1.0.2
- release/pythonExtensionApi/1.0.1
- release/pythonExtensionApi/1.0.0
- 2024.2.0
- 2023.8.0
- 2023.6.1
- 2023.6.0
1 parent
672d07e
commit 467823d
Showing
4 changed files
with
165 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/test/pythonEnvironments/creation/createEnvApi.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
import * as chaiAsPromised from 'chai-as-promised'; | ||
import * as sinon from 'sinon'; | ||
import * as typemoq from 'typemoq'; | ||
import { assert, use as chaiUse } from 'chai'; | ||
import { ConfigurationTarget, Uri } from 'vscode'; | ||
import { IDisposableRegistry, IInterpreterPathService, IPathUtils } from '../../../client/common/types'; | ||
import * as commandApis from '../../../client/common/vscodeApis/commandApis'; | ||
import { IInterpreterQuickPick } from '../../../client/interpreter/configuration/types'; | ||
import { registerCreateEnvironmentFeatures } from '../../../client/pythonEnvironments/creation/createEnvApi'; | ||
import * as windowApis from '../../../client/common/vscodeApis/windowApis'; | ||
import { CreateEnvironmentProvider } from '../../../client/pythonEnvironments/creation/types'; | ||
import { handleCreateEnvironmentCommand } from '../../../client/pythonEnvironments/creation/createEnvironment'; | ||
|
||
chaiUse(chaiAsPromised); | ||
|
||
suite('Create Environment APIs', () => { | ||
let registerCommandStub: sinon.SinonStub; | ||
let showQuickPickStub: sinon.SinonStub; | ||
let showInformationMessageStub: sinon.SinonStub; | ||
const disposables: IDisposableRegistry = []; | ||
let interpreterQuickPick: typemoq.IMock<IInterpreterQuickPick>; | ||
let interpreterPathService: typemoq.IMock<IInterpreterPathService>; | ||
let pathUtils: typemoq.IMock<IPathUtils>; | ||
|
||
setup(() => { | ||
showQuickPickStub = sinon.stub(windowApis, 'showQuickPick'); | ||
showInformationMessageStub = sinon.stub(windowApis, 'showInformationMessage'); | ||
|
||
registerCommandStub = sinon.stub(commandApis, 'registerCommand'); | ||
interpreterQuickPick = typemoq.Mock.ofType<IInterpreterQuickPick>(); | ||
interpreterPathService = typemoq.Mock.ofType<IInterpreterPathService>(); | ||
pathUtils = typemoq.Mock.ofType<IPathUtils>(); | ||
|
||
registerCommandStub.callsFake((_command: string, _callback: (...args: any[]) => any) => ({ | ||
dispose: () => { | ||
// Do nothing | ||
}, | ||
})); | ||
|
||
pathUtils.setup((p) => p.getDisplayName(typemoq.It.isAny())).returns(() => 'test'); | ||
|
||
registerCreateEnvironmentFeatures( | ||
disposables, | ||
interpreterQuickPick.object, | ||
interpreterPathService.object, | ||
pathUtils.object, | ||
); | ||
}); | ||
teardown(() => { | ||
disposables.forEach((d) => d.dispose()); | ||
sinon.restore(); | ||
}); | ||
|
||
[true, false].forEach((selectEnvironment) => { | ||
test(`Set environment selectEnvironment == ${selectEnvironment}`, async () => { | ||
const provider = typemoq.Mock.ofType<CreateEnvironmentProvider>(); | ||
provider.setup((p) => p.name).returns(() => 'test'); | ||
provider.setup((p) => p.id).returns(() => 'test-id'); | ||
provider.setup((p) => p.description).returns(() => 'test-description'); | ||
provider | ||
.setup((p) => p.createEnvironment(typemoq.It.isAny())) | ||
.returns(() => | ||
Promise.resolve({ | ||
path: '/path/to/env', | ||
uri: Uri.file('/path/to/env'), | ||
}), | ||
); | ||
provider.setup((p) => (p as any).then).returns(() => undefined); | ||
|
||
showQuickPickStub.resolves(provider.object); | ||
|
||
interpreterPathService | ||
.setup((p) => | ||
p.update( | ||
typemoq.It.isAny(), | ||
ConfigurationTarget.WorkspaceFolder, | ||
typemoq.It.isValue('/path/to/env'), | ||
), | ||
) | ||
.returns(() => Promise.resolve()) | ||
.verifiable(selectEnvironment ? typemoq.Times.once() : typemoq.Times.never()); | ||
|
||
await handleCreateEnvironmentCommand([provider.object], { selectEnvironment }); | ||
|
||
assert.ok(showQuickPickStub.calledOnce); | ||
assert.ok(selectEnvironment ? showInformationMessageStub.calledOnce : showInformationMessageStub.notCalled); | ||
interpreterPathService.verifyAll(); | ||
}); | ||
}); | ||
}); |