Skip to content

Commit 50318e4

Browse files
Add unit test for class type
1 parent 93e2d59 commit 50318e4

File tree

2 files changed

+94
-7
lines changed

2 files changed

+94
-7
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Person:
2+
def __init__(self, name, age):
3+
self.name = name
4+
self.age = age
5+
6+
def greet(self):
7+
return f"Hello, my name is {self.name} and I a {self.age} years old."
8+
9+
person1 = Person("John Doe", 30)
10+
person1.greet()

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

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ suite('Debugging - pythonInlineProvider', () => {
2222
setup(() => {
2323
customRequestStub = sinon.stub(vscodeapi, 'customRequest');
2424
customRequestStub.withArgs('scopes', sinon.match.any).resolves({ scopes: [{ variablesReference: 0 }] });
25+
});
26+
27+
teardown(async () => {
28+
sinon.restore();
29+
});
30+
31+
test('ProvideInlineValues function should return all the vars in the python file', async () => {
2532
customRequestStub.withArgs('variables', sinon.match.any).resolves({
2633
variables: [
2734
{
@@ -71,13 +78,6 @@ suite('Debugging - pythonInlineProvider', () => {
7178
},
7279
],
7380
});
74-
});
75-
76-
teardown(async () => {
77-
sinon.restore();
78-
});
79-
80-
test('ProvideInlineValues function should return all the vars in the python file', async () => {
8181
const file = path.join(WS_ROOT, 'pythonFiles', 'testVarTypes.py');
8282
let document = await workspace.openTextDocument(file);
8383
const inlineValueProvider = new PythonInlineValueProvider();
@@ -188,4 +188,81 @@ suite('Debugging - pythonInlineProvider', () => {
188188
];
189189
expect(result).to.deep.equal(expected);
190190
});
191+
192+
test('ProvideInlineValues function should return all the vars in the python file with class variables', async () => {
193+
customRequestStub.withArgs('variables', sinon.match.any).resolves({
194+
variables: [
195+
{
196+
name: 'self',
197+
value: '<__main__.Person object at 0x10b223310>',
198+
type: 'Person',
199+
evaluateName: 'self',
200+
variablesReference: 5,
201+
},
202+
],
203+
});
204+
const file = path.join(WS_ROOT, 'pythonFiles', 'testClassVarType.py');
205+
let document = await workspace.openTextDocument(file);
206+
const inlineValueProvider = new PythonInlineValueProvider();
207+
208+
const viewPort = new Range(0, 0, 10, 0);
209+
const context = { frameId: 0, stoppedLocation: new Range(6, 1, 6, 1) } as InlineValueContext;
210+
211+
const result = await inlineValueProvider.provideInlineValues(document, viewPort, context);
212+
const expected = [
213+
{
214+
range: {
215+
c: {
216+
c: 2,
217+
e: 8,
218+
},
219+
e: {
220+
c: 2,
221+
e: 17,
222+
},
223+
},
224+
expression: 'self.name',
225+
},
226+
{
227+
range: {
228+
c: {
229+
c: 3,
230+
e: 8,
231+
},
232+
e: {
233+
c: 3,
234+
e: 16,
235+
},
236+
},
237+
expression: 'self.age',
238+
},
239+
{
240+
range: {
241+
c: {
242+
c: 6,
243+
e: 18,
244+
},
245+
e: {
246+
c: 6,
247+
e: 27,
248+
},
249+
},
250+
expression: 'self.name',
251+
},
252+
{
253+
range: {
254+
c: {
255+
c: 6,
256+
e: 29,
257+
},
258+
e: {
259+
c: 6,
260+
e: 37,
261+
},
262+
},
263+
expression: 'self.age',
264+
},
265+
];
266+
expect(result).to.deep.equal(expected);
267+
});
191268
});

0 commit comments

Comments
 (0)