Skip to content

Commit 3457c62

Browse files
authored
Fixed travis unit tests (#1308)
* update to use latest api * config changes for multiroot workspace * linting support with multi roots * multi root support for formatters * determine workspace root path * revert change * support multiple configs per workspace folder * modify formatters to use resource specific settings * modified installer to pass resource for workspace resolution * null test in installer * canges to config settings to support multiroot workspace * changes to code refactoring to support workspace symbols * oops * modified to settings are resolved using document uri * unit tests for multi root support * fix unittests for multiroot * exclude files * add new line * config changes for multiroot workspace * new lines and enabled multi root linter tests * fix sys variables * added unit test to resolve ${workspaceRoot} in settings.json * #1228 workspace symbols with multiroot support * fix test * added some data for workspace symbol tests * data for unit tests * fixed to add support for multit roots with unit tests * account for mutiroot files in sub directory * disable all but multiroot tests * fixed tests * fix tests * test where failing * properly determine root workspace * fix pytest unit test * delete files * add awaiter * use a path that works on multiple os * fixes * uncomment * invert * debug statements * use default workspace * reverted unwanted changes * oops * test unittests only * more logging * partial fixes to unit tests * run all tests * changes not to set paths for shebang tests * remove comments * update settings only if necessary * fix test * include files for tests * Fixed travis tests for multi root workspace symbols (#1306) * added logging * more logging * yay * fixed * more fixes * fix tests * removed logging * enable all tests * uncommented * Added brackets around print statements (for p3) * use resource when getting settings
1 parent 51103f1 commit 3457c62

File tree

68 files changed

+1022
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1022
-434
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ before_install: |
4848
pyenv install $PYTHON
4949
pyenv global $PYTHON
5050
fi
51+
export TRAVIS_PYTHON_PATH=`which python`
5152
install:
5253
- pip install --upgrade -r requirements.txt
5354
- npm install

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"outFiles": [
3434
"${workspaceRoot}/out/**/*.js"
3535
],
36-
"preLaunchTask": "npm"
36+
"preLaunchTask": "compile"
3737
},
3838
{
3939
"name": "Launch Extension as debugServer", // https://code.visualstudio.com/docs/extensions/example-debuggers
@@ -65,15 +65,15 @@
6565
"outFiles": [
6666
"${workspaceRoot}/out/**/*.js"
6767
],
68-
"preLaunchTask": "npm"
68+
"preLaunchTask": "compile"
6969
},
7070
{
7171
"name": "Launch Multiroot Tests",
7272
"type": "extensionHost",
7373
"request": "launch",
7474
"runtimeExecutable": "${execPath}",
7575
"args": [
76-
"${workspaceRoot}/src/test/multiRootWkspc/multi.code-workspace",
76+
"${workspaceRoot}/src/testMultiRootWkspc/multi.code-workspace",
7777
"--extensionDevelopmentPath=${workspaceRoot}",
7878
"--extensionTestsPath=${workspaceRoot}/out/test"
7979
],

src/client/debugger/configProviders/simpleProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class SimpleConfigurationProvider implements DebugConfigurationProvider {
5151
type: 'python',
5252
request: 'launch',
5353
stopOnEntry: true,
54-
pythonPath: PythonSettings.getInstance().pythonPath,
54+
pythonPath: PythonSettings.getInstance(workspaceFolder ? Uri.file(workspaceFolder) : undefined).pythonPath,
5555
program: defaultProgram,
5656
cwd: workspaceFolder,
5757
envFile,

src/client/providers/execInTerminalProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function execInTerminal(fileUri?: vscode.Uri) {
3333
const terminalShellSettings = vscode.workspace.getConfiguration('terminal.integrated.shell');
3434
const IS_POWERSHELL = /powershell/.test(terminalShellSettings.get<string>('windows'));
3535

36-
let pythonSettings = settings.PythonSettings.getInstance();
36+
let pythonSettings = settings.PythonSettings.getInstance(fileUri);
3737
let filePath: string;
3838

3939
let currentPythonPath = pythonSettings.pythonPath;

src/client/providers/shebangCodeLensProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class ShebangCodeLensProvider implements vscode.CodeLensProvider {
1515

1616
private async createShebangCodeLens(document: TextDocument) {
1717
const shebang = await ShebangCodeLensProvider.detectShebang(document);
18-
if (!shebang || shebang === settings.PythonSettings.getInstance().pythonPath) {
18+
if (!shebang || shebang === settings.PythonSettings.getInstance(document.uri).pythonPath) {
1919
return [];
2020
}
2121

src/client/unittests/common/baseTestManager.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as vscode from 'vscode';
44
import { resetTestResults, displayTestErrorMessage, storeDiscoveredTests } from './testUtils';
55
import { Installer, Product } from '../../common/installer';
66
import { isNotInstalledError } from '../../common/helpers';
7+
import { IPythonSettings, PythonSettings } from '../../common/configSettings';
78

89
export abstract class BaseTestManager {
910
private tests: Tests;
@@ -25,9 +26,11 @@ export abstract class BaseTestManager {
2526
this.cancellationTokenSource.cancel();
2627
}
2728
}
29+
protected readonly settings: IPythonSettings;
2830
constructor(private testProvider: string, private product: Product, protected rootDirectory: string, protected outputChannel: vscode.OutputChannel) {
2931
this._status = TestStatus.Unknown;
3032
this.installer = new Installer();
33+
this.settings = PythonSettings.getInstance(vscode.Uri.file(this.rootDirectory));
3134
}
3235
public reset() {
3336
this._status = TestStatus.Unknown;
@@ -179,4 +182,4 @@ export abstract class BaseTestManager {
179182
});
180183
}
181184
abstract runTestImpl(tests: Tests, testsToRun?: TestsToRun, runFailedTests?: boolean, debug?: boolean): Promise<any>;
182-
}
185+
}

src/client/unittests/common/debugLauncher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { PythonSettings } from '../../common/configSettings';
44
import { execPythonFile } from './../../common/utils';
55
import { createDeferred } from './../../common/helpers';
66

7-
const pythonSettings = PythonSettings.getInstance();
87
export function launchDebugger(rootDirectory: string, testArgs: string[], token?: CancellationToken, outChannel?: OutputChannel) {
8+
const pythonSettings = PythonSettings.getInstance(rootDirectory ? Uri.file(rootDirectory) : undefined);
99
const def = createDeferred<any>();
1010
const launchDef = createDeferred<any>();
1111
let outputChannelShown = false;

src/client/unittests/configuration.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import * as unittest from './unittest/testConfigurationManager';
99
import { getSubDirectories } from '../common/utils';
1010
import * as path from 'path';
1111

12-
const settings = PythonSettings.getInstance();
13-
1412
function promptToEnableAndConfigureTestFramework(outputChannel: vscode.OutputChannel, messageToDisplay: string = 'Select a test framework/tool to enable', enableOnly: boolean = false): Thenable<any> {
1513
const items = [{
1614
label: 'unittest',
@@ -76,8 +74,9 @@ function promptToEnableAndConfigureTestFramework(outputChannel: vscode.OutputCha
7674
// Cuz we don't want the test engine (in main.ts file - tests get discovered when config changes are detected)
7775
// to start discovering tests when tests haven't been configured properly
7876
function enableTest(): Thenable<any> {
77+
// TODO: Enable multi workspace root support
7978
const pythonConfig = vscode.workspace.getConfiguration('python');
80-
if (settings.unitTest.promptToConfigure) {
79+
if (pythonConfig.get('unitTest.promptToConfigure')) {
8180
return configMgr.enable();
8281
}
8382
return pythonConfig.update('unitTest.promptToConfigure', undefined).then(() => {
@@ -94,6 +93,8 @@ function promptToEnableAndConfigureTestFramework(outputChannel: vscode.OutputCha
9493
});
9594
}
9695
export function displayTestFrameworkError(outputChannel: vscode.OutputChannel): Thenable<any> {
96+
// TODO: Enable multi workspace root support
97+
const settings = PythonSettings.getInstance();
9798
let enabledCount = settings.unitTest.pyTestEnabled ? 1 : 0;
9899
enabledCount += settings.unitTest.nosetestsEnabled ? 1 : 0;
99100
enabledCount += settings.unitTest.unittestEnabled ? 1 : 0;
@@ -111,6 +112,7 @@ export function displayTestFrameworkError(outputChannel: vscode.OutputChannel):
111112
}
112113
}
113114
export function displayPromptToEnableTests(rootDir: string, outputChannel: vscode.OutputChannel): Thenable<any> {
115+
const settings = PythonSettings.getInstance(vscode.Uri.file(rootDir));
114116
if (settings.unitTest.pyTestEnabled ||
115117
settings.unitTest.nosetestsEnabled ||
116118
settings.unitTest.unittestEnabled) {
@@ -147,4 +149,4 @@ function checkIfHasTestDirs(rootDir: string): Promise<boolean> {
147149
return getSubDirectories(rootDir).then(subDirs => {
148150
return subDirs.map(dir => path.relative(rootDir, dir)).filter(dir => dir.match(/test/i)).length > 0;
149151
});
150-
}
152+
}

src/client/unittests/main.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ import {
1414
} from './common/contracts';
1515
import { resolveValueAsTestToRun, getDiscoveredTests } from './common/testUtils';
1616
import { BaseTestManager } from './common/baseTestManager';
17-
import { PythonSettings } from '../common/configSettings';
17+
import { PythonSettings, IUnitTestSettings } from '../common/configSettings';
1818
import { TestResultDisplay } from './display/main';
1919
import { TestDisplay } from './display/picker';
2020
import { activateCodeLenses } from './codeLenses/main';
2121
import { displayTestFrameworkError } from './configuration';
2222
import { PythonSymbolProvider } from '../providers/symbolProvider';
2323

24-
const settings = PythonSettings.getInstance();
2524
let testManager: BaseTestManager | undefined | null;
2625
let pyTestManager: pytest.TestManager | undefined | null;
2726
let unittestManager: unittest.TestManager | undefined | null;
@@ -32,6 +31,9 @@ let outChannel: vscode.OutputChannel;
3231
let onDidChange: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
3332

3433
export function activate(context: vscode.ExtensionContext, outputChannel: vscode.OutputChannel, symboldProvider: PythonSymbolProvider) {
34+
// TODO: Add multi workspace support
35+
const settings = PythonSettings.getInstance();
36+
uniTestSettingsString = JSON.stringify(settings.unitTest);
3537
context.subscriptions.push({ dispose: dispose });
3638
outChannel = outputChannel;
3739
let disposables = registerCommands();
@@ -51,6 +53,8 @@ export function activate(context: vscode.ExtensionContext, outputChannel: vscode
5153
}
5254

5355
function getTestWorkingDirectory() {
56+
// TODO: Add multi workspace support
57+
const settings = PythonSettings.getInstance();
5458
return settings.unitTest.cwd && settings.unitTest.cwd.length > 0 ? settings.unitTest.cwd : vscode.workspace.rootPath!;
5559
}
5660

@@ -184,9 +188,11 @@ function displayStopUI(message: string) {
184188
testDisplay = testDisplay ? testDisplay : new TestDisplay();
185189
testDisplay.displayStopTestUI(message);
186190
}
187-
let uniTestSettingsString = JSON.stringify(settings.unitTest);
191+
let uniTestSettingsString: string;
188192

189193
function onConfigChanged() {
194+
// TODO: Add multi workspace support
195+
const settings = PythonSettings.getInstance();
190196
// Possible that a test framework has been enabled or some settings have changed
191197
// Meaning we need to re-load the discovered tests (as something could have changed)
192198
const newSettings = JSON.stringify(settings.unitTest);
@@ -230,6 +236,7 @@ function onConfigChanged() {
230236
}
231237
function getTestRunner() {
232238
const rootDirectory = getTestWorkingDirectory();
239+
const settings = PythonSettings.getInstance(vscode.Uri.file(rootDirectory));
233240
if (settings.unitTest.nosetestsEnabled) {
234241
return nosetestManager = nosetestManager ? nosetestManager : new nosetests.TestManager(rootDirectory, outChannel);
235242
}
@@ -317,4 +324,4 @@ function runTestsImpl(arg?: vscode.Uri | TestsToRun | boolean | FlattenedTestFun
317324
});
318325

319326
testResultDisplay.DisplayProgressStatus(runPromise, debug);
320-
}
327+
}

src/client/unittests/nosetest/collector.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import * as os from 'os';
66
import { extractBetweenDelimiters, convertFileToPackage, flattenTestFiles } from '../common/testUtils';
77
import { CancellationToken } from 'vscode';
88
import { PythonSettings } from '../../common/configSettings';
9-
import { OutputChannel } from 'vscode';
9+
import { OutputChannel, Uri } from 'vscode';
1010

11-
const pythonSettings = PythonSettings.getInstance();
1211
const NOSE_WANT_FILE_PREFIX = 'nose.selector: DEBUG: wantFile ';
1312
const NOSE_WANT_FILE_SUFFIX = '.py? True';
1413
const NOSE_WANT_FILE_SUFFIX_WITHOUT_EXT = '? True';
@@ -78,7 +77,7 @@ export function discoverTests(rootDirectory: string, args: string[], token: Canc
7877
});
7978
}
8079

81-
return execPythonFile(pythonSettings.unitTest.nosetestPath, args.concat(['--collect-only', '-vvv']), rootDirectory, true)
80+
return execPythonFile(PythonSettings.getInstance(Uri.file(rootDirectory)).unitTest.nosetestPath, args.concat(['--collect-only', '-vvv']), rootDirectory, true)
8281
.then(data => {
8382
outChannel.appendLine(data);
8483
processOutput(data);

0 commit comments

Comments
 (0)