Skip to content

Commit 75be488

Browse files
robodairDonJayamanne
authored andcommitted
Fix autocomplete & hover unit tests (#1012)
1 parent 635ce06 commit 75be488

3 files changed

Lines changed: 46 additions & 24 deletions

File tree

src/client/providers/jediHelpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export function extractSignatureAndDocumentation(definition: proxy.IAutoComplete
4949
}
5050

5151
export function highlightCode(docstring: string): string {
52-
// Add blank line
53-
docstring = EOL + EOL + docstring + EOL + EOL;
52+
// Add blank line before and after docstring
53+
docstring = EOL + docstring.trim() + EOL;
5454
// Section title -> heading level 2
5555
docstring = docstring.replace(/(.+\r?\n)[-=]+\r?\n/g, '## $1' + EOL);
5656
// Directives: '.. directive::' -> '**directive**'

src/test/extension.autocomplete.test.ts

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ suite('Hover Definition', () => {
235235
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '30,4', 'Start position is incorrect');
236236
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '30,11', 'End position is incorrect');
237237
assert.equal(def[0].contents.length, 1, 'Invalid content items');
238-
assert.equal(def[0].contents[0], '```python' + EOL + 'def method1()' + EOL + '```' + EOL + 'This is method1', 'function signature incorrect');
238+
assert.equal(def[0].contents[0], '```python' + EOL + 'def method1()' + EOL + '```' + EOL + EOL + 'This is method1' + EOL, 'function signature incorrect');
239239
}).then(done, done);
240240
});
241241

@@ -254,7 +254,7 @@ suite('Hover Definition', () => {
254254
assert.equal(def.length, 1, 'Definition length is incorrect');
255255
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '1,9', 'Start position is incorrect');
256256
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '1,12', 'End position is incorrect');
257-
assert.equal(def[0].contents[0], '```python' + EOL + 'def fun()' + EOL + '```' + EOL + 'This is fun', 'Invalid conents');
257+
assert.equal(def[0].contents[0], '```python' + EOL + 'def fun()' + EOL + '```' + EOL + EOL + 'This is fun' + EOL, 'Invalid conents');
258258
}).then(done, done);
259259
});
260260

@@ -273,9 +273,9 @@ suite('Hover Definition', () => {
273273
assert.equal(def.length, 1, 'Definition length is incorrect');
274274
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '25,4', 'Start position is incorrect');
275275
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '25,7', 'End position is incorrect');
276-
assert.equal(def[0].contents[0], '```python' + EOL + 'def bar()' + EOL + '```' + EOL +
276+
assert.equal(def[0].contents[0], '```python' + EOL + 'def bar()' + EOL + '```' + EOL + EOL +
277277
'说明 - keep this line, it works' + EOL + 'delete following line, it works' +
278-
EOL + '如果存在需要等待审批或正在执行的任务,将不刷新页面', 'Invalid conents');
278+
EOL + '如果存在需要等待审批或正在执行的任务,将不刷新页面' + EOL, 'Invalid conents');
279279
}).then(done, done);
280280
});
281281

@@ -296,9 +296,9 @@ suite('Hover Definition', () => {
296296
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '1,16', 'End position is incorrect');
297297
assert.equal(def[0].contents[0], '```python' + EOL +
298298
'def showMessage()' + EOL +
299-
'```' + EOL +
299+
'```' + EOL + EOL +
300300
'Кюм ут жэмпэр пошжим льаборэж, коммюны янтэрэсщэт нам ед, декта игнота ныморэ жят эи. ' + EOL +
301-
'Шэа декам экшырки эи, эи зыд эррэм докэндё, векж факэтэ пэрчыквюэрёж ку.', 'Invalid conents');
301+
'Шэа декам экшырки эи, эи зыд эррэм докэндё, векж факэтэ пэрчыквюэрёж ку.' + EOL, 'Invalid conents');
302302
}).then(done, done);
303303
});
304304

