Skip to content

Commit 73b1b9d

Browse files
committed
tests for pep484 and pep526
1 parent 8b1c35d commit 73b1b9d

File tree

6 files changed

+201
-549
lines changed

6 files changed

+201
-549
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
// Note: This example test is leveraging the Mocha test framework.
3+
// Please refer to their documentation on https://mochajs.org/ for help.
4+
5+
6+
// Place this right on top
7+
import { initialize, closeActiveWindows, setPythonExecutable } from '../initialize';
8+
// The module 'assert' provides assertion methods from node
9+
import * as assert from 'assert';
10+
// You can import and use all API from the 'vscode' module
11+
// as well as import your extension to test it
12+
import * as vscode from 'vscode';
13+
import * as path from 'path';
14+
import * as settings from '../../client/common/configSettings';
15+
import { execPythonFile } from '../../client/common/utils';
16+
import { createDeferred } from '../../client/common/helpers';
17+
18+
let pythonSettings = settings.PythonSettings.getInstance();
19+
let disposable: vscode.Disposable;
20+
21+
let autoCompPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'autocomp');
22+
const filePep484 = path.join(autoCompPath, 'pep484.py');
23+
24+
suite('Autocomplete PEP 484', () => {
25+
const isPython3Deferred = createDeferred<boolean>();
26+
const isPython3 = isPython3Deferred.promise;
27+
suiteSetup(async () => {
28+
disposable = setPythonExecutable(pythonSettings);
29+
await initialize();
30+
let version = await execPythonFile(pythonSettings.pythonPath, ['--version'], __dirname, true);
31+
isPython3Deferred.resolve(version.indexOf('3.') >= 0);
32+
});
33+
suiteTeardown(done => {
34+
disposable.dispose();
35+
closeActiveWindows().then(() => done(), () => done());
36+
});
37+
teardown(done => {
38+
closeActiveWindows().then(() => done(), () => done());
39+
});
40+
41+
test('argument', async () => {
42+
if (!await isPython3) {
43+
return;
44+
}
45+
let textDocument = await vscode.workspace.openTextDocument(filePep484);
46+
await vscode.window.showTextDocument(textDocument);
47+
assert(vscode.window.activeTextEditor, 'No active editor');
48+
const position = new vscode.Position(2, 27);
49+
let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
50+
assert.notEqual(list.items.filter(item => item.label === 'capitalize').length, 0, 'capitalize not found');
51+
assert.notEqual(list.items.filter(item => item.label === 'upper').length, 0, 'upper not found');
52+
assert.notEqual(list.items.filter(item => item.label === 'lower').length, 0, 'lower not found');
53+
});
54+
55+
test('return value', async () => {
56+
if (!await isPython3) {
57+
return;
58+
}
59+
let textDocument = await vscode.workspace.openTextDocument(filePep484);
60+
await vscode.window.showTextDocument(textDocument);
61+
assert(vscode.window.activeTextEditor, 'No active editor');
62+
const position = new vscode.Position(8, 6);
63+
let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
64+
assert.notEqual(list.items.filter(item => item.label === 'bit_length').length, 0, 'bit_length not found');
65+
assert.notEqual(list.items.filter(item => item.label === 'from_bytes').length, 0, 'from_bytes not found');
66+
});
67+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
// Note: This example test is leveraging the Mocha test framework.
3+
// Please refer to their documentation on https://mochajs.org/ for help.
4+
5+
6+
// Place this right on top
7+
import { initialize, closeActiveWindows, setPythonExecutable } from '../initialize';
8+
// The module 'assert' provides assertion methods from node
9+
import * as assert from 'assert';
10+
// You can import and use all API from the 'vscode' module
11+
// as well as import your extension to test it
12+
import * as vscode from 'vscode';
13+
import * as path from 'path';
14+
import * as settings from '../../client/common/configSettings';
15+
import { execPythonFile } from '../../client/common/utils';
16+
import { createDeferred } from '../../client/common/helpers';
17+
18+
let pythonSettings = settings.PythonSettings.getInstance();
19+
let disposable: vscode.Disposable;
20+
21+
let autoCompPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'autocomp');
22+
const filePep526 = path.join(autoCompPath, 'pep526.py');
23+
24+
suite('Autocomplete PEP 526', () => {
25+
const isPython3Deferred = createDeferred<boolean>();
26+
const isPython3 = isPython3Deferred.promise;
27+
suiteSetup(async () => {
28+
disposable = setPythonExecutable(pythonSettings);
29+
await initialize();
30+
let version = await execPythonFile(pythonSettings.pythonPath, ['--version'], __dirname, true);
31+
isPython3Deferred.resolve(version.indexOf('3.') >= 0);
32+
});
33+
suiteTeardown(done => {
34+
disposable.dispose();
35+
closeActiveWindows().then(() => done(), () => done());
36+
});
37+
teardown(done => {
38+
closeActiveWindows().then(() => done(), () => done());
39+
});
40+
41+
test('variable', async () => {
42+
if (!await isPython3) {
43+
return;
44+
}
45+
let textDocument = await vscode.workspace.openTextDocument(filePep526);
46+
await vscode.window.showTextDocument(textDocument);
47+
assert(vscode.window.activeTextEditor, 'No active editor');
48+
const position = new vscode.Position(3, 8);
49+
let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
50+
assert.notEqual(list.items.filter(item => item.label === 'capitalize').length, 0, 'capitalize not found');
51+
assert.notEqual(list.items.filter(item => item.label === 'upper').length, 0, 'upper not found');
52+
assert.notEqual(list.items.filter(item => item.label === 'lower').length, 0, 'lower not found');
53+
});
54+
});

0 commit comments

Comments
 (0)