Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulacamargo25 committed Sep 25, 2023
1 parent 2180976 commit ca09c2d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 72 deletions.
3 changes: 1 addition & 2 deletions src/extension/debugger/configuration/resolvers/attach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ export class AttachConfigurationResolver extends BaseConfigurationResolver<Attac
debugConfiguration.host = 'localhost';
}
if (debugConfiguration.justMyCode === undefined) {
const config = getConfiguration('debugpy');
debugConfiguration.justMyCode = config.get<boolean>('debugJustMyCode', false);
debugConfiguration.justMyCode = getConfiguration('debugpy').get<boolean>('debugJustMyCode', true);
}
debugConfiguration.showReturnValue = debugConfiguration.showReturnValue !== false;
// Pass workspace folder so we can get this when we get debug events firing.
Expand Down
5 changes: 3 additions & 2 deletions src/extension/debugger/configuration/resolvers/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver<Launc
debugConfiguration.debugOptions = [];
}
if (debugConfiguration.justMyCode === undefined) {
const config = getConfiguration('debugpy');
debugConfiguration.justMyCode = config.get<boolean>('debugJustMyCode', true);
let a = getConfiguration('debugpy').get<boolean>('debugJustMyCode', true);

debugConfiguration.justMyCode = getConfiguration('debugpy').get<boolean>('debugJustMyCode', true);
}
// Pass workspace folder so we can get this when we get debug events firing.
debugConfiguration.workspaceFolder = workspaceFolder ? workspaceFolder.fsPath : undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/test/unittest/adapter/factory.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ suite('Debugging - Adapter Factory', () => {
assert.deepStrictEqual(descriptor, debugExecutable);
});

