Skip to content

Commit fa16982

Browse files
committed
test fixes
1 parent 176c477 commit fa16982

3 files changed

Lines changed: 35 additions & 30 deletions

File tree

src/test/autocomplete/base.test.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
// Place this right on top
6-
import { initialize, PYTHON_PATH, closeActiveWindows } from '../initialize';
6+
import { initialize, PYTHON_PATH, closeActiveWindows, setPythonExecutable } from '../initialize';
77
// The module 'assert' provides assertion methods from node
88
import * as assert from 'assert';
99
import { EOL } from 'os';
@@ -12,8 +12,11 @@ import { EOL } from 'os';
1212
import * as vscode from 'vscode';
1313
import * as path from 'path';
1414
import * as settings from '../../client/common/configSettings';
15+
import { execPythonFile } from '../../client/common/utils';
16+
import { createDeferred } from '../../client/common/helpers';
1517

1618
let pythonSettings = settings.PythonSettings.getInstance();
19+
let disposable: vscode.Disposable;
1720
let autoCompPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'autocomp');
1821
const fileOne = path.join(autoCompPath, 'one.py');
1922
const fileImport = path.join(autoCompPath, 'imp.py');
@@ -24,11 +27,13 @@ const fileEncoding = path.join(autoCompPath, 'four.py');
2427
const fileEncodingUsed = path.join(autoCompPath, 'five.py');
2528

2629
suite('Autocomplete', () => {
27-
suiteSetup(done => {
28-
initialize().then(() => {
29-
pythonSettings.pythonPath = PYTHON_PATH;
30-
done();
31-
}, done);
30+
const isPython3Deferred = createDeferred<boolean>();
31+
const isPython3 = isPython3Deferred.promise;
32+
suiteSetup(async () => {
33+
disposable = setPythonExecutable(pythonSettings);
34+
await initialize();
35+
let version = await execPythonFile(pythonSettings.pythonPath, ['--version'], __dirname, true);
36+
isPython3Deferred.resolve(version.indexOf('3.') >= 0);
3237
});
3338

3439
suiteTeardown(done => {
@@ -78,6 +83,9 @@ suite('Autocomplete', () => {
7883

7984
// https://github.com/DonJayamanne/pythonVSCode/issues/265
8085
test('For "lambda"', async () => {
86+
if (!await isPython3) {
87+
return;
88+
}
8189
const textDocument = await vscode.workspace.openTextDocument(fileLambda);
8290
await vscode.window.showTextDocument(textDocument);
8391
const position = new vscode.Position(1, 19);

src/test/definitions/code.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ suite('Code Definition', () => {
110110
const position = new vscode.Position(13, 2);
111111
const def = await vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', textDocument.uri, position);
112112
assert.equal(def.length, 1, 'Definition length is incorrect');
113-
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '19,0', 'Start position is incorrect');
114-
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '26,42', 'End position is incorrect');
113+
if (!def[0].uri.fsPath.endsWith('operations.py')) {
114+
assert.fail(def[0].uri.fsPath, 'operations.py', 'Source of sudo is incorrect', 'file source');
115+
}
116+
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '1094,0', 'Start position is incorrect (3rd part operations.py could have changed)');
117+
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '1148,4', 'End position is incorrect (3rd part operations.py could have changed)');
115118
});
116119

117120
test('Go to function decorator', async () => {

src/test/definitions/hover.test.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -271,22 +271,15 @@ suite('Hover Definition', () => {
271271
}).then(def => {
272272
assert.equal(def.length, 1, 'Definition length is incorrect');
273273
assert.equal(def[0].contents.length, 1, 'Only expected one result');
274-
const expectedContent = '```python' + EOL +
275-
'Random' + EOL +
276-
'```' + EOL +
277-
'Random(self, x=None)' + EOL +
278-
EOL +
279-
'Random number generator base class used by bound module functions.' + EOL +
280-
EOL +
281-
"Used to instantiate instances of Random to get generators that don't" + EOL +
282-
'share state.' + EOL +
283-
EOL +
284-
'Class Random can also be subclassed if you want to use a different basic' + EOL +
285-
'generator of your own devising: in that case, override the following' + EOL + EOL +
286-
'`methods` random(), seed(), getstate(), and setstate().' + EOL + EOL +
287-
'Optionally, implement a getrandbits() method so that randrange()' + EOL +
288-
'can cover arbitrarily large ranges.';
289-
assert.equal(def[0].contents[0], expectedContent, 'Invalid content items');
274+
if (def[0].contents[0].toString().indexOf("```python") === -1) {
275+
assert.fail(def[0].contents[0].toString(), "", "First line is incorrect", "compare");
276+
}
277+
if (def[0].contents[0].toString().indexOf("Random number generator base class used by bound module functions.") === -1) {
278+
assert.fail(def[0].contents[0].toString(), "", "'Random number generator' message missing", "compare");
279+
}
280+
if (def[0].contents[0].toString().indexOf("Class Random can also be subclassed if you want to use a different basic") === -1) {
281+
assert.fail(def[0].contents[0].toString(), "", "'Class Random message' missing", "compare");
282+
}
290283
}).then(done, done);
291284
});
292285

@@ -297,11 +290,12 @@ suite('Hover Definition', () => {
297290
const def = await vscode.commands.executeCommand<vscode.Hover[]>('vscode.executeHoverProvider', textDocument.uri, position);
298291
assert.equal(def.length, 1, 'Definition length is incorrect');
299292
assert.equal(def[0].contents.length, 1, 'Only expected one result');
300-
const expectedContents = "```python" + EOL +
301-
"def capitalize()" + EOL +
302-
"```" + EOL + "S.capitalize() -> str" + EOL + EOL +
303-
"Return a capitalized version of S, i.e. make the first character" + EOL +
304-
"have upper case and the rest lower case.";
305-
assert.equal(def[0].contents[0], expectedContents, 'Invalid content items');
293+
if (def[0].contents[0].toString().indexOf("def capitalize") === -1) {
294+
assert.fail(def[0].contents[0].toString(), "", "'def capitalize' is missing", "compare");
295+
}
296+
if (def[0].contents[0].toString().indexOf("Return a capitalized version of S") === -1 &&
297+
def[0].contents[0].toString().indexOf("Return a copy of the string S with only its first character") === -1) {
298+
assert.fail(def[0].contents[0].toString(), "", "'Return a capitalized version of S/Return a copy of the string S with only its first character' message missing", "compare");
299+
}
306300
});
307301
});

0 commit comments

Comments
 (0)