forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpep526.test.ts
More file actions
101 lines (90 loc) · 5.38 KB
/
Copy pathpep526.test.ts
File metadata and controls
101 lines (90 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Note: This example test is leveraging the Mocha test framework.
// Please refer to their documentation on https://mochajs.org/ for help.
// The module 'assert' provides assertion methods from node
import * as assert from 'assert';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
import * as path from 'path';
import * as settings from '../../client/common/configSettings';
import { execPythonFile } from '../../client/common/utils';
import { initialize, closeActiveWindows, initializeTest } from '../initialize';
import { PythonSettings } from '../../client/common/configSettings';
import { rootWorkspaceUri } from '../common';
const autoCompPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'autocomp');
const filePep526 = path.join(autoCompPath, 'pep526.py');
suite('Autocomplete PEP 526', () => {
let isPython3: Promise<boolean>;
suiteSetup(async () => {
await initialize();
const version = await execPythonFile(rootWorkspaceUri, PythonSettings.getInstance(rootWorkspaceUri).pythonPath, ['--version'], __dirname, true);
isPython3 = Promise.resolve(version.indexOf('3.') >= 0);
});
setup(() => initializeTest());
suiteTeardown(() => closeActiveWindows());
teardown(() => closeActiveWindows());
test('variable (abc:str)', async () => {
if (!await isPython3) {
return;
}
let textDocument = await vscode.workspace.openTextDocument(filePep526);
await vscode.window.showTextDocument(textDocument);
assert(vscode.window.activeTextEditor, 'No active editor');
const position = new vscode.Position(9, 8);
let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'capitalize').length, 0, 'capitalize not found');
assert.notEqual(list.items.filter(item => item.label === 'upper').length, 0, 'upper not found');
assert.notEqual(list.items.filter(item => item.label === 'lower').length, 0, 'lower not found');
});
test('variable (abc: str = "")', async () => {
if (!await isPython3) {
return;
}
let textDocument = await vscode.workspace.openTextDocument(filePep526);
await vscode.window.showTextDocument(textDocument);
assert(vscode.window.activeTextEditor, 'No active editor');
const position = new vscode.Position(8, 14);
let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'capitalize').length, 0, 'capitalize not found');
assert.notEqual(list.items.filter(item => item.label === 'upper').length, 0, 'upper not found');
assert.notEqual(list.items.filter(item => item.label === 'lower').length, 0, 'lower not found');
});
test('variable (abc = UNKNOWN # type: str)', async () => {
if (!await isPython3) {
return;
}
let textDocument = await vscode.workspace.openTextDocument(filePep526);
await vscode.window.showTextDocument(textDocument);
assert(vscode.window.activeTextEditor, 'No active editor');
const position = new vscode.Position(7, 14);
let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'capitalize').length, 0, 'capitalize not found');
assert.notEqual(list.items.filter(item => item.label === 'upper').length, 0, 'upper not found');
assert.notEqual(list.items.filter(item => item.label === 'lower').length, 0, 'lower not found');
});
test('class methods', async () => {
if (!await isPython3) {
return;
}
let textDocument = await vscode.workspace.openTextDocument(filePep526);
await vscode.window.showTextDocument(textDocument);
assert(vscode.window.activeTextEditor, 'No active editor');
let position = new vscode.Position(20, 4);
let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'a').length, 0, 'method a not found');
position = new vscode.Position(21, 4);
list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'b').length, 0, 'method b not found');
});
test('class method types', async () => {
if (!await isPython3) {
return;
}
let textDocument = await vscode.workspace.openTextDocument(filePep526);
await vscode.window.showTextDocument(textDocument);
assert(vscode.window.activeTextEditor, 'No active editor');
const position = new vscode.Position(21, 6);
const list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'bit_length').length, 0, 'bit_length not found');
});
});