From 66ec06bc25edb6e6f50fe8dc73b00bd12c26c8bb Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Fri, 30 Jun 2023 12:21:07 -0700 Subject: [PATCH 1/6] Add verification for interpreter in debugAdapter --- src/extension/common/python.ts | 22 +++++----- src/extension/common/utils/localize.ts | 37 ----------------- src/extension/debugger/adapter/factory.ts | 49 +++++++++-------------- 3 files changed, 30 insertions(+), 78 deletions(-) diff --git a/src/extension/common/python.ts b/src/extension/common/python.ts index b06db990..c91ffcc4 100644 --- a/src/extension/common/python.ts +++ b/src/extension/common/python.ts @@ -80,17 +80,6 @@ export async function initializePython(disposables: Disposable[]): Promise } } -export async function getInterpreterDetails(resource?: Uri): Promise { - const api = await getPythonExtensionAPI(); - const environment = await api?.environments.resolveEnvironment( - api?.environments.getActiveEnvironmentPath(resource), - ); - if (environment?.executable.uri) { - return { path: [environment?.executable.uri.fsPath], resource }; - } - return { path: undefined, resource }; -} - export async function getDebuggerPath(): Promise { const api = await getPythonExtensionAPI(); return api?.debug.getDebuggerPackagePath(); @@ -121,6 +110,17 @@ export async function getActiveEnvironmentPath(resource?: Resource) { return api?.environments.getActiveEnvironmentPath(resource); } +export async function getInterpreterDetails(resource?: Uri): Promise { + const api = await getPythonExtensionAPI(); + const environment = await api?.environments.resolveEnvironment( + api?.environments.getActiveEnvironmentPath(resource), + ); + if (environment?.executable.uri) { + return { path: [environment?.executable.uri.fsPath], resource }; + } + return { path: undefined, resource }; +} + export async function hasInterpreters() { const api = await getPythonExtensionAPI(); if (api) { diff --git a/src/extension/common/utils/localize.ts b/src/extension/common/utils/localize.ts index 0a686823..2475aec5 100644 --- a/src/extension/common/utils/localize.ts +++ b/src/extension/common/utils/localize.ts @@ -133,43 +133,6 @@ export namespace DebugConfigStrings { } } -export namespace Diagnostics { - export const warnSourceMaps = l10n.t( - 'Source map support is enabled in the Python Extension, this will adversely impact performance of the extension.', - ); - export const disableSourceMaps = l10n.t('Disable Source Map Support'); - export const warnBeforeEnablingSourceMaps = l10n.t( - 'Enabling source map support in the Python Extension will adversely impact performance of the extension.', - ); - export const enableSourceMapsAndReloadVSC = l10n.t('Enable and reload Window.'); - export const lsNotSupported = l10n.t( - 'Your operating system does not meet the minimum requirements of the Python Language Server. Reverting to the alternative autocompletion provider, Jedi.', - ); - export const invalidPythonPathInDebuggerSettings = l10n.t( - 'You need to select a Python interpreter before you start debugging.\n\nTip: click on "Select Interpreter" in the status bar.', - ); - export const invalidPythonPathInDebuggerLaunch = l10n.t('The Python path in your debug configuration is invalid.'); - export const invalidDebuggerTypeDiagnostic = l10n.t( - 'Your launch.json file needs to be updated to change the "pythonExperimental" debug configurations to use the "python" debugger type, otherwise Python debugging may not work. Would you like to automatically update your launch.json file now?', - ); - export const consoleTypeDiagnostic = l10n.t( - 'Your launch.json file needs to be updated to change the console type string from "none" to "internalConsole", otherwise Python debugging may not work. Would you like to automatically update your launch.json file now?', - ); - export const justMyCodeDiagnostic = l10n.t( - 'Configuration "debugStdLib" in launch.json is no longer supported. It\'s recommended to replace it with "justMyCode", which is the exact opposite of using "debugStdLib". Would you like to automatically update your launch.json file to do that?', - ); - export const yesUpdateLaunch = l10n.t('Yes, update launch.json'); - export const invalidTestSettings = l10n.t( - 'Your settings needs to be updated to change the setting "python.unitTest." to "python.testing.", otherwise testing Python code using the extension may not work. Would you like to automatically update your settings now?', - ); - export const updateSettings = l10n.t('Yes, update settings'); - export const checkIsort5UpgradeGuide = l10n.t( - 'We found outdated configuration for sorting imports in this workspace. Check the [isort upgrade guide](https://aka.ms/AA9j5x4) to update your settings.', - ); - export const pylanceDefaultMessage = l10n.t( - "The Python extension now includes Pylance to improve completions, code navigation, overall performance and much more! You can learn more about the update and learn how to change your language server [here](https://aka.ms/new-python-bundle).\n\nRead Pylance's license [here](https://marketplace.visualstudio.com/items/ms-python.vscode-pylance/license).", - ); -} export namespace Common { export const loadingExtension = l10n.t('Python Debugger extension loading...'); diff --git a/src/extension/debugger/adapter/factory.ts b/src/extension/debugger/adapter/factory.ts index 842780b9..31a82521 100644 --- a/src/extension/debugger/adapter/factory.ts +++ b/src/extension/debugger/adapter/factory.ts @@ -13,15 +13,16 @@ import { DebugSession, l10n, WorkspaceFolder, + debug, } from 'vscode'; import { AttachRequestArguments, LaunchRequestArguments } from '../../types'; import { IDebugAdapterDescriptorFactory } from '../types'; -import { showErrorMessage } from '../../common/vscodeapi'; +import { executeCommand, showErrorMessage } from '../../common/vscodeapi'; import { traceLog, traceVerbose } from '../../common/log/logging'; import { EventName } from '../../telemetry/constants'; import { sendTelemetryEvent } from '../../telemetry'; import { - getActiveEnvironmentPath, + getInterpreterDetails, getInterpreters, hasInterpreters, resolveEnvironment, @@ -45,7 +46,7 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac public async createDebugAdapterDescriptor( session: DebugSession, _executable: DebugAdapterExecutable | undefined, - ): Promise { + ): Promise { const configuration = session.configuration as LaunchRequestArguments | AttachRequestArguments; // There are four distinct scenarios here: @@ -98,10 +99,9 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac traceLog(`DAP Server launched with command: ${executable} ${args.join(' ')}`); sendTelemetryEvent(EventName.DEBUG_ADAPTER_USING_WHEELS_PATH, undefined, { usingWheels: true }); return new DebugAdapterExecutable(executable, args); + } else { + debug.stopDebugging(session); } - - // Unlikely scenario. - throw new Error('Debug Adapter Executable not provided'); } // FIX THIS @@ -127,22 +127,23 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac } const resourceUri = workspaceFolder ? workspaceFolder.uri : undefined; - const interpreterPath = await getActiveEnvironmentPath(resourceUri); + const interpreter = await getInterpreterDetails(resourceUri); - if (interpreterPath) { - traceVerbose(`Selecting active interpreter as Python Executable for DA '${interpreterPath}'`); - return this.getExecutableCommand(await resolveEnvironment(interpreterPath)); + if (interpreter.path) { + traceVerbose(`Selecting active interpreter as Python Executable for DA '${interpreter.path[0]}'`); + return this.getExecutableCommand(await resolveEnvironment(interpreter.path[0])); } - await hasInterpreters(); // Wait until we know whether we have an interpreter - const interpreters = await getInterpreters(); - if (interpreters.length === 0) { - ignoreErrors(this.notifySelectInterpreter()); - return []; + const prompts = [Interpreters.changePythonInterpreter]; + const selection = await showErrorMessage( + l10n.t('You need to select a Python interpreter before you start debugging.\n\nTip: click on "Select Interpreter" in the status bar.',), + { modal: true }, + ...prompts, + ); + if (selection === Interpreters.changePythonInterpreter) { + executeCommand(Commands.Set_Interpreter); } - - traceVerbose(`Picking first available interpreter to launch the DA '${interpreters[0].path}'`); - return this.getExecutableCommand(interpreters[0]); + return []; } private async showDeprecatedPythonMessage() { @@ -185,16 +186,4 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac } return []; } - - /** - * Notify user about the requirement for Python. - * Unlikely scenario, as ex expect users to have Python in order to use the extension. - * However it is possible to ignore the warnings and continue using the extension. - * - * @private - * @memberof DebugAdapterDescriptorFactory - */ - private async notifySelectInterpreter() { - await showErrorMessage(l10n.t('Please install Python or select a Python Interpreter to use the debugger.')); - } } From a7cd940f25e59fc8562c698e4bcc520ac203c28a Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Mon, 24 Jul 2023 00:04:42 -0700 Subject: [PATCH 2/6] Fix tests --- src/extension/common/python.ts | 4 +- src/extension/common/utils/localize.ts | 1 - src/extension/debugger/adapter/factory.ts | 22 ++++------ .../unittest/adapter/factory.unit.test.ts | 44 ++++++++++++------- 4 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/extension/common/python.ts b/src/extension/common/python.ts index c91ffcc4..ed1fc5f7 100644 --- a/src/extension/common/python.ts +++ b/src/extension/common/python.ts @@ -26,7 +26,7 @@ interface IExtensionApi { known: Environment[]; getActiveEnvironmentPath(resource?: Resource): EnvironmentPath; resolveEnvironment( - environment: Environment | EnvironmentPath | string, + environment: Environment | EnvironmentPath | string | undefined, ): Promise; readonly onDidChangeActiveEnvironmentPath: Event; getEnvironmentVariables(resource?: Resource): EnvironmentVariables; @@ -100,7 +100,7 @@ export async function getEnvironmentVariables(resource?: Resource) { return api?.environments.getEnvironmentVariables(resource); } -export async function resolveEnvironment(env: Environment | EnvironmentPath | string) { +export async function resolveEnvironment(env: Environment | EnvironmentPath | string | undefined) { const api = await getPythonExtensionAPI(); return api?.environments.resolveEnvironment(env); } diff --git a/src/extension/common/utils/localize.ts b/src/extension/common/utils/localize.ts index 2475aec5..d76cdcc1 100644 --- a/src/extension/common/utils/localize.ts +++ b/src/extension/common/utils/localize.ts @@ -133,7 +133,6 @@ export namespace DebugConfigStrings { } } - export namespace Common { export const loadingExtension = l10n.t('Python Debugger extension loading...'); export const doNotShowAgain = l10n.t('Do not show again'); diff --git a/src/extension/debugger/adapter/factory.ts b/src/extension/debugger/adapter/factory.ts index 31a82521..5e8e736f 100644 --- a/src/extension/debugger/adapter/factory.ts +++ b/src/extension/debugger/adapter/factory.ts @@ -21,18 +21,11 @@ import { executeCommand, showErrorMessage } from '../../common/vscodeapi'; import { traceLog, traceVerbose } from '../../common/log/logging'; import { EventName } from '../../telemetry/constants'; import { sendTelemetryEvent } from '../../telemetry'; -import { - getInterpreterDetails, - getInterpreters, - hasInterpreters, - resolveEnvironment, - runPythonExtensionCommand, -} from '../../common/python'; +import { getActiveEnvironmentPath, resolveEnvironment, runPythonExtensionCommand } from '../../common/python'; import { Commands, EXTENSION_ROOT_DIR } from '../../common/constants'; import { Common, Interpreters } from '../../common/utils/localize'; import { IPersistentStateFactory } from '../../common/types'; import { Environment } from '../../common/pythonTypes'; -import { ignoreErrors } from '../../common/promiseUtils'; // persistent state names, exported to make use of in testing export enum debugStateKeys { @@ -127,16 +120,19 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac } const resourceUri = workspaceFolder ? workspaceFolder.uri : undefined; - const interpreter = await getInterpreterDetails(resourceUri); + const interpreterPath = await getActiveEnvironmentPath(resourceUri); + const interpreter = await resolveEnvironment(interpreterPath); - if (interpreter.path) { - traceVerbose(`Selecting active interpreter as Python Executable for DA '${interpreter.path[0]}'`); - return this.getExecutableCommand(await resolveEnvironment(interpreter.path[0])); + if (interpreter?.path) { + traceVerbose(`Selecting active interpreter as Python Executable for DA '${interpreterPath}'`); + return this.getExecutableCommand(await resolveEnvironment(interpreterPath)); } const prompts = [Interpreters.changePythonInterpreter]; const selection = await showErrorMessage( - l10n.t('You need to select a Python interpreter before you start debugging.\n\nTip: click on "Select Interpreter" in the status bar.',), + l10n.t( + 'You need to select a Python interpreter before you start debugging.\n\nTip: click on "Select Interpreter" in the status bar.', + ), { modal: true }, ...prompts, ); diff --git a/src/test/unittest/adapter/factory.unit.test.ts b/src/test/unittest/adapter/factory.unit.test.ts index 70b9f1d7..228e7c9f 100644 --- a/src/test/unittest/adapter/factory.unit.test.ts +++ b/src/test/unittest/adapter/factory.unit.test.ts @@ -22,6 +22,7 @@ import * as vscodeApi from '../../../extension/common/vscodeapi'; import { EXTENSION_ROOT_DIR } from '../../../extension/common/constants'; import { Architecture } from '../../../extension/common/platform'; import * as pythonApi from '../../../extension/common/python'; +import { debug } from 'vscode'; use(chaiAsPromised); @@ -34,6 +35,7 @@ suite('Debugging - Adapter Factory', () => { let getInterpretersStub: sinon.SinonStub; let getActiveEnvironmentPathStub: sinon.SinonStub; let hasInterpretersStub: sinon.SinonStub; + let stopDebuggingStub: sinon.SinonStub; const nodeExecutable = undefined; const debugAdapterPath = path.join(EXTENSION_ROOT_DIR, 'bundled', 'libs', 'debugpy', 'adapter'); @@ -72,6 +74,7 @@ suite('Debugging - Adapter Factory', () => { getInterpretersStub = sinon.stub(pythonApi, 'getInterpreters'); getActiveEnvironmentPathStub = sinon.stub(pythonApi, 'getActiveEnvironmentPath'); hasInterpretersStub = sinon.stub(pythonApi, 'hasInterpreters'); + stopDebuggingStub = sinon.stub(debug, 'stopDebugging'); when( stateFactory.createGlobalPersistentState(debugStateKeys.doNotShowAgain, false), @@ -125,21 +128,15 @@ suite('Debugging - Adapter Factory', () => { assert.deepStrictEqual(descriptor, debugExecutable); }); - test('Return the path of the first available interpreter as the current python path, configuration.pythonPath is not defined and there is no active interpreter', async () => { - const session = createSession({}); - const debugExecutable = new DebugAdapterExecutable(pythonPath, [debugAdapterPath]); - - const descriptor = await factory.createDebugAdapterDescriptor(session, nodeExecutable); - - assert.deepStrictEqual(descriptor, debugExecutable); - }); - test('Display a message if no python interpreter is set', async () => { - getInterpretersStub.returns([]); + getActiveEnvironmentPathStub.resolves(undefined); const session = createSession({}); - const promise = factory.createDebugAdapterDescriptor(session, nodeExecutable); + await factory.createDebugAdapterDescriptor(session, nodeExecutable); - await expect(promise).to.eventually.be.rejectedWith('Debug Adapter Executable not provided'); + //check stop debugger + sinon.assert.calledOnceWithExactly(stopDebuggingStub, session); + + //check error message sinon.assert.calledOnce(showErrorMessageStub); }); @@ -191,11 +188,10 @@ suite('Debugging - Adapter Factory', () => { test('Return Debug Adapter executable if request is "attach", and listen is specified', async () => { const session = createSession({ request: 'attach', listen: { port: 5678, host: 'localhost' } }); const debugExecutable = new DebugAdapterExecutable(pythonPath, [debugAdapterPath]); - getActiveEnvironmentPathStub.resolves(interpreter.path); resolveEnvironmentStub.resolves(interpreter); - const descriptor = await factory.createDebugAdapterDescriptor(session, nodeExecutable); + assert.deepStrictEqual(descriptor, debugExecutable); }); @@ -223,6 +219,9 @@ suite('Debugging - Adapter Factory', () => { EXTENSION_ROOT_DIR, ]); + getActiveEnvironmentPathStub.resolves(interpreter.path); + resolveEnvironmentStub.withArgs(interpreter.path).resolves(interpreter); + const descriptor = await factory.createDebugAdapterDescriptor(session, nodeExecutable); assert.deepStrictEqual(descriptor, debugExecutable); @@ -232,6 +231,9 @@ suite('Debugging - Adapter Factory', () => { const session = createSession({}); const debugExecutable = new DebugAdapterExecutable(pythonPath, [debugAdapterPath]); + getActiveEnvironmentPathStub.resolves(interpreter.path); + resolveEnvironmentStub.withArgs(interpreter.path).resolves(interpreter); + const descriptor = await factory.createDebugAdapterDescriptor(session, nodeExecutable); assert.deepStrictEqual(descriptor, debugExecutable); @@ -241,6 +243,9 @@ suite('Debugging - Adapter Factory', () => { const session = createSession({ logToFile: false }); const debugExecutable = new DebugAdapterExecutable(pythonPath, [debugAdapterPath]); + getActiveEnvironmentPathStub.resolves(interpreter.path); + resolveEnvironmentStub.withArgs(interpreter.path).resolves(interpreter); + const descriptor = await factory.createDebugAdapterDescriptor(session, nodeExecutable); assert.deepStrictEqual(descriptor, debugExecutable); @@ -248,6 +253,9 @@ suite('Debugging - Adapter Factory', () => { test('Send attach to local process telemetry if attaching to a local process', async () => { const session = createSession({ request: 'attach', processId: 1234 }); + getActiveEnvironmentPathStub.resolves(interpreter.path); + resolveEnvironmentStub.withArgs(interpreter.path).resolves(interpreter); + await factory.createDebugAdapterDescriptor(session, nodeExecutable); assert.ok(Reporter.eventNames.includes(EventName.DEBUGGER_ATTACH_TO_LOCAL_PROCESS)); @@ -255,6 +263,8 @@ suite('Debugging - Adapter Factory', () => { test("Don't send any telemetry if not attaching to a local process", async () => { const session = createSession({}); + getActiveEnvironmentPathStub.resolves(interpreter.path); + resolveEnvironmentStub.withArgs(interpreter.path).resolves(interpreter); await factory.createDebugAdapterDescriptor(session, nodeExecutable); @@ -265,7 +275,8 @@ suite('Debugging - Adapter Factory', () => { const customAdapterPath = 'custom/debug/adapter/path'; const session = createSession({ debugAdapterPath: customAdapterPath }); const debugExecutable = new DebugAdapterExecutable(pythonPath, [customAdapterPath]); - + getActiveEnvironmentPathStub.resolves(interpreter.path); + resolveEnvironmentStub.withArgs(interpreter.path).resolves(interpreter); const descriptor = await factory.createDebugAdapterDescriptor(session, nodeExecutable); assert.deepStrictEqual(descriptor, debugExecutable); @@ -292,7 +303,8 @@ suite('Debugging - Adapter Factory', () => { test('Do not use "python" to spawn the debug adapter', async () => { const session = createSession({ python: '/bin/custompy' }); const debugExecutable = new DebugAdapterExecutable(pythonPath, [debugAdapterPath]); - + getActiveEnvironmentPathStub.resolves(interpreter.path); + resolveEnvironmentStub.withArgs(interpreter.path).resolves(interpreter); const descriptor = await factory.createDebugAdapterDescriptor(session, nodeExecutable); assert.deepStrictEqual(descriptor, debugExecutable); From 57242abeea0539e1aa800b558455dc73e4500c7b Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Mon, 24 Jul 2023 12:01:18 -0700 Subject: [PATCH 3/6] Add error --- src/extension/debugger/adapter/factory.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/extension/debugger/adapter/factory.ts b/src/extension/debugger/adapter/factory.ts index 5e8e736f..06172734 100644 --- a/src/extension/debugger/adapter/factory.ts +++ b/src/extension/debugger/adapter/factory.ts @@ -93,14 +93,13 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac sendTelemetryEvent(EventName.DEBUG_ADAPTER_USING_WHEELS_PATH, undefined, { usingWheels: true }); return new DebugAdapterExecutable(executable, args); } else { - debug.stopDebugging(session); + throw new Error('Debug Stopped'); } } - // FIX THIS /** * Get the python executable used to launch the Python Debug Adapter. - * In the case of `attach` scenarios, just use the workspace interpreter, else first available one. + * In the case of `attach` scenarios, just use the workspace interpreter. * It is unlike user won't have a Python interpreter * * @private @@ -137,7 +136,7 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac ...prompts, ); if (selection === Interpreters.changePythonInterpreter) { - executeCommand(Commands.Set_Interpreter); + await executeCommand(Commands.Set_Interpreter); } return []; } From dc90877598b32134dbed3e7c92f011d5f3700fe1 Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Tue, 25 Jul 2023 12:05:00 -0700 Subject: [PATCH 4/6] Fix unused import --- src/extension/debugger/adapter/factory.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/extension/debugger/adapter/factory.ts b/src/extension/debugger/adapter/factory.ts index 06172734..8a55cce2 100644 --- a/src/extension/debugger/adapter/factory.ts +++ b/src/extension/debugger/adapter/factory.ts @@ -13,7 +13,6 @@ import { DebugSession, l10n, WorkspaceFolder, - debug, } from 'vscode'; import { AttachRequestArguments, LaunchRequestArguments } from '../../types'; import { IDebugAdapterDescriptorFactory } from '../types'; From 124813c3519c1adc7ceff4fd262649e92c23397a Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Tue, 25 Jul 2023 12:24:29 -0700 Subject: [PATCH 5/6] Fix tests --- src/extension/common/utils/localize.ts | 1 + src/extension/debugger/adapter/factory.ts | 4 ++-- src/test/unittest/adapter/factory.unit.test.ts | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/extension/common/utils/localize.ts b/src/extension/common/utils/localize.ts index cdb369a9..36346e9f 100644 --- a/src/extension/common/utils/localize.ts +++ b/src/extension/common/utils/localize.ts @@ -13,6 +13,7 @@ export namespace AttachProcess { } export namespace DebugConfigStrings { + export const debugStopped = l10n.t('Debug Stopped'); export const selectConfiguration = { title: l10n.t('Select a debug configuration'), placeholder: l10n.t('Debug Configuration'), diff --git a/src/extension/debugger/adapter/factory.ts b/src/extension/debugger/adapter/factory.ts index 8a55cce2..af5b58cc 100644 --- a/src/extension/debugger/adapter/factory.ts +++ b/src/extension/debugger/adapter/factory.ts @@ -22,7 +22,7 @@ import { EventName } from '../../telemetry/constants'; import { sendTelemetryEvent } from '../../telemetry'; import { getActiveEnvironmentPath, resolveEnvironment, runPythonExtensionCommand } from '../../common/python'; import { Commands, EXTENSION_ROOT_DIR } from '../../common/constants'; -import { Common, Interpreters } from '../../common/utils/localize'; +import { Common, DebugConfigStrings, Interpreters } from '../../common/utils/localize'; import { IPersistentStateFactory } from '../../common/types'; import { Environment } from '../../common/pythonTypes'; @@ -92,7 +92,7 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac sendTelemetryEvent(EventName.DEBUG_ADAPTER_USING_WHEELS_PATH, undefined, { usingWheels: true }); return new DebugAdapterExecutable(executable, args); } else { - throw new Error('Debug Stopped'); + throw new Error(DebugConfigStrings.debugStopped); } } diff --git a/src/test/unittest/adapter/factory.unit.test.ts b/src/test/unittest/adapter/factory.unit.test.ts index 228e7c9f..6c635105 100644 --- a/src/test/unittest/adapter/factory.unit.test.ts +++ b/src/test/unittest/adapter/factory.unit.test.ts @@ -23,6 +23,7 @@ import { EXTENSION_ROOT_DIR } from '../../../extension/common/constants'; import { Architecture } from '../../../extension/common/platform'; import * as pythonApi from '../../../extension/common/python'; import { debug } from 'vscode'; +import { DebugConfigStrings } from '../../../extension/common/utils/localize'; use(chaiAsPromised); @@ -128,13 +129,12 @@ suite('Debugging - Adapter Factory', () => { assert.deepStrictEqual(descriptor, debugExecutable); }); - test('Display a message if no python interpreter is set', async () => { + test.only('Display a message if no python interpreter is set', async () => { getActiveEnvironmentPathStub.resolves(undefined); const session = createSession({}); - await factory.createDebugAdapterDescriptor(session, nodeExecutable); + const promise = factory.createDebugAdapterDescriptor(session, nodeExecutable); - //check stop debugger - sinon.assert.calledOnceWithExactly(stopDebuggingStub, session); + await expect(promise).to.eventually.be.rejectedWith(DebugConfigStrings.debugStopped); //check error message sinon.assert.calledOnce(showErrorMessageStub); From c210045e3626763f867e54e0d09a85875c3d5152 Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Tue, 25 Jul 2023 12:34:00 -0700 Subject: [PATCH 6/6] fix import error --- src/test/unittest/adapter/factory.unit.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/unittest/adapter/factory.unit.test.ts b/src/test/unittest/adapter/factory.unit.test.ts index 6c635105..04fef451 100644 --- a/src/test/unittest/adapter/factory.unit.test.ts +++ b/src/test/unittest/adapter/factory.unit.test.ts @@ -22,7 +22,6 @@ import * as vscodeApi from '../../../extension/common/vscodeapi'; import { EXTENSION_ROOT_DIR } from '../../../extension/common/constants'; import { Architecture } from '../../../extension/common/platform'; import * as pythonApi from '../../../extension/common/python'; -import { debug } from 'vscode'; import { DebugConfigStrings } from '../../../extension/common/utils/localize'; use(chaiAsPromised); @@ -36,7 +35,6 @@ suite('Debugging - Adapter Factory', () => { let getInterpretersStub: sinon.SinonStub; let getActiveEnvironmentPathStub: sinon.SinonStub; let hasInterpretersStub: sinon.SinonStub; - let stopDebuggingStub: sinon.SinonStub; const nodeExecutable = undefined; const debugAdapterPath = path.join(EXTENSION_ROOT_DIR, 'bundled', 'libs', 'debugpy', 'adapter'); @@ -75,7 +73,6 @@ suite('Debugging - Adapter Factory', () => { getInterpretersStub = sinon.stub(pythonApi, 'getInterpreters'); getActiveEnvironmentPathStub = sinon.stub(pythonApi, 'getActiveEnvironmentPath'); hasInterpretersStub = sinon.stub(pythonApi, 'hasInterpreters'); - stopDebuggingStub = sinon.stub(debug, 'stopDebugging'); when( stateFactory.createGlobalPersistentState(debugStateKeys.doNotShowAgain, false),