forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.test.ts
More file actions
176 lines (160 loc) · 10.6 KB
/
Copy pathbase.test.ts
File metadata and controls
176 lines (160 loc) · 10.6 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// 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';
import { EOL } from 'os';
// 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 { initialize, closeActiveWindows, initializeTest } from '../initialize';
import { execPythonFile } from '../../client/common/utils';
import { PythonSettings } from '../../client/common/configSettings';
import { rootWorkspaceUri } from '../common';
const autoCompPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'autocomp');
const fileOne = path.join(autoCompPath, 'one.py');
const fileImport = path.join(autoCompPath, 'imp.py');
const fileDoc = path.join(autoCompPath, 'doc.py');
const fileLambda = path.join(autoCompPath, 'lamb.py');
const fileDecorator = path.join(autoCompPath, 'deco.py');
const fileEncoding = path.join(autoCompPath, 'four.py');
const fileEncodingUsed = path.join(autoCompPath, 'five.py');
suite('Autocomplete', () => {
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('For "sys."', done => {
let textEditor: vscode.TextEditor;
let textDocument: vscode.TextDocument;
vscode.workspace.openTextDocument(fileOne).then(document => {
textDocument = document;
return vscode.window.showTextDocument(textDocument);
}).then(editor => {
assert(vscode.window.activeTextEditor, 'No active editor');
textEditor = editor;
const position = new vscode.Position(3, 10);
return vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
}).then(list => {
assert.equal(list.items.filter(item => item.label === 'api_version').length, 1, 'api_version not found');
}).then(done, done);
});
// https://github.com/DonJayamanne/pythonVSCode/issues/975
test('For "import *"', async () => {
const textDocument = await vscode.workspace.openTextDocument(fileImport);
await vscode.window.showTextDocument(textDocument);
const position = new vscode.Position(1, 4);
const list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.equal(list.items.filter(item => item.label === 'fstat').length, 1, 'fstat not found');
});
// https://github.com/DonJayamanne/pythonVSCode/issues/898
test('For "f.readlines()"', async () => {
const textDocument = await vscode.workspace.openTextDocument(fileDoc);
await vscode.window.showTextDocument(textDocument);
const position = new vscode.Position(5, 27);
const list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
// These are not known to work, jedi issue
// assert.equal(list.items.filter(item => item.label === 'capitalize').length, 1, 'capitalize not found (known not to work, Jedi issue)');
// assert.notEqual(list.items.filter(item => item.label === 'upper').length, 1, 'upper not found');
// assert.notEqual(list.items.filter(item => item.label === 'lower').length, 1, 'lower not found');
});
// https://github.com/DonJayamanne/pythonVSCode/issues/265
test('For "lambda"', async () => {
if (!await isPython3) {
return;
}
const textDocument = await vscode.workspace.openTextDocument(fileLambda);
await vscode.window.showTextDocument(textDocument);
const position = new vscode.Position(1, 19);
const list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'append').length, 0, 'append not found');
assert.notEqual(list.items.filter(item => item.label === 'clear').length, 0, 'clear not found');
assert.notEqual(list.items.filter(item => item.label === 'count').length, 0, 'cound not found');
});
// https://github.com/DonJayamanne/pythonVSCode/issues/630
test('For "abc.decorators"', async () => {
const textDocument = await vscode.workspace.openTextDocument(fileDecorator);
await vscode.window.showTextDocument(textDocument);
let position = new vscode.Position(3, 9);
let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'ABCMeta').length, 0, 'ABCMeta not found');
assert.notEqual(list.items.filter(item => item.label === 'abstractmethod').length, 0, 'abstractmethod not found');
position = new vscode.Position(4, 9);
list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'ABCMeta').length, 0, 'ABCMeta not found');
assert.notEqual(list.items.filter(item => item.label === 'abstractmethod').length, 0, 'abstractmethod not found');
position = new vscode.Position(2, 30);
list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'ABCMeta').length, 0, 'ABCMeta not found');
assert.notEqual(list.items.filter(item => item.label === 'abstractmethod').length, 0, 'abstractmethod not found');
});
// https://github.com/DonJayamanne/pythonVSCode/issues/727
// https://github.com/DonJayamanne/pythonVSCode/issues/746
// https://github.com/davidhalter/jedi/issues/859
test('For "time.slee"', async () => {
const textDocument = await vscode.workspace.openTextDocument(fileDoc);
await vscode.window.showTextDocument(textDocument);
const position = new vscode.Position(10, 9);
const list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'sleep').length, 0, 'sleep not found');
assert.notEqual(list.items.filter(item => item.documentation.toString().startsWith("Delay execution for a given number of seconds. The argument may be")).length, 0, 'Documentation incorrect');
});
test('For custom class', done => {
let textEditor: vscode.TextEditor;
let textDocument: vscode.TextDocument;
vscode.workspace.openTextDocument(fileOne).then(document => {
textDocument = document;
return vscode.window.showTextDocument(textDocument);
}).then(editor => {
assert(vscode.window.activeTextEditor, 'No active editor');
textEditor = editor;
const position = new vscode.Position(30, 4);
return vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
}).then(list => {
assert.notEqual(list.items.filter(item => item.label === 'method1').length, 0, 'method1 not found');
assert.notEqual(list.items.filter(item => item.label === 'method2').length, 0, 'method2 not found');
}).then(done, done);
});
test('With Unicode Characters', done => {
let textEditor: vscode.TextEditor;
let textDocument: vscode.TextDocument;
vscode.workspace.openTextDocument(fileEncoding).then(document => {
textDocument = document;
return vscode.window.showTextDocument(textDocument);
}).then(editor => {
assert(vscode.window.activeTextEditor, 'No active editor');
textEditor = editor;
const position = new vscode.Position(25, 4);
return vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
}).then(list => {
assert.equal(list.items.filter(item => item.label === 'bar').length, 1, 'bar not found');
const documentation = `说明 - keep this line, it works${EOL}delete following line, it works${EOL}如果存在需要等待审批或正在执行的任务,将不刷新页面`;
assert.equal(list.items.filter(item => item.label === 'bar')[0].documentation, documentation, 'unicode documentation is incorrect');
}).then(done, done);
});
test('Across files With Unicode Characters', done => {
let textEditor: vscode.TextEditor;
let textDocument: vscode.TextDocument;
vscode.workspace.openTextDocument(fileEncodingUsed).then(document => {
textDocument = document;
return vscode.window.showTextDocument(textDocument);
}).then(editor => {
assert(vscode.window.activeTextEditor, 'No active editor');
textEditor = editor;
const position = new vscode.Position(1, 5);
return vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
}).then(list => {
assert.equal(list.items.filter(item => item.label === 'Foo').length, 1, 'Foo not found');
assert.equal(list.items.filter(item => item.label === 'Foo')[0].documentation, '说明', 'Foo unicode documentation is incorrect');
assert.equal(list.items.filter(item => item.label === 'showMessage').length, 1, 'showMessage not found');
const documentation = `Кюм ут жэмпэр пошжим льаборэж, коммюны янтэрэсщэт нам ед, декта игнота ныморэ жят эи. ${EOL}Шэа декам экшырки эи, эи зыд эррэм докэндё, векж факэтэ пэрчыквюэрёж ку.`;
assert.equal(list.items.filter(item => item.label === 'showMessage')[0].documentation, documentation, 'showMessage unicode documentation is incorrect');
}).then(done, done);
});
});