Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulacamargo25 committed Aug 6, 2024
1 parent 56ba8ee commit 56e2c2a
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/test/unittest/configuration/resolvers/attach.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
return debugpySettings.object;
}

function createVariablePresentationMoqConfiguration(variablePresentation: object) {
const debugpySettings = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
debugpySettings
.setup((p) => p.get<object>('debugVariablePresentation', TypeMoq.It.isAny()))
.returns(() => variablePresentation);
return debugpySettings.object;
}

function setupActiveEditor(fileName: string | undefined, languageId: string) {
if (fileName) {
const textEditor = TypeMoq.Mock.ofType<TextEditor>();
Expand Down Expand Up @@ -566,6 +574,60 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
});
});

const testsForVariablePresentation = [
{
variablePresentation: {},
variablePresentationSetting: {
"class": "inline"
},
expectedResult: {},
},
{
variablePresentation: {
"class": "inline"
},
variablePresentationSetting: {
"class": "hide"
},
expectedResult: {
"class": "inline"
},
},
{
variablePresentation: undefined,
variablePresentationSetting: {
"class": "inline"
},
expectedResult: {
"class": "inline"
},
},
];
testsForVariablePresentation.forEach(async (testParams) => {
test('Ensure variablePresentation 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', sinon.match.any)
.returns(createVariablePresentationMoqConfiguration(testParams.variablePresentationSetting));
const debugConfig = await resolveDebugConfiguration(workspaceFolder, {
...attach,
debugOptions,
variablePresentation: testParams.variablePresentation,
});
expect(debugConfig).to.have.property('variablePresentation').that.deep.equals(testParams.expectedResult); // Corrected to use deep.equals

});
});

test('Send consoleName value to debugpy as consoleTitle', async () => {
const activeFile = 'xyz.py';
const consoleName = 'My Console Name';
Expand Down
56 changes: 56 additions & 0 deletions src/test/unittest/configuration/resolvers/launch.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
return debugpySettings.object;
}

function createVariablePresentationMoqConfiguration(variablePresentation: object) {
const debugpySettings = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
debugpySettings
.setup((p) => p.get<object>('debugVariablePresentation', TypeMoq.It.isAny()))
.returns(() => variablePresentation);
return debugpySettings.object;
}

function getClientOS() {
return osType === platform.OSType.Windows ? 'windows' : 'unix';
}
Expand Down Expand Up @@ -803,6 +811,54 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
});
});

const testsForVariablePresentation = [
{
variablePresentation: {},
variablePresentationSetting: {
"class": "inline"
},
expectedResult: {},
},
{
variablePresentation: {
"class": "inline"
},
variablePresentationSetting: {
"class": "hide"
},
expectedResult: {
"class": "inline"
},
},
{
variablePresentation: undefined,
variablePresentationSetting: {
"class": "inline"
},
expectedResult: {
"class": "inline"
},
},
];
testsForVariablePresentation.forEach(async (testParams) => {
test('Ensure variablePresentation 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', sinon.match.any)
.returns(createVariablePresentationMoqConfiguration(testParams.variablePresentationSetting));
const debugConfig = await resolveDebugConfiguration(workspaceFolder, {
...launch,
variablePresentation: testParams.variablePresentation,
});
expect(debugConfig).to.have.property('variablePresentation').that.deep.equals(testParams.expectedResult); // Corrected to use deep.equals

});
});

const testsForRedirectOutput = [
{
console: 'internalConsole',
Expand Down

0 comments on commit 56e2c2a

Please sign in to comment.