forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Tests for PYTHONSTARTUP setting #24145
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d4d4262
start creating test for pythonstartup setting
anthonykim1 b72fe78
failing to run locally, 0 pass or fail
anthonykim1 32edc64
c.environmentVariableCollection.replace is not a function?
anthonykim1 5ab075e
context.environmentVariableCollection.delete AND replace is not a fun…
anthonykim1 8808176
two test working, one test still mystery
anthonykim1 74e51b7
get rid of attempt to convert test into ts-mockito
anthonykim1 ad8129e
more test to prepare once mystery is resolved
anthonykim1 fbecbc3
leave questions so I don't forget things
anthonykim1 4d11998
add more test where I can, leave the blocker with question
anthonykim1 b164ac3
fianlly figured it out
anthonykim1 56526ad
I win
anthonykim1 3765370
remove junk
anthonykim1 aeb0b5a
pay attention to newlines
anthonykim1 32a11b5
last one
anthonykim1 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 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
125 changes: 125 additions & 0 deletions
125
src/test/terminals/shellIntegration/pythonStartup.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,125 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import * as sinon from 'sinon'; | ||
import * as TypeMoq from 'typemoq'; | ||
import { GlobalEnvironmentVariableCollection, Uri, WorkspaceConfiguration } from 'vscode'; | ||
import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis'; | ||
import { registerPythonStartup } from '../../../client/terminals/pythonStartup'; | ||
import { IExtensionContext } from '../../../client/common/types'; | ||
|
||
suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { | ||
let getConfigurationStub: sinon.SinonStub; | ||
let pythonConfig: TypeMoq.IMock<WorkspaceConfiguration>; | ||
let editorConfig: TypeMoq.IMock<WorkspaceConfiguration>; | ||
let context: TypeMoq.IMock<IExtensionContext>; | ||
let createDirectoryStub: sinon.SinonStub; | ||
let copyStub: sinon.SinonStub; | ||
let globalEnvironmentVariableCollection: TypeMoq.IMock<GlobalEnvironmentVariableCollection>; | ||
|
||
setup(() => { | ||
context = TypeMoq.Mock.ofType<IExtensionContext>(); | ||
globalEnvironmentVariableCollection = TypeMoq.Mock.ofType<GlobalEnvironmentVariableCollection>(); | ||
|
||
// Question: Why do we have to set up environmentVariableCollection and globalEnvironmentVariableCollection in this flip-flop way? | ||
// Reference: /vscode-python/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts | ||
context.setup((c) => c.environmentVariableCollection).returns(() => globalEnvironmentVariableCollection.object); | ||
context.setup((c) => c.storageUri).returns(() => Uri.parse('a')); | ||
|
||
globalEnvironmentVariableCollection | ||
.setup((c) => c.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())) | ||
.returns(() => Promise.resolve()); | ||
|
||
globalEnvironmentVariableCollection.setup((c) => c.delete(TypeMoq.It.isAny())).returns(() => Promise.resolve()); | ||
|
||
getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); | ||
createDirectoryStub = sinon.stub(workspaceApis, 'createDirectory'); | ||
copyStub = sinon.stub(workspaceApis, 'copy'); | ||
|
||
pythonConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>(); | ||
editorConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>(); | ||
getConfigurationStub.callsFake((section: string) => { | ||
if (section === 'python') { | ||
return pythonConfig.object; | ||
} | ||
return editorConfig.object; | ||
}); | ||
|
||
createDirectoryStub.callsFake((_) => Promise.resolve()); | ||
copyStub.callsFake((_, __, ___) => Promise.resolve()); | ||
}); | ||
|
||
teardown(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
test('Verify createDirectory is called when shell integration is enabled', async () => { | ||
pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); | ||
|
||
await registerPythonStartup(context.object); | ||
|
||
sinon.assert.calledOnce(createDirectoryStub); | ||
}); | ||
|
||
test('Verify createDirectory is not called when shell integration is disabled', async () => { | ||
pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => false); | ||
|
||
await registerPythonStartup(context.object); | ||
|
||
sinon.assert.notCalled(createDirectoryStub); | ||
}); | ||
|
||
test('Verify copy is called when shell integration is enabled', async () => { | ||
pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); | ||
|
||
await registerPythonStartup(context.object); | ||
|
||
sinon.assert.calledOnce(copyStub); | ||
}); | ||
|
||
test('Verify copy is not called when shell integration is disabled', async () => { | ||
pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => false); | ||
|
||
await registerPythonStartup(context.object); | ||
|
||
sinon.assert.notCalled(copyStub); | ||
}); | ||
|
||
test('PYTHONSTARTUP is set when enableShellIntegration setting is true', async () => { | ||
pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); | ||
|
||
await registerPythonStartup(context.object); | ||
|
||
globalEnvironmentVariableCollection.verify( | ||
(c) => c.replace('PYTHONSTARTUP', TypeMoq.It.isAny(), TypeMoq.It.isAny()), | ||
TypeMoq.Times.once(), | ||
); | ||
}); | ||
|
||
test('environmentCollection should not remove PYTHONSTARTUP when enableShellIntegration setting is true', async () => { | ||
pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); | ||
|
||
await registerPythonStartup(context.object); | ||
|
||
globalEnvironmentVariableCollection.verify((c) => c.delete('PYTHONSTARTUP'), TypeMoq.Times.never()); | ||
}); | ||
|
||
test('PYTHONSTARTUP is not set when enableShellIntegration setting is false', async () => { | ||
pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => false); | ||
|
||
await registerPythonStartup(context.object); | ||
|
||
globalEnvironmentVariableCollection.verify( | ||
(c) => c.replace('PYTHONSTARTUP', TypeMoq.It.isAny(), TypeMoq.It.isAny()), | ||
TypeMoq.Times.never(), | ||
); | ||
}); | ||
|
||
test('PYTHONSTARTUP is deleted when enableShellIntegration setting is false', async () => { | ||
pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => false); | ||
|
||
await registerPythonStartup(context.object); | ||
|
||
globalEnvironmentVariableCollection.verify((c) => c.delete('PYTHONSTARTUP'), TypeMoq.Times.once()); | ||
}); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a hygiene rule in core to prevent this slipping in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea and I've made item on this: #24161
I see "local/code-no-test-only": "error", from vscode. Not sure if that local/code is something vscode repository specific, but I think something like:
works too