Skip to content

Commit 56e2c2a

Browse files
Add tests
1 parent 56ba8ee commit 56e2c2a

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

src/test/unittest/configuration/resolvers/attach.unit.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
7474
return debugpySettings.object;
7575
}
7676

77+
function createVariablePresentationMoqConfiguration(variablePresentation: object) {
78+
const debugpySettings = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
79+
debugpySettings
80+
.setup((p) => p.get<object>('debugVariablePresentation', TypeMoq.It.isAny()))
81+
.returns(() => variablePresentation);
82+
return debugpySettings.object;
83+
}
84+
7785
function setupActiveEditor(fileName: string | undefined, languageId: string) {
7886
if (fileName) {
7987
const textEditor = TypeMoq.Mock.ofType<TextEditor>();
@@ -566,6 +574,60 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
566574
});
567575
});
568576

577+
const testsForVariablePresentation = [
578+
{
579+
variablePresentation: {},
580+
variablePresentationSetting: {
581+
"class": "inline"
582+
},
583+
expectedResult: {},
584+
},
585+
{
586+
variablePresentation: {
587+
"class": "inline"
588+
},
589+
variablePresentationSetting: {
590+
"class": "hide"
591+
},
592+
expectedResult: {
593+
"class": "inline"
594+
},
595+
},
596+
{
597+
variablePresentation: undefined,
598+
variablePresentationSetting: {
599+
"class": "inline"
600+
},
601+
expectedResult: {
602+
"class": "inline"
603+
},
604+
},
605+
];
606+
testsForVariablePresentation.forEach(async (testParams) => {
607+
test('Ensure variablePresentation property is correctly derived from global settings', async () => {
608+
const activeFile = 'xyz.py';
609+
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
610+
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
611+
const defaultWorkspace = path.join('usr', 'desktop');
612+
setupWorkspaces([defaultWorkspace]);
613+
614+
const debugOptions = debugOptionsAvailable
615+
.slice()
616+
.concat(DebugOptions.Jinja, DebugOptions.Sudo) as DebugOptions[];
617+
618+
getConfigurationStub
619+
.withArgs('debugpy', sinon.match.any)
620+
.returns(createVariablePresentationMoqConfiguration(testParams.variablePresentationSetting));
621+
const debugConfig = await resolveDebugConfiguration(workspaceFolder, {
622+
...attach,
623+
debugOptions,
624+
variablePresentation: testParams.variablePresentation,
625+
});
626+
expect(debugConfig).to.have.property('variablePresentation').that.deep.equals(testParams.expectedResult); // Corrected to use deep.equals
627+
628+
});
629+
});
630+
569631
test('Send consoleName value to debugpy as consoleTitle', async () => {
570632
const activeFile = 'xyz.py';
571633
const consoleName = 'My Console Name';

src/test/unittest/configuration/resolvers/launch.unit.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
7272
return debugpySettings.object;
7373
}
7474

75+
function createVariablePresentationMoqConfiguration(variablePresentation: object) {
76+
const debugpySettings = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
77+
debugpySettings
78+
.setup((p) => p.get<object>('debugVariablePresentation', TypeMoq.It.isAny()))
79+
.returns(() => variablePresentation);
80+
return debugpySettings.object;
81+
}
82+
7583
function getClientOS() {
7684
return osType === platform.OSType.Windows ? 'windows' : 'unix';
7785
}
@@ -803,6 +811,54 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
803811
});
804812
});
805813

814+
const testsForVariablePresentation = [
815+
{
816+
variablePresentation: {},
817+
variablePresentationSetting: {
818+
"class": "inline"
819+
},
820+
expectedResult: {},
821+
},
822+
{
823+
variablePresentation: {
824+
"class": "inline"
825+
},
826+
variablePresentationSetting: {
827+
"class": "hide"
828+
},
829+
expectedResult: {
830+
"class": "inline"
831+
},
832+
},
833+
{
834+
variablePresentation: undefined,
835+
variablePresentationSetting: {
836+
"class": "inline"
837+
},
838+
expectedResult: {
839+
"class": "inline"
840+
},
841+
},
842+
];
843+
testsForVariablePresentation.forEach(async (testParams) => {
844+
test('Ensure variablePresentation property is correctly derived from global settings', async () => {
845+
const pythonPath = `PythonPath_${new Date().toString()}`;
846+
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
847+
const pythonFile = 'xyz.py';
848+
setupIoc(pythonPath);
849+
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
850+
getConfigurationStub
851+
.withArgs('debugpy', sinon.match.any)
852+
.returns(createVariablePresentationMoqConfiguration(testParams.variablePresentationSetting));
853+
const debugConfig = await resolveDebugConfiguration(workspaceFolder, {
854+
...launch,
855+
variablePresentation: testParams.variablePresentation,
856+
});
857+
expect(debugConfig).to.have.property('variablePresentation').that.deep.equals(testParams.expectedResult); // Corrected to use deep.equals
858+
859+
});
860+
});
861+
806862
const testsForRedirectOutput = [
807863
{
808864
console: 'internalConsole',

0 commit comments

Comments
 (0)