@@ -351,17 +351,19 @@ suite('Hover Definition', () => {
351351
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '11,18', 'End position is incorrect');
352352
let documentation = "```python" + EOL +
353353
"class Random(x=None)" + EOL +
354-
"```" + EOL +
354+
"```" + EOL + EOL +
355355
"Random number generator base class used by bound module functions." + EOL +
356356
"" + EOL +
357357
"Used to instantiate instances of Random to get generators that don't" + EOL +
358358
"share state." + EOL +
359359
"" + EOL +
360360
"Class Random can also be subclassed if you want to use a different basic" + EOL +
361361
"generator of your own devising: in that case, override the following" + EOL +
362-
"methods: random(), seed(), getstate(), and setstate()." + EOL +
362+
EOL +
363+
"`methods` random(), seed(), getstate(), and setstate()." + EOL +
364+
EOL +
363365
"Optionally, implement a getrandbits() method so that randrange()" + EOL +
364-
"can cover arbitrarily large ranges.";
366+
"can cover arbitrarily large ranges." + EOL;
365367

366368
assert.equal(def[0].contents[0], documentation, 'Invalid conents');
367369
}).then(done, done);
@@ -384,8 +386,9 @@ suite('Hover Definition', () => {
384386
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '12,12', 'End position is incorrect');
385387
assert.equal(def[0].contents[0], '```python' + EOL +
386388
'def randint(a, b)' + EOL +
387-
'```' + EOL +
388-
'Return random integer in range [a, b], including both end points.', 'Invalid conents');
389+
'```' + EOL + EOL +
390+
'Return random integer in range [a, b], including both end points.' + EOL,
391+
'Invalid conents');
389392
}).then(done, done);
390393
});
391394

@@ -406,8 +409,9 @@ suite('Hover Definition', () => {
406409
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '8,15', 'End position is incorrect');
407410
assert.equal(def[0].contents[0], '```python' + EOL +
408411
'def acos(x)' + EOL +
409-
'```' + EOL +
410-
'Return the arc cosine (measured in radians) of x.', 'Invalid conents');
412+
'```' + EOL + EOL +
413+
'Return the arc cosine (measured in radians) of x.' + EOL,
414+
'Invalid conents');
411415
}).then(done, done);
412416
});
413417

@@ -428,13 +432,14 @@ suite('Hover Definition', () => {
428432
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '14,15', 'End position is incorrect');
429433
assert.equal(def[0].contents[0], '```python' + EOL +
430434
'class Thread(group=None, target=None, name=None, args=(), kwargs=None, verbose=None)' + EOL +
431-
'```' + EOL +
435+
'```' + EOL + EOL +
432436
'Thread(self, group=None, target=None, name=None,' + EOL +
433437
'args=(), kwargs=None, verbose=None)' + EOL +
434438
'' + EOL +
435439
'A class that represents a thread of control.' + EOL +
436440
'' + EOL +
437-
'This class can be safely subclassed in a limited fashion.', 'Invalid content items');
441+
'This class can be safely subclassed in a limited fashion.'
442+
+ EOL, 'Invalid content items');
438443
}).then(done, done);
439444
});
440445

@@ -452,12 +457,29 @@ suite('Hover Definition', () => {
452457
}).then(def => {
453458
assert.equal(def.length, 1, 'Definition length is incorrect');
454459
assert.equal(def[0].contents.length, 1, 'Only expected one result');
455-
assert.ok(def[0].contents[0].toString().startsWith('```python' + EOL +
456-
'Random' + EOL +
457-
'```' + EOL +
458-
'Random(self, x=None)' + EOL +
459-
EOL +
460-
'Random number generator base class used by bound module functions.'), 'Invalid content items');
460+
assert.equal(def[0].contents[0],
461+
'```python' + EOL +
462+
'Random' + EOL +
463+
'```' + EOL + EOL +
464+
`Random(self, x=None)
465+
466+
Random number generator base class used by bound module functions.
467+
468+
Used to instantiate instances of Random to get generators that don't
469+
share state. Especially useful for multi-threaded programs, creating
470+
a different instance of Random for each thread, and using the jumpahead()
471+
method to ensure that the generated sequences seen by each thread don't
472+
overlap.
473+
474+
Class Random can also be subclassed if you want to use a different basic
475+
generator of your own devising: in that case, override the following
476+
477+
\`methods\` random(), seed(), getstate(), setstate() and jumpahead().
478+
479+
Optionally, implement a getrandbits() method so that randrange() can cover
480+
arbitrarily large ranges.
481+
`,
482+
'Invalid content items');
461483
}).then(done, done);
462484
});
463485
});

src/test/pythonFiles/autocomp/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ class Random(_random.Random):
13361336
13371337
Class Random can also be subclassed if you want to use a different basic
13381338
generator of your own devising: in that case, override the following
1339-
methods: random(), seed(), getstate(), and setstate().
1339+
methods: random(), seed(), getstate(), and setstate().
13401340
Optionally, implement a getrandbits() method so that randrange()
13411341
can cover arbitrarily large ranges.
13421342

0 commit comments

Comments
 (0)