Skip to content

Commit

Permalink
Merge branch 'main' into ignore-null-key-values
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorjboyd authored Sep 27, 2023
2 parents 5d6416f + 6d74f8d commit 9f047d3
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 9f047d3

Please sign in to comment.