Skip to content

Commit

Permalink
Use python debugger in testing (#22903)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulacamargo25 committed Feb 14, 2024
1 parent 84734a8 commit aff0b05
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/client/debugger/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
'use strict';

export const DebuggerTypeName = 'python';
export const PythonDebuggerTypeName = 'debugpy';
6 changes: 3 additions & 3 deletions src/client/debugger/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { DebugConfiguration } from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol/lib/debugProtocol';
import { DebuggerTypeName } from './constants';
import { DebuggerTypeName, PythonDebuggerTypeName } from './constants';

export enum DebugOptions {
RedirectOutput = 'RedirectOutput',
Expand Down Expand Up @@ -123,14 +123,14 @@ export interface LaunchRequestArguments
extends DebugProtocol.LaunchRequestArguments,
IKnownLaunchRequestArguments,
DebugConfiguration {
type: typeof DebuggerTypeName;
type: typeof DebuggerTypeName | typeof PythonDebuggerTypeName;
}

export interface AttachRequestArguments
extends DebugProtocol.AttachRequestArguments,
IKnownAttachDebugArguments,
DebugConfiguration {
type: typeof DebuggerTypeName;
type: typeof DebuggerTypeName | typeof PythonDebuggerTypeName;
}

export interface DebugConfigurationArguments extends LaunchRequestArguments, AttachRequestArguments {}
Expand Down
6 changes: 3 additions & 3 deletions src/client/testing/common/debugLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IApplicationShell, IDebugService } from '../../common/application/types
import { EXTENSION_ROOT_DIR } from '../../common/constants';
import * as internalScripts from '../../common/process/internal/scripts';
import { IConfigurationService, IPythonSettings } from '../../common/types';
import { DebuggerTypeName } from '../../debugger/constants';
import { DebuggerTypeName, PythonDebuggerTypeName } from '../../debugger/constants';
import { IDebugConfigurationResolver } from '../../debugger/extension/configuration/types';
import { DebugPurpose, LaunchRequestArguments } from '../../debugger/types';
import { IServiceContainer } from '../../ioc/types';
Expand Down Expand Up @@ -78,7 +78,7 @@ export class DebugLauncher implements ITestDebugLauncher {
if (!debugConfig) {
debugConfig = {
name: 'Debug Unit Test',
type: 'python',
type: 'debugpy',
request: 'test',
subProcess: true,
};
Expand Down Expand Up @@ -118,7 +118,7 @@ export class DebugLauncher implements ITestDebugLauncher {
for (const cfg of configs) {
if (
cfg.name &&
cfg.type === DebuggerTypeName &&
(cfg.type === DebuggerTypeName || cfg.type === PythonDebuggerTypeName) &&
(cfg.request === 'test' ||
(cfg as LaunchRequestArguments).purpose?.includes(DebugPurpose.DebugTest))
) {
Expand Down
42 changes: 21 additions & 21 deletions src/test/testing/common/debugLauncher.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { IApplicationShell, IDebugService } from '../../../client/common/applica
import { EXTENSION_ROOT_DIR } from '../../../client/common/constants';
import '../../../client/common/extensions';
import { IConfigurationService, IPythonSettings } from '../../../client/common/types';
import { DebuggerTypeName } from '../../../client/debugger/constants';
import { PythonDebuggerTypeName } from '../../../client/debugger/constants';
import { IDebugEnvironmentVariablesService } from '../../../client/debugger/extension/configuration/resolvers/helper';
import { LaunchConfigurationResolver } from '../../../client/debugger/extension/configuration/resolvers/launch';
import { DebugOptions } from '../../../client/debugger/types';
Expand Down Expand Up @@ -166,7 +166,7 @@ suite('Unit Tests - Debug Launcher', () => {
function getDefaultDebugConfig(): DebugConfiguration {
return {
name: 'Debug Unit Test',
type: DebuggerTypeName,
type: PythonDebuggerTypeName,
request: 'launch',
console: 'internalConsole',
env: {},
Expand Down Expand Up @@ -329,7 +329,7 @@ suite('Unit Tests - Debug Launcher', () => {
};
const expected = getDefaultDebugConfig();
expected.name = 'spam';
setupSuccess(options, 'unittest', expected, [{ name: 'spam', type: DebuggerTypeName, request: 'test' }]);
setupSuccess(options, 'unittest', expected, [{ name: 'spam', type: PythonDebuggerTypeName, request: 'test' }]);

await debugLauncher.launchDebugger(options);

Expand Down Expand Up @@ -363,7 +363,7 @@ suite('Unit Tests - Debug Launcher', () => {
};
const expected = {
name: 'my tests',
type: DebuggerTypeName,
type: PythonDebuggerTypeName,
request: 'launch',
python: 'some/dir/bin/py3',
debugAdapterPython: 'some/dir/bin/py3',
Expand All @@ -388,7 +388,7 @@ suite('Unit Tests - Debug Launcher', () => {
setupSuccess(options, 'unittest', expected, [
{
name: 'my tests',
type: DebuggerTypeName,
type: PythonDebuggerTypeName,
request: 'test',
pythonPath: expected.python,
stopOnEntry: expected.stopOnEntry,
Expand Down Expand Up @@ -417,9 +417,9 @@ suite('Unit Tests - Debug Launcher', () => {
const expected = getDefaultDebugConfig();
expected.name = 'spam1';
setupSuccess(options, 'unittest', expected, [
{ name: 'spam1', type: DebuggerTypeName, request: 'test' },
{ name: 'spam2', type: DebuggerTypeName, request: 'test' },
{ name: 'spam3', type: DebuggerTypeName, request: 'test' },
{ name: 'spam1', type: PythonDebuggerTypeName, request: 'test' },
{ name: 'spam2', type: PythonDebuggerTypeName, request: 'test' },
{ name: 'spam3', type: PythonDebuggerTypeName, request: 'test' },
]);

await debugLauncher.launchDebugger(options);
Expand All @@ -446,15 +446,15 @@ suite('Unit Tests - Debug Launcher', () => {
'// test 2 \n\
{ \n\
"name": "spam", \n\
"type": "python", \n\
"type": "debugpy", \n\
"request": "test" \n\
} \n\
',
'// test 3 \n\
[ \n\
{ \n\
"name": "spam", \n\
"type": "python", \n\
"type": "debugpy", \n\
"request": "test" \n\
} \n\
] \n\
Expand All @@ -464,7 +464,7 @@ suite('Unit Tests - Debug Launcher', () => {
"configurations": [ \n\
{ \n\
"name": "spam", \n\
"type": "python", \n\
"type": "debugpy", \n\
"request": "test" \n\
} \n\
] \n\
Expand Down Expand Up @@ -499,10 +499,10 @@ suite('Unit Tests - Debug Launcher', () => {
setupSuccess(options, 'unittest', expected, [
{} as DebugConfiguration,
{ name: 'spam1' } as DebugConfiguration,
{ name: 'spam2', type: DebuggerTypeName } as DebugConfiguration,
{ name: 'spam2', type: PythonDebuggerTypeName } as DebugConfiguration,
{ name: 'spam3', request: 'test' } as DebugConfiguration,
{ type: DebuggerTypeName } as DebugConfiguration,
{ type: DebuggerTypeName, request: 'test' } as DebugConfiguration,
{ type: PythonDebuggerTypeName } as DebugConfiguration,
{ type: PythonDebuggerTypeName, request: 'test' } as DebugConfiguration,
{ request: 'test' } as DebugConfiguration,
]);

Expand Down Expand Up @@ -532,7 +532,7 @@ suite('Unit Tests - Debug Launcher', () => {
testProvider: 'unittest',
};
const expected = getDefaultDebugConfig();
setupSuccess(options, 'unittest', expected, [{ name: 'spam', type: DebuggerTypeName, request: 'bogus' }]);
setupSuccess(options, 'unittest', expected, [{ name: 'spam', type: PythonDebuggerTypeName, request: 'bogus' }]);

await debugLauncher.launchDebugger(options);

Expand All @@ -547,8 +547,8 @@ suite('Unit Tests - Debug Launcher', () => {
};
const expected = getDefaultDebugConfig();
setupSuccess(options, 'unittest', expected, [
{ name: 'spam', type: DebuggerTypeName, request: 'launch' },
{ name: 'spam', type: DebuggerTypeName, request: 'attach' },
{ name: 'spam', type: PythonDebuggerTypeName, request: 'launch' },
{ name: 'spam', type: PythonDebuggerTypeName, request: 'attach' },
]);

await debugLauncher.launchDebugger(options);
Expand All @@ -567,9 +567,9 @@ suite('Unit Tests - Debug Launcher', () => {
setupSuccess(options, 'unittest', expected, [
{ name: 'foo1', type: 'other', request: 'bar' },
{ name: 'foo2', type: 'other', request: 'bar' },
{ name: 'spam1', type: DebuggerTypeName, request: 'launch' },
{ name: 'spam2', type: DebuggerTypeName, request: 'test' },
{ name: 'spam3', type: DebuggerTypeName, request: 'attach' },
{ name: 'spam1', type: PythonDebuggerTypeName, request: 'launch' },
{ name: 'spam2', type: PythonDebuggerTypeName, request: 'test' },
{ name: 'spam3', type: PythonDebuggerTypeName, request: 'attach' },
{ name: 'xyz', type: 'another', request: 'abc' },
]);

Expand Down Expand Up @@ -599,7 +599,7 @@ suite('Unit Tests - Debug Launcher', () => {
{ \n\
// "test" debug config \n\
"name": "spam", /* non-empty */ \n\
"type": "python", /* must be "python" */ \n\
"type": "debugpy", /* must be "python" */ \n\
"request": "test", /* must be "test" */ \n\
// extra stuff here: \n\
"stopOnEntry": true \n\
Expand Down

0 comments on commit aff0b05

Please sign in to comment.