Skip to content

Commit

Permalink
Ensure we don't show version selection when user selects useExisting (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig authored Sep 27, 2023
1 parent 2d3ce98 commit 6d74f8d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,30 @@ async function createEnvironment(options?: CreateEnvironmentOptions): Promise<Cr
let version: string | undefined;
const versionStep = new MultiStepNode(
workspaceStep,
async () => {
try {
version = await pickPythonVersion();
} catch (ex) {
if (ex === MultiStepAction.Back || ex === MultiStepAction.Cancel) {
return ex;
async (context) => {
if (
existingCondaAction === ExistingCondaAction.Recreate ||
existingCondaAction === ExistingCondaAction.Create
) {
try {
version = await pickPythonVersion();
} catch (ex) {
if (ex === MultiStepAction.Back || ex === MultiStepAction.Cancel) {
return ex;
}
throw ex;
}
if (version === undefined) {
traceError('Python version was not selected for creating conda environment.');
return MultiStepAction.Cancel;
}
traceInfo(`Selected Python version ${version} for creating conda environment.`);
} else if (existingCondaAction === ExistingCondaAction.UseExisting) {
if (context === MultiStepAction.Back) {
return MultiStepAction.Back;
}
throw ex;
}

if (version === undefined) {
traceError('Python version was not selected for creating conda environment.');
return MultiStepAction.Cancel;
}
traceInfo(`Selected Python version ${version} for creating conda environment.`);
return MultiStepAction.Continue;
},
undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ suite('Conda Creation provider tests', () => {
let withProgressStub: sinon.SinonStub;
let showErrorMessageWithLogsStub: sinon.SinonStub;
let pickExistingCondaActionStub: sinon.SinonStub;
let getPrefixCondaEnvPathStub: sinon.SinonStub;

setup(() => {
pickWorkspaceFolderStub = sinon.stub(wsSelect, 'pickWorkspaceFolder');
Expand All @@ -50,6 +51,8 @@ suite('Conda Creation provider tests', () => {
pickExistingCondaActionStub = sinon.stub(condaUtils, 'pickExistingCondaAction');
pickExistingCondaActionStub.resolves(condaUtils.ExistingCondaAction.Create);

getPrefixCondaEnvPathStub = sinon.stub(commonUtils, 'getPrefixCondaEnvPath');

progressMock = typemoq.Mock.ofType<CreateEnvironmentProgress>();
condaProvider = condaCreationProvider();
});
Expand Down Expand Up @@ -254,4 +257,24 @@ suite('Conda Creation provider tests', () => {
assert.isTrue(showErrorMessageWithLogsStub.calledOnce);
assert.isTrue(pickExistingCondaActionStub.calledOnce);
});

test('Use existing conda environment', async () => {
getCondaBaseEnvStub.resolves('/usr/bin/conda');
const workspace1 = {
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace1')),
name: 'workspace1',
index: 0,
};
pickWorkspaceFolderStub.resolves(workspace1);
pickExistingCondaActionStub.resolves(condaUtils.ExistingCondaAction.UseExisting);
getPrefixCondaEnvPathStub.returns('existing_environment');

const result = await condaProvider.createEnvironment();
assert.isTrue(showErrorMessageWithLogsStub.notCalled);
assert.isTrue(pickPythonVersionStub.notCalled);
assert.isTrue(execObservableStub.notCalled);
assert.isTrue(withProgressStub.notCalled);

assert.deepStrictEqual(result, { path: 'existing_environment', workspaceFolder: workspace1 });
});
});

0 comments on commit 6d74f8d

Please sign in to comment.