-
Notifications
You must be signed in to change notification settings - Fork 42
prioritize workspace selected env over process.env.CONDA_PREFIX #1398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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/managers/conda/condaUtils.getCondaForWorkspace.unit.test.ts
This file contains hidden or 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 @@ | ||
| import assert from 'assert'; | ||
| import * as sinon from 'sinon'; | ||
| import * as persistentState from '../../../common/persistentState'; | ||
| import { CONDA_WORKSPACE_KEY, getCondaForWorkspace } from '../../../managers/conda/condaUtils'; | ||
|
|
||
| suite('Conda Utils - getCondaForWorkspace prioritization', () => { | ||
| let mockState: { get: sinon.SinonStub; set: sinon.SinonStub }; | ||
| let getWorkspacePersistentStateStub: sinon.SinonStub; | ||
| let originalCondaPrefix: string | undefined; | ||
|
|
||
| setup(() => { | ||
| originalCondaPrefix = process.env.CONDA_PREFIX; | ||
|
|
||
| mockState = { | ||
| get: sinon.stub(), | ||
| set: sinon.stub().resolves(), | ||
| }; | ||
| getWorkspacePersistentStateStub = sinon.stub(persistentState, 'getWorkspacePersistentState'); | ||
| getWorkspacePersistentStateStub.resolves(mockState); | ||
| }); | ||
|
|
||
| teardown(() => { | ||
| if (originalCondaPrefix === undefined) { | ||
| delete process.env.CONDA_PREFIX; | ||
| } else { | ||
| process.env.CONDA_PREFIX = originalCondaPrefix; | ||
| } | ||
| sinon.restore(); | ||
| }); | ||
|
|
||
| test('Persisted selection takes priority over CONDA_PREFIX', async () => { | ||
| const workspacePath = '/home/user/project'; | ||
| const userSelectedEnv = '/home/user/miniconda3/envs/myenv'; | ||
| process.env.CONDA_PREFIX = '/home/user/miniconda3'; | ||
|
|
||
| mockState.get.withArgs(CONDA_WORKSPACE_KEY).resolves({ | ||
| [workspacePath]: userSelectedEnv, | ||
| }); | ||
|
|
||
| const result = await getCondaForWorkspace(workspacePath); | ||
|
|
||
| assert.strictEqual(result, userSelectedEnv); | ||
| }); | ||
|
|
||
| test('CONDA_PREFIX is used as fallback when no persisted selection exists', async () => { | ||
| const workspacePath = '/home/user/project'; | ||
| const condaBase = '/home/user/miniconda3'; | ||
| process.env.CONDA_PREFIX = condaBase; | ||
|
|
||
| mockState.get.withArgs(CONDA_WORKSPACE_KEY).resolves(undefined); | ||
|
|
||
| const result = await getCondaForWorkspace(workspacePath); | ||
|
|
||
| assert.strictEqual(result, condaBase); | ||
| }); | ||
|
|
||
| test('CONDA_PREFIX is used when persisted data exists but not for this workspace', async () => { | ||
| const workspacePath = '/home/user/project'; | ||
| const condaBase = '/home/user/miniconda3'; | ||
| process.env.CONDA_PREFIX = condaBase; | ||
|
|
||
| mockState.get.withArgs(CONDA_WORKSPACE_KEY).resolves({ | ||
| '/home/user/other-project': '/home/user/miniconda3/envs/other', | ||
| }); | ||
|
|
||
| const result = await getCondaForWorkspace(workspacePath); | ||
|
|
||
| assert.strictEqual(result, condaBase); | ||
| }); | ||
|
|
||
| test('Returns undefined when no persisted selection and no CONDA_PREFIX', async () => { | ||
| delete process.env.CONDA_PREFIX; | ||
|
|
||
| mockState.get.withArgs(CONDA_WORKSPACE_KEY).resolves(undefined); | ||
|
|
||
| const result = await getCondaForWorkspace('/home/user/project'); | ||
|
|
||
| assert.strictEqual(result, undefined); | ||
| }); | ||
|
|
||
| test('Returns persisted selection when CONDA_PREFIX is not set', async () => { | ||
| const workspacePath = '/home/user/project'; | ||
| const userSelectedEnv = '/home/user/miniconda3/envs/myenv'; | ||
| delete process.env.CONDA_PREFIX; | ||
|
|
||
| mockState.get.withArgs(CONDA_WORKSPACE_KEY).resolves({ | ||
| [workspacePath]: userSelectedEnv, | ||
| }); | ||
|
|
||
| const result = await getCondaForWorkspace(workspacePath); | ||
|
|
||
| assert.strictEqual(result, userSelectedEnv); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.