test.only('Display a message if no python interpreter is set', async () => {
test('Display a message if no python interpreter is set', async () => {
getActiveEnvironmentPathStub.resolves(undefined);
const session = createSession({});
const promise = factory.createDebugAdapterDescriptor(session, nodeExecutable);
Expand Down
64 changes: 29 additions & 35 deletions src/test/unittest/configuration/resolvers/attach.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { expect } from 'chai';
import * as TypeMoq from 'typemoq';
import * as sinon from 'sinon';
import { DebugConfiguration, DebugConfigurationProvider, TextDocument, TextEditor, Uri, WorkspaceFolder } from 'vscode';
import { DebugConfiguration, DebugConfigurationProvider, TextDocument, TextEditor, Uri, WorkspaceConfiguration, WorkspaceFolder } from 'vscode';
import { PYTHON_LANGUAGE } from '../../../../extension/common/constants';
import { getInfoPerOS } from './common';
import { AttachRequestArguments, DebugOptions } from '../../../../extension/types';
Expand Down Expand Up @@ -34,6 +34,7 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
let getActiveTextEditorStub: sinon.SinonStub;
let getWorkspaceFoldersStub: sinon.SinonStub;
let getOSTypeStub: sinon.SinonStub;
let getConfigurationStub: sinon.SinonStub;
const debugOptionsAvailable = getAvailableOptions();

setup(() => {
Expand All @@ -42,6 +43,8 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
getOSTypeStub = sinon.stub(platform, 'getOSType');
getWorkspaceFoldersStub = sinon.stub(vscodeapi, 'getWorkspaceFolders');
getOSTypeStub.returns(osType);
getConfigurationStub = sinon.stub(vscodeapi, 'getConfiguration');
getConfigurationStub.withArgs('debugpy').returns(createMoqConfiguration(true));
});

teardown(() => {
Expand All @@ -54,6 +57,12 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
return folder.object;
}

function createMoqConfiguration(justMyCode: boolean) {
const debugpySettings = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
debugpySettings.setup((p) => p.get<boolean>('debugJustMyCode', TypeMoq.It.isAny())).returns(() => (justMyCode));
return debugpySettings.object;
}

function setupActiveEditor(fileName: string | undefined, languageId: string) {
if (fileName) {
const textEditor = TypeMoq.Mock.ofType<TextEditor>();
Expand Down Expand Up @@ -493,67 +502,52 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
const testsForJustMyCode = [
{
justMyCode: false,
debugStdLib: true,
expectedResult: false,
},
{
justMyCode: false,
debugStdLib: false,
justMyCodeSetting: true,
expectedResult: false,
},
{
justMyCode: false,
debugStdLib: undefined,
justMyCodeSetting: false,
expectedResult: false,
},
{
justMyCode: true,
debugStdLib: false,
justMyCodeSetting: false,
expectedResult: true,
},
{
justMyCode: true,
debugStdLib: true,
expectedResult: true,
},
{
justMyCode: true,
debugStdLib: undefined,
justMyCodeSetting: true,
expectedResult: true,
},
{
justMyCode: undefined,
debugStdLib: false,
expectedResult: true,
},
{
justMyCode: undefined,
debugStdLib: true,
justMyCodeSetting: false,
expectedResult: false,
},
{
justMyCode: undefined,
debugStdLib: undefined,
justMyCodeSetting: true,
expectedResult: true,
},
];
test('Ensure justMyCode property is correctly derived from debugStdLib', async () => {
const activeFile = 'xyz.py';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

const debugOptions = debugOptionsAvailable
.slice()
.concat(DebugOptions.Jinja, DebugOptions.Sudo) as DebugOptions[];

testsForJustMyCode.forEach(async (testParams) => {
testsForJustMyCode.forEach(async (testParams) => {
test('Ensure justMyCode property is correctly derived from global settings', async () => {
const activeFile = 'xyz.py';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

const debugOptions = debugOptionsAvailable
.slice()
.concat(DebugOptions.Jinja, DebugOptions.Sudo) as DebugOptions[];

getConfigurationStub.withArgs('debugpy').returns(createMoqConfiguration(testParams.justMyCodeSetting));
const debugConfig = await resolveDebugConfiguration(workspaceFolder, {
...attach,
debugOptions,
justMyCode: testParams.justMyCode,
debugStdLib: testParams.debugStdLib,
});
expect(debugConfig).to.have.property('justMyCode', testParams.expectedResult);
});
Expand Down
58 changes: 26 additions & 32 deletions src/test/unittest/configuration/resolvers/launch.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { expect } from 'chai';
import * as TypeMoq from 'typemoq';
import * as sinon from 'sinon';
import { DebugConfiguration, DebugConfigurationProvider, TextDocument, TextEditor, Uri, WorkspaceFolder } from 'vscode';
import { DebugConfiguration, DebugConfigurationProvider, TextDocument, TextEditor, Uri, WorkspaceConfiguration, WorkspaceFolder } from 'vscode';
import { PYTHON_LANGUAGE } from '../../../../extension/common/constants';
import { LaunchConfigurationResolver } from '../../../../extension/debugger/configuration/resolvers/launch';
import { getInfoPerOS } from './common';
Expand All @@ -31,6 +31,7 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
let getInterpreterDetailsStub: sinon.SinonStub;
let getEnvFileStub: sinon.SinonStub;
let getDebugEnvironmentVariablesStub: sinon.SinonStub;
let getConfigurationStub: sinon.SinonStub;

setup(() => {
getActiveTextEditorStub = sinon.stub(vscodeapi, 'getActiveTextEditor');
Expand All @@ -40,6 +41,8 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
getInterpreterDetailsStub = sinon.stub(pythonApi, 'getInterpreterDetails');
getEnvFileStub = sinon.stub(settings, 'getEnvFile');
getDebugEnvironmentVariablesStub = sinon.stub(helper, 'getDebugEnvironmentVariables');
getConfigurationStub = sinon.stub(vscodeapi, 'getConfiguration');
getConfigurationStub.withArgs('debugpy').returns(createMoqConfiguration(true));
});

teardown(() => {
Expand All @@ -52,6 +55,12 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
return folder.object;
}

function createMoqConfiguration(justMyCode: boolean) {
const debugpySettings = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
debugpySettings.setup((p) => p.get<boolean>('debugJustMyCode', TypeMoq.It.isAny())).returns(() => (justMyCode));
return debugpySettings.object;
}

function getClientOS() {
return osType === platform.OSType.Windows ? 'windows' : 'unix';
}
Expand Down Expand Up @@ -727,7 +736,6 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
expect(debugConfig).to.have.property('justMyCode', false);
expect(debugConfig).to.have.property('debugOptions');
const expectedOptions = [
DebugOptions.DebugStdLib,
DebugOptions.ShowReturnValue,
DebugOptions.RedirectOutput,
];
Expand All @@ -740,61 +748,46 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
const testsForJustMyCode = [
{
justMyCode: false,
debugStdLib: true,
expectedResult: false,
},
{
justMyCode: false,
debugStdLib: false,
justMyCodeSetting: true,
expectedResult: false,
},
{
justMyCode: false,
debugStdLib: undefined,
justMyCodeSetting: false,
expectedResult: false,
},
{
justMyCode: true,
debugStdLib: false,
expectedResult: true,
},
{
justMyCode: true,
debugStdLib: true,
justMyCodeSetting: false,
expectedResult: true,
},
{
justMyCode: true,
debugStdLib: undefined,
justMyCodeSetting: true,
expectedResult: true,
},
{
justMyCode: undefined,
debugStdLib: false,
expectedResult: true,
},
{
justMyCode: undefined,
debugStdLib: true,
justMyCodeSetting: false,
expectedResult: false,
},
{
justMyCode: undefined,
debugStdLib: undefined,
justMyCodeSetting: true,
expectedResult: true,
},
];
test('Ensure justMyCode property is correctly derived from debugStdLib', async () => {
const pythonPath = `PythonPath_${new Date().toString()}`;
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';
setupIoc(pythonPath);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
testsForJustMyCode.forEach(async (testParams) => {
testsForJustMyCode.forEach(async (testParams) => {
test('Ensure justMyCode property is correctly derived from global settings', async () => {
const pythonPath = `PythonPath_${new Date().toString()}`;
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';
setupIoc(pythonPath);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
getConfigurationStub.withArgs('debugpy').returns(createMoqConfiguration(testParams.justMyCodeSetting));
const debugConfig = await resolveDebugConfiguration(workspaceFolder, {
...launch,
debugStdLib: testParams.debugStdLib,
justMyCode: testParams.justMyCode,
justMyCode: testParams.justMyCode,
});
expect(debugConfig).to.have.property('justMyCode', testParams.expectedResult);
});
Expand Down Expand Up @@ -930,6 +923,7 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
request: requestType,
type: 'python',
name: '',
justMyCode: false,
...settings,
};
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
Expand Down
1 change: 1 addition & 0 deletions src/test/unittest/extensionInit.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ suite('Debugging - register Debugging', () => {
sinon.assert.calledWithExactly(registerCommandStub, Commands.ClearStorage, sinon.match.any);
expect(registerCommandStub.callCount).to.be.equal(5);
});

test('Activation will register the Debug adapter factories', async () => {
registerDebugger(context.object);

Expand Down

0 comments on commit ca09c2d

Please sign in to comment.