Skip to content

Commit c22951c

Browse files
committed
Fix language server smoke tests (#3497)
* Fix language server smoke tests
1 parent e00f85a commit c22951c

File tree

3 files changed

+54
-49
lines changed

3 files changed

+54
-49
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ script:
108108
- if [[ $AZURE_STORAGE_ACCOUNT && "$TRAVIS_BRANCH" == release* && "$TRAVIS_PULL_REQUEST" == "false" ]]; then
109109
npm run clean;
110110
vsce package;
111-
azure storage blob upload python*.vsix $AZURE_STORAGE_CONTAINER ms-python-$TRAVIS_BRANCH-insiders.vsix --account-name $AZURE_STORAGE_ACCOUNT --account-key $AZURE_STORAGE_ACCESS_KEY --quiet;
111+
azure storage blob upload python*.vsix $AZURE_STORAGE_CONTAINER ms-python-$TRAVIS_BRANCH-unbundled.vsix --account-name $AZURE_STORAGE_ACCOUNT --account-key $AZURE_STORAGE_ACCESS_KEY --quiet;
112112
npm run clean;
113113
npm run package;
114114
npx gulp clean:cleanExceptTests;

src/test/smoke/msLanguageServer.smoke.test.ts

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
// tslint:disable:max-func-body-length no-invalid-this no-any
77

88
import * as assert from 'assert';
9+
import { expect } from 'chai';
910
import * as fs from 'fs-extra';
1011
import * as glob from 'glob';
1112
import * as path from 'path';
1213
import * as vscode from 'vscode';
14+
import { waitForCondition } from '../common';
1315
import { EXTENSION_ROOT_DIR_FOR_TESTS, IS_SMOKE_TEST, SMOKE_TEST_EXTENSIONS_DIR } from '../constants';
14-
import { isWindows, noop } from '../core';
16+
import { noop, sleep } from '../core';
1517
import { closeActiveWindows, initialize, initializeTest } from '../initialize';
1618

17-
const decoratorsPath = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test', 'pythonFiles', 'definition', 'navigation');
18-
const fileDefinitions = path.join(decoratorsPath, 'definitions.py');
19-
const wksPath = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test', 'pythonFiles', 'exclusions');
20-
const fileOne = path.join(wksPath, 'one.py');
19+
const fileDefinitions = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'smokeTests', 'definitions.py');
2120

2221
suite('Smoke Test: Language Server', function () {
2322
// Large value to allow for LS to get downloaded.
@@ -79,54 +78,29 @@ suite('Smoke Test: Language Server', function () {
7978
// In test mode it awaits for the completion before trying
8079
// to fetch data for completion, hover.etc.
8180
await vscode.commands.executeCommand('vscode.executeCompletionItemProvider', textDocument.uri, new vscode.Position(0, 0));
82-
assert.equal(await isLanguageServerDownloaded(), true, 'Language Server not downloaded');
81+
await waitForCondition(isLanguageServerDownloaded, 30_000, 'Language Server not downloaded');
82+
// For for LS to get extracted.
83+
await sleep(10_000);
8384
return textDocument;
8485
}
8586

86-
const assertFile = (expectedLocation: string, location: vscode.Uri) => {
87-
let relLocation = vscode.workspace.asRelativePath(location);
88-
let expectedRelLocation = vscode.workspace.asRelativePath(expectedLocation);
89-
if (isWindows) {
90-
relLocation = relLocation.toUpperCase();
91-
expectedRelLocation = expectedRelLocation.toUpperCase();
92-
}
93-
assert.equal(expectedRelLocation, relLocation, 'Position is in wrong file');
94-
};
95-
96-
const assertRange = (expectedRange: vscode.Range, range: vscode.Range) => {
97-
const formatPosition = (position: vscode.Position) => {
98-
return `${position.line},${position.character}`;
99-
};
100-
assert.equal(formatPosition(expectedRange.start), formatPosition(range.start), 'Start position is incorrect');
101-
assert.equal(formatPosition(expectedRange.end), formatPosition(range.end), 'End position is incorrect');
102-
};
103-
10487
test('Definitions', async () => {
105-
const startPosition = new vscode.Position(2, 6);
106-
const expectedFiles = [fileDefinitions];
107-
const expectedRanges = [new vscode.Range(2, 4, 2, 16)];
88+
const startPosition = new vscode.Position(13, 6);
10889
const textDocument = await openFile(fileDefinitions);
109-
110-
const locations = await vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', textDocument.uri, startPosition);
111-
assert.equal(expectedFiles.length, locations!.length, 'Wrong number of results');
112-
113-
for (let i = 0; i < locations!.length; i += 1) {
114-
assertFile(expectedFiles[i], locations![i].uri);
115-
assertRange(expectedRanges[i], locations![i].range!);
90+
let tested = false;
91+
for (let i = 0; i < 5; i += 1) {
92+
const locations = await vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', textDocument.uri, startPosition);
93+
if (locations && locations.length > 0) {
94+
expect(locations![0].uri.fsPath).to.contain(path.basename(fileDefinitions));
95+
tested = true;
96+
break;
97+
} else {
98+
// Wait for LS to start.
99+
await sleep(5_000);
100+
}
101+
}
102+
if (!tested) {
103+
assert.fail('Failled to test definitions');
116104
}
117-
});
118-
119-
test('Exclude subfolder', async () => {
120-
await openFile(fileOne);
121-
const diag = vscode.languages.getDiagnostics();
122-
123-
const main = diag.filter(d => d[0].fsPath.indexOf('one.py') >= 0);
124-
assert.equal(main.length > 0, true);
125-
126-
const subdir1 = diag.filter(d => d[0].fsPath.indexOf('dir1file.py') >= 0);
127-
assert.equal(subdir1.length, 0);
128-
129-
const subdir2 = diag.filter(d => d[0].fsPath.indexOf('dir2file.py') >= 0);
130-
assert.equal(subdir2.length, 0);
131105
});
132106
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from contextlib import contextmanager
2+
3+
def my_decorator(fn):
4+
"""
5+
This is my decorator.
6+
"""
7+
def wrapper(*args, **kwargs):
8+
"""
9+
This is the wrapper.
10+
"""
11+
return 42
12+
return wrapper
13+
14+
@my_decorator
15+
def thing(arg):
16+
"""
17+
Thing which is decorated.
18+
"""
19+
pass
20+
21+
@contextmanager
22+
def my_context_manager():
23+
"""
24+
This is my context manager.
25+
"""
26+
print("before")
27+
yield
28+
print("after")
29+
30+
with my_context_manager():
31+
thing(19)

0 commit comments

Comments
 (0)