Skip to content

Commit 8956500

Browse files
fix tests
1 parent be2a2ff commit 8956500

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/test/unittest/inlineValue/pythonInlineValueProvider.unit.test.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
import * as chaiAsPromised from 'chai-as-promised';
77
import * as path from 'path';
8+
import * as TypeMoq from 'typemoq';
89
import * as sinon from 'sinon';
910
import { use, expect } from 'chai';
1011
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../constants';
1112
import { PythonInlineValueProvider } from '../../../extension/debugger/inlineValue/pythonInlineValueProvider';
12-
import { workspace, Range, InlineValueContext } from 'vscode';
13+
import { workspace, Range, InlineValueContext, WorkspaceConfiguration } from 'vscode';
1314
import * as vscodeapi from '../../../extension/common/vscodeapi';
1415

1516
use(chaiAsPromised);
@@ -18,16 +19,27 @@ const WS_ROOT = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test');
1819

1920
suite('Debugging - pythonInlineProvider', () => {
2021
let customRequestStub: sinon.SinonStub;
22+
let getConfigurationStub: sinon.SinonStub;
2123

2224
setup(() => {
2325
customRequestStub = sinon.stub(vscodeapi, 'customRequest');
2426
customRequestStub.withArgs('scopes', sinon.match.any).resolves({ scopes: [{ variablesReference: 0 }] });
27+
getConfigurationStub = sinon.stub(vscodeapi, 'getConfiguration');
28+
getConfigurationStub.withArgs('debugpy').returns(createMoqConfiguration(true));
2529
});
2630

2731
teardown(async () => {
2832
sinon.restore();
2933
});
3034

35+
function createMoqConfiguration(showPythonInlineValues: boolean) {
36+
const debugpySettings = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
37+
debugpySettings
38+
.setup((p) => p.get<boolean>('showPythonInlineValues', TypeMoq.It.isAny()))
39+
.returns(() => showPythonInlineValues);
40+
return debugpySettings.object;
41+
}
42+
3143
test('ProvideInlineValues function should return all the vars in the python file', async () => {
3244
customRequestStub.withArgs('variables', sinon.match.any).resolves({
3345
variables: [
@@ -331,7 +343,7 @@ suite('Debugging - pythonInlineProvider', () => {
331343
expect(result).to.deep.equal(expected);
332344
});
333345

334-
test.only('ProvideInlineValues function should return all the vars in the python file using Assignment Expressions', async () => {
346+
test('ProvideInlineValues function should return all the vars in the python file using Assignment Expressions', async () => {
335347
customRequestStub.withArgs('variables', sinon.match.any).resolves({
336348
variables: [
337349
{
@@ -502,4 +514,16 @@ suite('Debugging - pythonInlineProvider', () => {
502514
];
503515
expect(result).to.deep.equal(expected);
504516
});
517+
518+
test("Provider should return empty array if 'showPythonInlineValues' is false", async () => {
519+
getConfigurationStub.withArgs('debugpy').returns(createMoqConfiguration(false));
520+
const file = path.join(WS_ROOT, 'pythonFiles', 'testAssignmentExp.py');
521+
let document = await workspace.openTextDocument(file);
522+
const viewPort = new Range(0, 0, 6, 0);
523+
const context = { frameId: 0, stoppedLocation: new Range(3, 1, 3, 1) } as InlineValueContext;
524+
const inlineValueProvider = new PythonInlineValueProvider();
525+
526+
const result = await inlineValueProvider.provideInlineValues(document, viewPort, context);
527+
expect(result).to.deep.equal([]);
528+
});
505529
});

0 commit comments

Comments
 (0)