Skip to content

Commit 6c2b04c

Browse files
Add tests
1 parent 0ac91e7 commit 6c2b04c

File tree

3 files changed

+198
-1
lines changed

3 files changed

+198
-1
lines changed

src/extension/common/vscodeapi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ export function startDebugging(
131131

132132
export function customRequest(command: string, args?: any): any {
133133
return debug.activeDebugSession?.customRequest(command, args);
134-
}
134+
}

src/test/pythonFiles/testVarTypes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var1 = 5
2+
var2 = 7
3+
var3 = "hola"
4+
var4 = {"a": 1, "b": 2}
5+
var5 = [1, 2, 3]
6+
var6 =var1 + var2
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
import * as chaiAsPromised from 'chai-as-promised';
7+
import * as path from 'path';
8+
import * as sinon from 'sinon';
9+
import { use, expect } from 'chai';
10+
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../constants';
11+
import { PythonInlineValueProvider } from '../../../extension/debugger/inlineValue/pythonInlineValueProvider';
12+
import { workspace, Range, InlineValueContext, debug, TextDocument } from 'vscode';
13+
import * as vscodeapi from '../../../extension/common/vscodeapi';
14+
15+
use(chaiAsPromised);
16+
17+
const WS_ROOT = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test');
18+
19+
suite('Debugging - pythonInlineProvider', () => {
20+
let customRequestStub: sinon.SinonStub;
21+
22+
setup(() => {
23+
customRequestStub = sinon.stub(vscodeapi, 'customRequest');
24+
customRequestStub.withArgs('scopes', sinon.match.any).resolves({ scopes: [{ variablesReference: 0 }] });
25+
customRequestStub.withArgs('variables', sinon.match.any).resolves({
26+
variables: [
27+
{
28+
name: 'special variables',
29+
value: '',
30+
type: '',
31+
evaluateName: 'special variables',
32+
variablesReference: 10,
33+
},
34+
{
35+
name: 'var1',
36+
value: '5',
37+
type: 'int',
38+
evaluateName: 'var1',
39+
variablesReference: 0,
40+
},
41+
{
42+
name: 'var2',
43+
value: '7',
44+
type: 'int',
45+
evaluateName: 'var2',
46+
variablesReference: 0,
47+
},
48+
{
49+
name: 'var3',
50+
value: "'hola'",
51+
type: 'str',
52+
evaluateName: 'var3',
53+
variablesReference: 0,
54+
presentationHint: {
55+
attributes: ['rawString'],
56+
},
57+
},
58+
{
59+
name: 'var4',
60+
value: "{'a': 1, 'b': 2}",
61+
type: 'dict',
62+
evaluateName: 'var4',
63+
variablesReference: 8,
64+
},
65+
{
66+
name: 'var5',
67+
value: '[1, 2, 3]',
68+
type: 'list',
69+
evaluateName: 'var5',
70+
variablesReference: 9,
71+
},
72+
],
73+
});
74+
});
75+
76+
teardown(async () => {
77+
sinon.restore();
78+
});
79+
80+
test('ProvideInlineValues function should return all the vars in the python file', async () => {
81+
const file = path.join(WS_ROOT, 'pythonFiles', 'testVarTypes.py');
82+
let document = await workspace.openTextDocument(file);
83+
const inlineValueProvider = new PythonInlineValueProvider();
84+
85+
const viewPort = new Range(0, 0, 5, 17);
86+
const context = { frameId: 0, stoppedLocation: new Range(5, 1, 5, 1) } as InlineValueContext;
87+
88+
const result = await inlineValueProvider.provideInlineValues(document, viewPort, context);
89+
const expected = [
90+
{
91+
range: {
92+
c: {
93+
c: 0,
94+
e: 0,
95+
},
96+
e: {
97+
c: 0,
98+
e: 4,
99+
},
100+
},
101+
variableName: 'var1',
102+
caseSensitiveLookup: false,
103+
},
104+
{
105+
range: {
106+
c: {
107+
c: 1,
108+
e: 0,
109+
},
110+
e: {
111+
c: 1,
112+
e: 4,
113+
},
114+
},
115+
variableName: 'var2',
116+
caseSensitiveLookup: false,
117+
},
118+
{
119+
range: {
120+
c: {
121+
c: 2,
122+
e: 0,
123+
},
124+
e: {
125+
c: 2,
126+
e: 4,
127+
},
128+
},
129+
variableName: 'var3',
130+
caseSensitiveLookup: false,
131+
},
132+
{
133+
range: {
134+
c: {
135+
c: 3,
136+
e: 0,
137+
},
138+
e: {
139+
c: 3,
140+
e: 4,
141+
},
142+
},
143+
variableName: 'var4',
144+
caseSensitiveLookup: false,
145+
},
146+
{
147+
range: {
148+
c: {
149+
c: 4,
150+
e: 0,
151+
},
152+
e: {
153+
c: 4,
154+
e: 4,
155+
},
156+
},
157+
variableName: 'var5',
158+
caseSensitiveLookup: false,
159+
},
160+
{
161+
range: {
162+
c: {
163+
c: 5,
164+
e: 6,
165+
},
166+
e: {
167+
c: 5,
168+
e: 10,
169+
},
170+
},
171+
variableName: 'var1',
172+
caseSensitiveLookup: false,
173+
},
174+
{
175+
range: {
176+
c: {
177+
c: 5,
178+
e: 13,
179+
},
180+
e: {
181+
c: 5,
182+
e: 17,
183+
},
184+
},
185+
variableName: 'var2',
186+
caseSensitiveLookup: false,
187+
},
188+
];
189+
expect(result).to.deep.equal(expected);
190+
});
191+
});

0 commit comments

Comments
 (0)