From d4d42629823b931dff0d12df9576748884025a15 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 17:09:01 -0700 Subject: [PATCH 01/14] start creating test for pythonstartup setting --- src/test/.vscode/settings.json | 2 +- .../terminals/codeExecution/smartSend.test.ts | 3 + .../shellIntegration/pythonStartup.test.ts | 63 +++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/test/terminals/shellIntegration/pythonStartup.test.ts diff --git a/src/test/.vscode/settings.json b/src/test/.vscode/settings.json index cd2b4152591d..65764d5f6132 100644 --- a/src/test/.vscode/settings.json +++ b/src/test/.vscode/settings.json @@ -14,5 +14,5 @@ // Don't set this to `Pylance`, for CI we want to use the LS that ships with the extension. "python.languageServer": "Jedi", "python.pythonPath": "C:\\GIT\\s p\\vscode-python\\.venv\\Scripts\\python.exe", - "python.defaultInterpreterPath": "python" + "python.defaultInterpreterPath": "/Users/anthonykim/Desktop/vscode-python/.venv/bin/python" } diff --git a/src/test/terminals/codeExecution/smartSend.test.ts b/src/test/terminals/codeExecution/smartSend.test.ts index 594db361f51e..6fac0cbe2eb4 100644 --- a/src/test/terminals/codeExecution/smartSend.test.ts +++ b/src/test/terminals/codeExecution/smartSend.test.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + import * as TypeMoq from 'typemoq'; import * as path from 'path'; import { TextEditor, Selection, Position, TextDocument, Uri } from 'vscode'; diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts new file mode 100644 index 000000000000..cfbd05b2f309 --- /dev/null +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +import * as sinon from 'sinon'; +import * as TypeMoq from 'typemoq'; +import { EnvironmentVariableCollection, GlobalEnvironmentVariableCollection, 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 context: IExtensionContext; + let getConfigurationStub: sinon.SinonStub; + let pythonConfig: TypeMoq.IMock; + let editorConfig: TypeMoq.IMock; + let context: TypeMoq.IMock; + let createDirectoryStub: sinon.SinonStub; + let copyStub: sinon.SinonStub; + let environmentVariableCollection: TypeMoq.IMock; + let globalEnvironmentVariableCollection: TypeMoq.IMock; + setup(() => { + context = TypeMoq.Mock.ofType(); + context.setup((c) => c).returns(() => context.object); + environmentVariableCollection = TypeMoq.Mock.ofType(); + globalEnvironmentVariableCollection = TypeMoq.Mock.ofType(); + context.setup((c) => c.environmentVariableCollection).returns(() => globalEnvironmentVariableCollection.object); + // setup context.environmentVariableCollection when delete method is called + globalEnvironmentVariableCollection.setup((c) => c.delete(TypeMoq.It.isAny())).returns(() => undefined); + + getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); + createDirectoryStub = sinon.stub(workspaceApis, 'createDirectory'); + copyStub = sinon.stub(workspaceApis, 'copy'); + + pythonConfig = TypeMoq.Mock.ofType(); + editorConfig = TypeMoq.Mock.ofType(); + 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('PYTHONSTARTUP is set when setting is enabled', async () => { + pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); + + await registerPythonStartup(context.object); + + // Make sure context.environmentVariableCollection.replace is called once + // context.verify( + // (c) => c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny()), + // TypeMoq.Times.once(), + // ); + context.verify((c) => c.environmentVariableCollection.delete(TypeMoq.It.isAny()), TypeMoq.Times.once()); + // fail the test + }); +}); From b72fe78e523c6d927f37d9ae1ce264fc2dd1ac6a Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 17:10:34 -0700 Subject: [PATCH 02/14] failing to run locally, 0 pass or fail --- .../terminals/shellIntegration/pythonStartup.test.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index cfbd05b2f309..ee8714a44869 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -15,6 +15,7 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { let context: TypeMoq.IMock; let createDirectoryStub: sinon.SinonStub; let copyStub: sinon.SinonStub; + // eslint-disable-next-line @typescript-eslint/no-unused-vars let environmentVariableCollection: TypeMoq.IMock; let globalEnvironmentVariableCollection: TypeMoq.IMock; setup(() => { @@ -53,11 +54,9 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { await registerPythonStartup(context.object); // Make sure context.environmentVariableCollection.replace is called once - // context.verify( - // (c) => c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny()), - // TypeMoq.Times.once(), - // ); - context.verify((c) => c.environmentVariableCollection.delete(TypeMoq.It.isAny()), TypeMoq.Times.once()); - // fail the test + context.verify( + (c) => c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny()), + TypeMoq.Times.once(), + ); }); }); From 32edc64ccce533daaa16dc9cd859aa9526caff32 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 17:49:24 -0700 Subject: [PATCH 03/14] c.environmentVariableCollection.replace is not a function? --- .vscode/launch.json | 2 +- src/test/repl/variableProvider.test.ts | 2 +- .../shellIntegration/pythonStartup.test.ts | 22 +++++++++++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1e983413c8d4..603eaa45394f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -90,7 +90,7 @@ "--extensionTestsPath=${workspaceFolder}/out/test" ], "env": { - "VSC_PYTHON_CI_TEST_GREP": "" // Modify this to run a subset of the single workspace tests + "VSC_PYTHON_CI_TEST_GREP": "PYTHONSTARTUP is set when setting is enabled" // Modify this to run a subset of the single workspace tests }, "sourceMaps": true, "outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"], diff --git a/src/test/repl/variableProvider.test.ts b/src/test/repl/variableProvider.test.ts index 8b45fae0c5a0..1b151d34c096 100644 --- a/src/test/repl/variableProvider.test.ts +++ b/src/test/repl/variableProvider.test.ts @@ -8,7 +8,7 @@ import { IVariableDescription } from '../../client/repl/variables/types'; import { VariablesProvider } from '../../client/repl/variables/variablesProvider'; import { VariableRequester } from '../../client/repl/variables/variableRequester'; -suite.only('ReplVariablesProvider', () => { +suite('ReplVariablesProvider', () => { let provider: VariablesProvider; let varRequester: TypeMoq.IMock; let notebook: TypeMoq.IMock; diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index ee8714a44869..4939228e38ed 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -2,7 +2,12 @@ // Licensed under the MIT License. import * as sinon from 'sinon'; import * as TypeMoq from 'typemoq'; -import { EnvironmentVariableCollection, GlobalEnvironmentVariableCollection, WorkspaceConfiguration } from 'vscode'; +import { + EnvironmentVariableCollection, + 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'; @@ -20,12 +25,20 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { let globalEnvironmentVariableCollection: TypeMoq.IMock; setup(() => { context = TypeMoq.Mock.ofType(); - context.setup((c) => c).returns(() => context.object); + // context.setup((c) => c).returns(() => context.object); environmentVariableCollection = TypeMoq.Mock.ofType(); globalEnvironmentVariableCollection = TypeMoq.Mock.ofType(); + context.setup((c) => c.environmentVariableCollection).returns(() => globalEnvironmentVariableCollection.object); - // setup context.environmentVariableCollection when delete method is called - globalEnvironmentVariableCollection.setup((c) => c.delete(TypeMoq.It.isAny())).returns(() => undefined); + globalEnvironmentVariableCollection + .setup((c) => c.getScoped(TypeMoq.It.isAny())) + .returns(() => environmentVariableCollection.object); + context.setup((c) => c.storageUri).returns(() => Uri.parse('a')); + context + .setup((c) => + c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()), + ) + .returns(() => Promise.resolve()); getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); createDirectoryStub = sinon.stub(workspaceApis, 'createDirectory'); @@ -58,5 +71,6 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { (c) => c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny()), TypeMoq.Times.once(), ); + // context.verify((c) => c.environmentVariableCollection.delete(TypeMoq.It.isAny()), TypeMoq.Times.never()); }); }); From 5ab075e1d5345e01d639a8004fd286182ccee648 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 18:52:48 -0700 Subject: [PATCH 04/14] context.environmentVariableCollection.delete AND replace is not a function??? --- .vscode/launch.json | 2 +- .../pythonStartup-ts-mockito.test.ts | 104 ++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/test/terminals/shellIntegration/pythonStartup-ts-mockito.test.ts diff --git a/.vscode/launch.json b/.vscode/launch.json index 603eaa45394f..eb5ab6b20c57 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -90,7 +90,7 @@ "--extensionTestsPath=${workspaceFolder}/out/test" ], "env": { - "VSC_PYTHON_CI_TEST_GREP": "PYTHONSTARTUP is set when setting is enabled" // Modify this to run a subset of the single workspace tests + "VSC_PYTHON_CI_TEST_GREP": "Terminal - Shell Integration with PYTHONSTARTUP" // Modify this to run a subset of the single workspace tests }, "sourceMaps": true, "outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"], diff --git a/src/test/terminals/shellIntegration/pythonStartup-ts-mockito.test.ts b/src/test/terminals/shellIntegration/pythonStartup-ts-mockito.test.ts new file mode 100644 index 000000000000..a75dd61374f4 --- /dev/null +++ b/src/test/terminals/shellIntegration/pythonStartup-ts-mockito.test.ts @@ -0,0 +1,104 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +import * as sinon from 'sinon'; +import * as TypeMoq from 'typemoq'; +import { + EnvironmentVariableCollection, + GlobalEnvironmentVariableCollection, + Uri, + WorkspaceConfiguration, +} from 'vscode'; +import { mock, instance, when, anything, verify, reset } from 'ts-mockito'; +import path from 'path'; +import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis'; +import { registerPythonStartup } from '../../../client/terminals/pythonStartup'; +import { IExtensionContext } from '../../../client/common/types'; + +suite.only('temporarily try with ts-mockito', () => { + // let context: IExtensionContext; + let getConfigurationStub: sinon.SinonStub; + let pythonConfig: TypeMoq.IMock; + let editorConfig: TypeMoq.IMock; + // let context: TypeMoq.IMock; + let context: IExtensionContext; + let createDirectoryStub: sinon.SinonStub; + let copyStub: sinon.SinonStub; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + // let environmentVariableCollection: TypeMoq.IMock; + // let globalEnvironmentVariableCollection: TypeMoq.IMock; + + let collection: EnvironmentVariableCollection; + let globalCollection: GlobalEnvironmentVariableCollection; + + const joinPathStub = sinon.stub(Uri, 'joinPath'); + const sourcePathStub = sinon.stub(path, 'join'); + + setup(() => { + // context = TypeMoq.Mock.ofType(); + context = mock(); + // context.setup((c) => c).returns(() => context.object); + // environmentVariableCollection = TypeMoq.Mock.ofType(); + // globalEnvironmentVariableCollection = TypeMoq.Mock.ofType(); + + // context.setup((c) => c.environmentVariableCollection).returns(() => globalEnvironmentVariableCollection.object); + // globalEnvironmentVariableCollection + // .setup((c) => c.getScoped(TypeMoq.It.isAny())) + // .returns(() => environmentVariableCollection.object); + // context.setup((c) => c.storageUri).returns(() => Uri.parse('a')); + // context + // .setup((c) => + // c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()), + // ) + // .returns(() => Promise.resolve()); + + globalCollection = mock(); + collection = mock(); + when(context.environmentVariableCollection).thenReturn(instance(globalCollection)); + when(globalCollection.getScoped(anything())).thenReturn(instance(collection)); + + getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); + createDirectoryStub = sinon.stub(workspaceApis, 'createDirectory'); + copyStub = sinon.stub(workspaceApis, 'copy'); + when(context.storageUri).thenReturn(undefined); + + // Stub the Uri.joinPath method + joinPathStub.returns(Uri.parse('file:///mock/path/pythonrc.py')); + + pythonConfig = TypeMoq.Mock.ofType(); + editorConfig = TypeMoq.Mock.ofType(); + 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('PYTHONSTARTUP is set when setting is enabled', async () => { + pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => false); + when(context.storageUri).thenReturn(Uri.parse('file:///a/b/c')); + + // Stub the Uri.joinPath method + joinPathStub.returns(Uri.parse('file:///mock/path/pythonrc.py')); + + await registerPythonStartup(context); + + // Make sure context.environmentVariableCollection.replace is called once + // context.verify( + // (c) => c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny()), + // TypeMoq.Times.once(), + // ); + when(collection.replace(anything(), anything(), anything())).thenResolve(); + when(collection.delete(anything())).thenResolve(); + // verify(collection.replace(anything(), anything(), anything())).once(); + verify(collection.delete(anything())).once(); + // context.verify((c) => c.environmentVariableCollection.delete(TypeMoq.It.isAny()), TypeMoq.Times.never()); + }); +}); From 88081765369bfe980cf3c58623e90a1e0fd12967 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 19:26:55 -0700 Subject: [PATCH 05/14] two test working, one test still mystery --- .../pythonStartup-ts-mockito.test.ts | 148 ++++++++++++------ .../shellIntegration/pythonStartup.test.ts | 31 +++- 2 files changed, 124 insertions(+), 55 deletions(-) diff --git a/src/test/terminals/shellIntegration/pythonStartup-ts-mockito.test.ts b/src/test/terminals/shellIntegration/pythonStartup-ts-mockito.test.ts index a75dd61374f4..462b647a4787 100644 --- a/src/test/terminals/shellIntegration/pythonStartup-ts-mockito.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup-ts-mockito.test.ts @@ -5,64 +5,125 @@ import * as TypeMoq from 'typemoq'; import { EnvironmentVariableCollection, GlobalEnvironmentVariableCollection, + ProgressLocation, Uri, WorkspaceConfiguration, } from 'vscode'; import { mock, instance, when, anything, verify, reset } from 'ts-mockito'; import path from 'path'; +import { expect } from 'chai'; import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis'; import { registerPythonStartup } from '../../../client/terminals/pythonStartup'; -import { IExtensionContext } from '../../../client/common/types'; +import { + IConfigurationService, + IExperimentService, + IExtensionContext, + IPythonSettings, +} from '../../../client/common/types'; +import { + IApplicationShell, + IApplicationEnvironment, + IWorkspaceService, +} from '../../../client/common/application/types'; +import { TerminalEnvVarActivation } from '../../../client/common/experiments/groups'; +import { PathUtils } from '../../../client/common/platform/pathUtils'; +import { IPlatformService } from '../../../client/common/platform/types'; +import { Interpreters } from '../../../client/common/utils/localize'; +import { IEnvironmentVariablesProvider } from '../../../client/common/variables/types'; +import { defaultShells } from '../../../client/interpreter/activation/service'; +import { IEnvironmentActivationService } from '../../../client/interpreter/activation/types'; +import { IInterpreterService } from '../../../client/interpreter/contracts'; +import { TerminalEnvVarCollectionService } from '../../../client/terminals/envCollectionActivation/service'; +import { ITerminalDeactivateService, IShellIntegrationDetectionService } from '../../../client/terminals/types'; +import { getOSType, OSType } from '../../common'; + +suite('hello mockito', () => { + let platform: IPlatformService; + let interpreterService: IInterpreterService; + let context: IExtensionContext; + let shell: IApplicationShell; + let experimentService: IExperimentService; + let collection: EnvironmentVariableCollection; + let globalCollection: GlobalEnvironmentVariableCollection; + let applicationEnvironment: IApplicationEnvironment; + let environmentActivationService: IEnvironmentActivationService; + let workspaceService: IWorkspaceService; + let terminalEnvVarCollectionService: TerminalEnvVarCollectionService; + let terminalDeactivateService: ITerminalDeactivateService; -suite.only('temporarily try with ts-mockito', () => { - // let context: IExtensionContext; + const progressOptions = { + location: ProgressLocation.Window, + title: Interpreters.activatingTerminals, + }; + let configService: IConfigurationService; + let shellIntegrationService: IShellIntegrationDetectionService; + const displayPath = 'display/path'; + const customShell = 'powershell'; + const defaultShell = defaultShells[getOSType()]; let getConfigurationStub: sinon.SinonStub; let pythonConfig: TypeMoq.IMock; let editorConfig: TypeMoq.IMock; - // let context: TypeMoq.IMock; - let context: IExtensionContext; let createDirectoryStub: sinon.SinonStub; let copyStub: sinon.SinonStub; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - // let environmentVariableCollection: TypeMoq.IMock; - // let globalEnvironmentVariableCollection: TypeMoq.IMock; - - let collection: EnvironmentVariableCollection; - let globalCollection: GlobalEnvironmentVariableCollection; - - const joinPathStub = sinon.stub(Uri, 'joinPath'); - const sourcePathStub = sinon.stub(path, 'join'); setup(() => { - // context = TypeMoq.Mock.ofType(); + workspaceService = mock(); + terminalDeactivateService = mock(); + when(terminalDeactivateService.getScriptLocation(anything(), anything())).thenResolve(undefined); + when(terminalDeactivateService.initializeScriptParams(anything())).thenResolve(); + when(workspaceService.getWorkspaceFolder(anything())).thenReturn(undefined); + when(workspaceService.workspaceFolders).thenReturn(undefined); + platform = mock(); + when(platform.osType).thenReturn(getOSType()); + interpreterService = mock(); context = mock(); - // context.setup((c) => c).returns(() => context.object); - // environmentVariableCollection = TypeMoq.Mock.ofType(); - // globalEnvironmentVariableCollection = TypeMoq.Mock.ofType(); - - // context.setup((c) => c.environmentVariableCollection).returns(() => globalEnvironmentVariableCollection.object); - // globalEnvironmentVariableCollection - // .setup((c) => c.getScoped(TypeMoq.It.isAny())) - // .returns(() => environmentVariableCollection.object); - // context.setup((c) => c.storageUri).returns(() => Uri.parse('a')); - // context - // .setup((c) => - // c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()), - // ) - // .returns(() => Promise.resolve()); - + shell = mock(); + const envVarProvider = mock(); + shellIntegrationService = mock(); + when(shellIntegrationService.isWorking()).thenResolve(true); globalCollection = mock(); collection = mock(); when(context.environmentVariableCollection).thenReturn(instance(globalCollection)); when(globalCollection.getScoped(anything())).thenReturn(instance(collection)); + experimentService = mock(); + when(experimentService.inExperimentSync(TerminalEnvVarActivation.experiment)).thenReturn(true); + applicationEnvironment = mock(); + when(applicationEnvironment.shell).thenReturn(customShell); + when(shell.withProgress(anything(), anything())) + .thenCall((options, _) => { + expect(options).to.deep.equal(progressOptions); + }) + .thenResolve(); + environmentActivationService = mock(); + when(environmentActivationService.getProcessEnvironmentVariables(anything(), anything())).thenResolve( + process.env, + ); + configService = mock(); + when(configService.getSettings(anything())).thenReturn(({ + terminal: { activateEnvironment: true }, + pythonPath: displayPath, + } as unknown) as IPythonSettings); + when(collection.clear()).thenResolve(); + terminalEnvVarCollectionService = new TerminalEnvVarCollectionService( + instance(platform), + instance(interpreterService), + instance(context), + instance(shell), + instance(experimentService), + instance(applicationEnvironment), + [], + instance(environmentActivationService), + instance(workspaceService), + instance(configService), + instance(terminalDeactivateService), + new PathUtils(getOSType() === OSType.Windows), + instance(shellIntegrationService), + instance(envVarProvider), + ); getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); createDirectoryStub = sinon.stub(workspaceApis, 'createDirectory'); copyStub = sinon.stub(workspaceApis, 'copy'); - when(context.storageUri).thenReturn(undefined); - - // Stub the Uri.joinPath method - joinPathStub.returns(Uri.parse('file:///mock/path/pythonrc.py')); pythonConfig = TypeMoq.Mock.ofType(); editorConfig = TypeMoq.Mock.ofType(); @@ -75,6 +136,7 @@ suite.only('temporarily try with ts-mockito', () => { createDirectoryStub.callsFake((_) => Promise.resolve()); copyStub.callsFake((_, __, ___) => Promise.resolve()); + when(context.storageUri).thenReturn(Uri.parse('http://www.example.com/some/path')); }); teardown(() => { @@ -82,23 +144,15 @@ suite.only('temporarily try with ts-mockito', () => { }); test('PYTHONSTARTUP is set when setting is enabled', async () => { - pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => false); - when(context.storageUri).thenReturn(Uri.parse('file:///a/b/c')); - - // Stub the Uri.joinPath method - joinPathStub.returns(Uri.parse('file:///mock/path/pythonrc.py')); + pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); + when(collection.replace(anything(), anything(), anything())).thenResolve(); + when(collection.delete(anything())).thenResolve(); + when(context.storageUri).thenReturn(Uri.parse('http://www.example.com/some/path')); await registerPythonStartup(context); // Make sure context.environmentVariableCollection.replace is called once - // context.verify( - // (c) => c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny()), - // TypeMoq.Times.once(), - // ); - when(collection.replace(anything(), anything(), anything())).thenResolve(); - when(collection.delete(anything())).thenResolve(); - // verify(collection.replace(anything(), anything(), anything())).once(); - verify(collection.delete(anything())).once(); + verify(collection.replace).once(); // context.verify((c) => c.environmentVariableCollection.delete(TypeMoq.It.isAny()), TypeMoq.Times.never()); }); }); diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index 4939228e38ed..1274700400b8 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -38,7 +38,7 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { .setup((c) => c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()), ) - .returns(() => Promise.resolve()); + .returns(() => Promise.resolve()); // TODO: what is wrong with this --> complaining it is NOT a Function getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); createDirectoryStub = sinon.stub(workspaceApis, 'createDirectory'); @@ -61,16 +61,31 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { sinon.restore(); }); - test('PYTHONSTARTUP is set when setting is enabled', async () => { + test('Verify createDirectory is called when shell integration is enabled', async () => { pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); await registerPythonStartup(context.object); - // Make sure context.environmentVariableCollection.replace is called once - context.verify( - (c) => c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny()), - TypeMoq.Times.once(), - ); - // context.verify((c) => c.environmentVariableCollection.delete(TypeMoq.It.isAny()), TypeMoq.Times.never()); + // Verify createDirectoryStub has been called + 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); + + // Verify createDirectoryStub has not been called + sinon.assert.notCalled(createDirectoryStub); + }); + + // TODO: figure out what is wrong. How is environmentVariableCollection not a function in context? + test('Verify environment collection.replace is called when shell integration is enabled', async () => { + pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); + + await registerPythonStartup(context.object); + + // Verify environment collection.replace has been called + sinon.assert.calledOnce(context.environmentVariableCollection.replace); }); }); From 74e51b76b220aa448f46a159fbb2aa3906bbc6f3 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 19:27:46 -0700 Subject: [PATCH 06/14] get rid of attempt to convert test into ts-mockito --- .../pythonStartup-ts-mockito.test.ts | 158 ------------------ 1 file changed, 158 deletions(-) delete mode 100644 src/test/terminals/shellIntegration/pythonStartup-ts-mockito.test.ts diff --git a/src/test/terminals/shellIntegration/pythonStartup-ts-mockito.test.ts b/src/test/terminals/shellIntegration/pythonStartup-ts-mockito.test.ts deleted file mode 100644 index 462b647a4787..000000000000 --- a/src/test/terminals/shellIntegration/pythonStartup-ts-mockito.test.ts +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -import * as sinon from 'sinon'; -import * as TypeMoq from 'typemoq'; -import { - EnvironmentVariableCollection, - GlobalEnvironmentVariableCollection, - ProgressLocation, - Uri, - WorkspaceConfiguration, -} from 'vscode'; -import { mock, instance, when, anything, verify, reset } from 'ts-mockito'; -import path from 'path'; -import { expect } from 'chai'; -import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis'; -import { registerPythonStartup } from '../../../client/terminals/pythonStartup'; -import { - IConfigurationService, - IExperimentService, - IExtensionContext, - IPythonSettings, -} from '../../../client/common/types'; -import { - IApplicationShell, - IApplicationEnvironment, - IWorkspaceService, -} from '../../../client/common/application/types'; -import { TerminalEnvVarActivation } from '../../../client/common/experiments/groups'; -import { PathUtils } from '../../../client/common/platform/pathUtils'; -import { IPlatformService } from '../../../client/common/platform/types'; -import { Interpreters } from '../../../client/common/utils/localize'; -import { IEnvironmentVariablesProvider } from '../../../client/common/variables/types'; -import { defaultShells } from '../../../client/interpreter/activation/service'; -import { IEnvironmentActivationService } from '../../../client/interpreter/activation/types'; -import { IInterpreterService } from '../../../client/interpreter/contracts'; -import { TerminalEnvVarCollectionService } from '../../../client/terminals/envCollectionActivation/service'; -import { ITerminalDeactivateService, IShellIntegrationDetectionService } from '../../../client/terminals/types'; -import { getOSType, OSType } from '../../common'; - -suite('hello mockito', () => { - let platform: IPlatformService; - let interpreterService: IInterpreterService; - let context: IExtensionContext; - let shell: IApplicationShell; - let experimentService: IExperimentService; - let collection: EnvironmentVariableCollection; - let globalCollection: GlobalEnvironmentVariableCollection; - let applicationEnvironment: IApplicationEnvironment; - let environmentActivationService: IEnvironmentActivationService; - let workspaceService: IWorkspaceService; - let terminalEnvVarCollectionService: TerminalEnvVarCollectionService; - let terminalDeactivateService: ITerminalDeactivateService; - - const progressOptions = { - location: ProgressLocation.Window, - title: Interpreters.activatingTerminals, - }; - let configService: IConfigurationService; - let shellIntegrationService: IShellIntegrationDetectionService; - const displayPath = 'display/path'; - const customShell = 'powershell'; - const defaultShell = defaultShells[getOSType()]; - let getConfigurationStub: sinon.SinonStub; - let pythonConfig: TypeMoq.IMock; - let editorConfig: TypeMoq.IMock; - let createDirectoryStub: sinon.SinonStub; - let copyStub: sinon.SinonStub; - - setup(() => { - workspaceService = mock(); - terminalDeactivateService = mock(); - when(terminalDeactivateService.getScriptLocation(anything(), anything())).thenResolve(undefined); - when(terminalDeactivateService.initializeScriptParams(anything())).thenResolve(); - when(workspaceService.getWorkspaceFolder(anything())).thenReturn(undefined); - when(workspaceService.workspaceFolders).thenReturn(undefined); - platform = mock(); - when(platform.osType).thenReturn(getOSType()); - interpreterService = mock(); - context = mock(); - shell = mock(); - const envVarProvider = mock(); - shellIntegrationService = mock(); - when(shellIntegrationService.isWorking()).thenResolve(true); - globalCollection = mock(); - collection = mock(); - when(context.environmentVariableCollection).thenReturn(instance(globalCollection)); - when(globalCollection.getScoped(anything())).thenReturn(instance(collection)); - experimentService = mock(); - when(experimentService.inExperimentSync(TerminalEnvVarActivation.experiment)).thenReturn(true); - applicationEnvironment = mock(); - when(applicationEnvironment.shell).thenReturn(customShell); - when(shell.withProgress(anything(), anything())) - .thenCall((options, _) => { - expect(options).to.deep.equal(progressOptions); - }) - .thenResolve(); - environmentActivationService = mock(); - when(environmentActivationService.getProcessEnvironmentVariables(anything(), anything())).thenResolve( - process.env, - ); - configService = mock(); - when(configService.getSettings(anything())).thenReturn(({ - terminal: { activateEnvironment: true }, - pythonPath: displayPath, - } as unknown) as IPythonSettings); - when(collection.clear()).thenResolve(); - terminalEnvVarCollectionService = new TerminalEnvVarCollectionService( - instance(platform), - instance(interpreterService), - instance(context), - instance(shell), - instance(experimentService), - instance(applicationEnvironment), - [], - instance(environmentActivationService), - instance(workspaceService), - instance(configService), - instance(terminalDeactivateService), - new PathUtils(getOSType() === OSType.Windows), - instance(shellIntegrationService), - instance(envVarProvider), - ); - - getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); - createDirectoryStub = sinon.stub(workspaceApis, 'createDirectory'); - copyStub = sinon.stub(workspaceApis, 'copy'); - - pythonConfig = TypeMoq.Mock.ofType(); - editorConfig = TypeMoq.Mock.ofType(); - getConfigurationStub.callsFake((section: string) => { - if (section === 'python') { - return pythonConfig.object; - } - return editorConfig.object; - }); - - createDirectoryStub.callsFake((_) => Promise.resolve()); - copyStub.callsFake((_, __, ___) => Promise.resolve()); - when(context.storageUri).thenReturn(Uri.parse('http://www.example.com/some/path')); - }); - - teardown(() => { - sinon.restore(); - }); - - test('PYTHONSTARTUP is set when setting is enabled', async () => { - pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); - when(collection.replace(anything(), anything(), anything())).thenResolve(); - when(collection.delete(anything())).thenResolve(); - when(context.storageUri).thenReturn(Uri.parse('http://www.example.com/some/path')); - - await registerPythonStartup(context); - - // Make sure context.environmentVariableCollection.replace is called once - verify(collection.replace).once(); - // context.verify((c) => c.environmentVariableCollection.delete(TypeMoq.It.isAny()), TypeMoq.Times.never()); - }); -}); From ad8129e65ebf2ce97046296ea44bb834ac6406bb Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 19:35:10 -0700 Subject: [PATCH 07/14] more test to prepare once mystery is resolved --- .../terminals/shellIntegration/pythonStartup.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index 1274700400b8..c3c6d3af779e 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -88,4 +88,16 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { // Verify environment collection.replace has been called sinon.assert.calledOnce(context.environmentVariableCollection.replace); }); + + // TODO: BLOCKED: How is it that environmentVariableCollection is not a function in context? + // Is it some mystery between IExtensionContext and ExtensionContext? + + // test('Verify copy is called when shell integration is enabled', async () => { + // pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); + + // await registerPythonStartup(context.object); + + // // Verify copyStub has been called + // sinon.assert.calledOnce(copyStub); + // }); }); From fbecbc38ea4399e0ebf14c186c63852d7cfe3f62 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 19:36:22 -0700 Subject: [PATCH 08/14] leave questions so I don't forget things --- src/test/terminals/shellIntegration/pythonStartup.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index c3c6d3af779e..d1826ca7e92a 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -29,6 +29,8 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { environmentVariableCollection = TypeMoq.Mock.ofType(); globalEnvironmentVariableCollection = TypeMoq.Mock.ofType(); + // 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); globalEnvironmentVariableCollection .setup((c) => c.getScoped(TypeMoq.It.isAny())) From 4d11998118f3b384a609d2642bcf67e7756bade3 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 19:38:25 -0700 Subject: [PATCH 09/14] add more test where I can, leave the blocker with question --- .../shellIntegration/pythonStartup.test.ts | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index d1826ca7e92a..02fc5aae681f 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -36,12 +36,14 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { .setup((c) => c.getScoped(TypeMoq.It.isAny())) .returns(() => environmentVariableCollection.object); context.setup((c) => c.storageUri).returns(() => Uri.parse('a')); + + // Commenting out 41 to 45 will pas first couple test. "c.environmentVariableCollection is not a function" crashes everything. context .setup((c) => c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()), ) .returns(() => Promise.resolve()); // TODO: what is wrong with this --> complaining it is NOT a Function - + // Marker ----- getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); createDirectoryStub = sinon.stub(workspaceApis, 'createDirectory'); copyStub = sinon.stub(workspaceApis, 'copy'); @@ -81,25 +83,31 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { sinon.assert.notCalled(createDirectoryStub); }); - // TODO: figure out what is wrong. How is environmentVariableCollection not a function in context? - test('Verify environment collection.replace is called when shell integration is enabled', async () => { + test('Verify copy is called when shell integration is enabled', async () => { pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); await registerPythonStartup(context.object); - // Verify environment collection.replace has been called - sinon.assert.calledOnce(context.environmentVariableCollection.replace); + // Verify copyStub has been called + sinon.assert.calledOnce(copyStub); }); - // TODO: BLOCKED: How is it that environmentVariableCollection is not a function in context? - // Is it some mystery between IExtensionContext and ExtensionContext? + 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); + + // Verify copyStub has not been called + sinon.assert.notCalled(copyStub); + }); - // test('Verify copy is called when shell integration is enabled', async () => { - // pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); + // TODO: figure out what is wrong. How is environmentVariableCollection not a function in context? + test('Verify environment collection.replace is called when shell integration is enabled', async () => { + pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); - // await registerPythonStartup(context.object); + await registerPythonStartup(context.object); - // // Verify copyStub has been called - // sinon.assert.calledOnce(copyStub); - // }); + // Verify environment collection.replace has been called + sinon.assert.calledOnce(context.environmentVariableCollection.replace); + }); }); From b164ac35778deda8f9543491cb58db35929204b1 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 23:26:47 -0700 Subject: [PATCH 10/14] fianlly figured it out --- .../shellIntegration/pythonStartup.test.ts | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index 02fc5aae681f..c4cf801c0fe4 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -23,6 +23,7 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { // eslint-disable-next-line @typescript-eslint/no-unused-vars let environmentVariableCollection: TypeMoq.IMock; let globalEnvironmentVariableCollection: TypeMoq.IMock; + setup(() => { context = TypeMoq.Mock.ofType(); // context.setup((c) => c).returns(() => context.object); @@ -37,12 +38,20 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { .returns(() => environmentVariableCollection.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()); + + environmentVariableCollection + .setup((c) => c.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())) + .returns(() => Promise.resolve()); + // Commenting out 41 to 45 will pas first couple test. "c.environmentVariableCollection is not a function" crashes everything. - context - .setup((c) => - c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()), - ) - .returns(() => Promise.resolve()); // TODO: what is wrong with this --> complaining it is NOT a Function + // context + // .setup((c) => + // c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()), + // ) + // .returns(() => Promise.resolve()); // Marker ----- getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); createDirectoryStub = sinon.stub(workspaceApis, 'createDirectory'); @@ -108,6 +117,9 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { await registerPythonStartup(context.object); // Verify environment collection.replace has been called - sinon.assert.calledOnce(context.environmentVariableCollection.replace); + globalEnvironmentVariableCollection.verify( + (c) => c.replace('PYTHONSTARTUP', TypeMoq.It.isAny(), TypeMoq.It.isAny()), + TypeMoq.Times.once(), + ); }); }); From 56526ad0743c7d588d7e2e004bd48233ff08f212 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 23:35:17 -0700 Subject: [PATCH 11/14] I win --- .../shellIntegration/pythonStartup.test.ts | 61 +++++++++---------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index c4cf801c0fe4..1958749b0cc4 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -2,57 +2,35 @@ // Licensed under the MIT License. import * as sinon from 'sinon'; import * as TypeMoq from 'typemoq'; -import { - EnvironmentVariableCollection, - GlobalEnvironmentVariableCollection, - Uri, - WorkspaceConfiguration, -} from 'vscode'; +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 context: IExtensionContext; let getConfigurationStub: sinon.SinonStub; let pythonConfig: TypeMoq.IMock; let editorConfig: TypeMoq.IMock; let context: TypeMoq.IMock; let createDirectoryStub: sinon.SinonStub; let copyStub: sinon.SinonStub; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - let environmentVariableCollection: TypeMoq.IMock; let globalEnvironmentVariableCollection: TypeMoq.IMock; setup(() => { context = TypeMoq.Mock.ofType(); - // context.setup((c) => c).returns(() => context.object); - environmentVariableCollection = TypeMoq.Mock.ofType(); globalEnvironmentVariableCollection = TypeMoq.Mock.ofType(); // 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); - globalEnvironmentVariableCollection - .setup((c) => c.getScoped(TypeMoq.It.isAny())) - .returns(() => environmentVariableCollection.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()); - environmentVariableCollection - .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()); - // Commenting out 41 to 45 will pas first couple test. "c.environmentVariableCollection is not a function" crashes everything. - // context - // .setup((c) => - // c.environmentVariableCollection.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()), - // ) - // .returns(() => Promise.resolve()); - // Marker ----- getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); createDirectoryStub = sinon.stub(workspaceApis, 'createDirectory'); copyStub = sinon.stub(workspaceApis, 'copy'); @@ -79,7 +57,6 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { await registerPythonStartup(context.object); - // Verify createDirectoryStub has been called sinon.assert.calledOnce(createDirectoryStub); }); @@ -88,7 +65,6 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { await registerPythonStartup(context.object); - // Verify createDirectoryStub has not been called sinon.assert.notCalled(createDirectoryStub); }); @@ -97,7 +73,6 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { await registerPythonStartup(context.object); - // Verify copyStub has been called sinon.assert.calledOnce(copyStub); }); @@ -106,20 +81,44 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { await registerPythonStartup(context.object); - // Verify copyStub has not been called sinon.assert.notCalled(copyStub); }); - // TODO: figure out what is wrong. How is environmentVariableCollection not a function in context? - test('Verify environment collection.replace is called when shell integration is enabled', async () => { + test('PYTHONSTARTUP is set when enableShellIntegration setting is true', async () => { pythonConfig.setup((p) => p.get('REPL.enableShellIntegration')).returns(() => true); await registerPythonStartup(context.object); - // Verify environment collection.replace has been called 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()); + }); }); From 3765370abec5a2dbe3f25a71a11e980487fb4eff Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 23:38:08 -0700 Subject: [PATCH 12/14] remove junk --- .vscode/launch.json | 2 +- src/test/.vscode/settings.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index eb5ab6b20c57..1e983413c8d4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -90,7 +90,7 @@ "--extensionTestsPath=${workspaceFolder}/out/test" ], "env": { - "VSC_PYTHON_CI_TEST_GREP": "Terminal - Shell Integration with PYTHONSTARTUP" // Modify this to run a subset of the single workspace tests + "VSC_PYTHON_CI_TEST_GREP": "" // Modify this to run a subset of the single workspace tests }, "sourceMaps": true, "outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"], diff --git a/src/test/.vscode/settings.json b/src/test/.vscode/settings.json index 65764d5f6132..36d3fd77195e 100644 --- a/src/test/.vscode/settings.json +++ b/src/test/.vscode/settings.json @@ -14,5 +14,4 @@ // Don't set this to `Pylance`, for CI we want to use the LS that ships with the extension. "python.languageServer": "Jedi", "python.pythonPath": "C:\\GIT\\s p\\vscode-python\\.venv\\Scripts\\python.exe", - "python.defaultInterpreterPath": "/Users/anthonykim/Desktop/vscode-python/.venv/bin/python" } From aeb0b5ab643fb77d4eb81443312f8648264e449e Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 23:38:45 -0700 Subject: [PATCH 13/14] pay attention to newlines --- src/test/terminals/shellIntegration/pythonStartup.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index 1958749b0cc4..41388fc331c8 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -1,5 +1,6 @@ // 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'; From 32a11b526fe4a0a4ca392b4bacdbc8813fe413f4 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 20 Sep 2024 23:39:42 -0700 Subject: [PATCH 14/14] last one --- src/test/.vscode/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/.vscode/settings.json b/src/test/.vscode/settings.json index 36d3fd77195e..cd2b4152591d 100644 --- a/src/test/.vscode/settings.json +++ b/src/test/.vscode/settings.json @@ -14,4 +14,5 @@ // Don't set this to `Pylance`, for CI we want to use the LS that ships with the extension. "python.languageServer": "Jedi", "python.pythonPath": "C:\\GIT\\s p\\vscode-python\\.venv\\Scripts\\python.exe", + "python.defaultInterpreterPath": "python" }