Skip to content

Commit

Permalink
Fixed travis unit tests (#1308)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
DonJayamanne authored Oct 14, 2017
1 parent 51103f1 commit 3457c62
Show file tree
Hide file tree
Showing 68 changed files with 1,022 additions and 434 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ before_install: |
pyenv install $PYTHON
pyenv global $PYTHON
fi
export TRAVIS_PYTHON_PATH=`which python`
install:
- pip install --upgrade -r requirements.txt
- npm install
Expand Down
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"outFiles": [
"${workspaceRoot}/out/**/*.js"
],
"preLaunchTask": "npm"
"preLaunchTask": "compile"
},
{
"name": "Launch Extension as debugServer", // https://code.visualstudio.com/docs/extensions/example-debuggers
Expand Down Expand Up @@ -65,15 +65,15 @@
"outFiles": [
"${workspaceRoot}/out/**/*.js"
],
"preLaunchTask": "npm"
"preLaunchTask": "compile"
},
{
"name": "Launch Multiroot Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"${workspaceRoot}/src/test/multiRootWkspc/multi.code-workspace",
"${workspaceRoot}/src/testMultiRootWkspc/multi.code-workspace",
"--extensionDevelopmentPath=${workspaceRoot}",
"--extensionTestsPath=${workspaceRoot}/out/test"
],
Expand Down
2 changes: 1 addition & 1 deletion src/client/debugger/configProviders/simpleProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class SimpleConfigurationProvider implements DebugConfigurationProvider {
type: 'python',
request: 'launch',
stopOnEntry: true,
pythonPath: PythonSettings.getInstance().pythonPath,
pythonPath: PythonSettings.getInstance(workspaceFolder ? Uri.file(workspaceFolder) : undefined).pythonPath,
program: defaultProgram,
cwd: workspaceFolder,
envFile,
Expand Down
2 changes: 1 addition & 1 deletion src/client/providers/execInTerminalProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function execInTerminal(fileUri?: vscode.Uri) {
const terminalShellSettings = vscode.workspace.getConfiguration('terminal.integrated.shell');
const IS_POWERSHELL = /powershell/.test(terminalShellSettings.get<string>('windows'));

let pythonSettings = settings.PythonSettings.getInstance();
let pythonSettings = settings.PythonSettings.getInstance(fileUri);
let filePath: string;

let currentPythonPath = pythonSettings.pythonPath;
Expand Down
2 changes: 1 addition & 1 deletion src/client/providers/shebangCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ShebangCodeLensProvider implements vscode.CodeLensProvider {

private async createShebangCodeLens(document: TextDocument) {
const shebang = await ShebangCodeLensProvider.detectShebang(document);
if (!shebang || shebang === settings.PythonSettings.getInstance().pythonPath) {
if (!shebang || shebang === settings.PythonSettings.getInstance(document.uri).pythonPath) {
return [];
}

Expand Down
5 changes: 4 additions & 1 deletion src/client/unittests/common/baseTestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as vscode from 'vscode';
import { resetTestResults, displayTestErrorMessage, storeDiscoveredTests } from './testUtils';
import { Installer, Product } from '../../common/installer';
import { isNotInstalledError } from '../../common/helpers';
import { IPythonSettings, PythonSettings } from '../../common/configSettings';

export abstract class BaseTestManager {
private tests: Tests;
Expand All @@ -25,9 +26,11 @@ export abstract class BaseTestManager {
this.cancellationTokenSource.cancel();
}
}
protected readonly settings: IPythonSettings;
constructor(private testProvider: string, private product: Product, protected rootDirectory: string, protected outputChannel: vscode.OutputChannel) {
this._status = TestStatus.Unknown;
this.installer = new Installer();
this.settings = PythonSettings.getInstance(vscode.Uri.file(this.rootDirectory));
}
public reset() {
this._status = TestStatus.Unknown;
Expand Down Expand Up @@ -179,4 +182,4 @@ export abstract class BaseTestManager {
});
}
abstract runTestImpl(tests: Tests, testsToRun?: TestsToRun, runFailedTests?: boolean, debug?: boolean): Promise<any>;
}
}
2 changes: 1 addition & 1 deletion src/client/unittests/common/debugLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { PythonSettings } from '../../common/configSettings';
import { execPythonFile } from './../../common/utils';
import { createDeferred } from './../../common/helpers';

const pythonSettings = PythonSettings.getInstance();
export function launchDebugger(rootDirectory: string, testArgs: string[], token?: CancellationToken, outChannel?: OutputChannel) {
const pythonSettings = PythonSettings.getInstance(rootDirectory ? Uri.file(rootDirectory) : undefined);
const def = createDeferred<any>();
const launchDef = createDeferred<any>();
let outputChannelShown = false;
Expand Down
10 changes: 6 additions & 4 deletions src/client/unittests/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import * as unittest from './unittest/testConfigurationManager';
import { getSubDirectories } from '../common/utils';
import * as path from 'path';

const settings = PythonSettings.getInstance();

function promptToEnableAndConfigureTestFramework(outputChannel: vscode.OutputChannel, messageToDisplay: string = 'Select a test framework/tool to enable', enableOnly: boolean = false): Thenable<any> {
const items = [{
label: 'unittest',
Expand Down Expand Up @@ -76,8 +74,9 @@ function promptToEnableAndConfigureTestFramework(outputChannel: vscode.OutputCha
// Cuz we don't want the test engine (in main.ts file - tests get discovered when config changes are detected)
// to start discovering tests when tests haven't been configured properly
function enableTest(): Thenable<any> {
// TODO: Enable multi workspace root support
const pythonConfig = vscode.workspace.getConfiguration('python');
if (settings.unitTest.promptToConfigure) {
if (pythonConfig.get('unitTest.promptToConfigure')) {
return configMgr.enable();
}
return pythonConfig.update('unitTest.promptToConfigure', undefined).then(() => {
Expand All @@ -94,6 +93,8 @@ function promptToEnableAndConfigureTestFramework(outputChannel: vscode.OutputCha
});
}
export function displayTestFrameworkError(outputChannel: vscode.OutputChannel): Thenable<any> {
// TODO: Enable multi workspace root support
const settings = PythonSettings.getInstance();
let enabledCount = settings.unitTest.pyTestEnabled ? 1 : 0;
enabledCount += settings.unitTest.nosetestsEnabled ? 1 : 0;
enabledCount += settings.unitTest.unittestEnabled ? 1 : 0;
Expand All @@ -111,6 +112,7 @@ export function displayTestFrameworkError(outputChannel: vscode.OutputChannel):
}
}
export function displayPromptToEnableTests(rootDir: string, outputChannel: vscode.OutputChannel): Thenable<any> {
const settings = PythonSettings.getInstance(vscode.Uri.file(rootDir));
if (settings.unitTest.pyTestEnabled ||
settings.unitTest.nosetestsEnabled ||
settings.unitTest.unittestEnabled) {
Expand Down Expand Up @@ -147,4 +149,4 @@ function checkIfHasTestDirs(rootDir: string): Promise<boolean> {
return getSubDirectories(rootDir).then(subDirs => {
return subDirs.map(dir => path.relative(rootDir, dir)).filter(dir => dir.match(/test/i)).length > 0;
});
}
}
15 changes: 11 additions & 4 deletions src/client/unittests/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import {
} from './common/contracts';
import { resolveValueAsTestToRun, getDiscoveredTests } from './common/testUtils';
import { BaseTestManager } from './common/baseTestManager';
import { PythonSettings } from '../common/configSettings';
import { PythonSettings, IUnitTestSettings } from '../common/configSettings';
import { TestResultDisplay } from './display/main';
import { TestDisplay } from './display/picker';
import { activateCodeLenses } from './codeLenses/main';
import { displayTestFrameworkError } from './configuration';
import { PythonSymbolProvider } from '../providers/symbolProvider';

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

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

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

Expand Down Expand Up @@ -184,9 +188,11 @@ function displayStopUI(message: string) {
testDisplay = testDisplay ? testDisplay : new TestDisplay();
testDisplay.displayStopTestUI(message);
}
let uniTestSettingsString = JSON.stringify(settings.unitTest);
let uniTestSettingsString: string;

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

testResultDisplay.DisplayProgressStatus(runPromise, debug);
}
}
5 changes: 2 additions & 3 deletions src/client/unittests/nosetest/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import * as os from 'os';
import { extractBetweenDelimiters, convertFileToPackage, flattenTestFiles } from '../common/testUtils';
import { CancellationToken } from 'vscode';
import { PythonSettings } from '../../common/configSettings';
import { OutputChannel } from 'vscode';
import { OutputChannel, Uri } from 'vscode';

const pythonSettings = PythonSettings.getInstance();
const NOSE_WANT_FILE_PREFIX = 'nose.selector: DEBUG: wantFile ';
const NOSE_WANT_FILE_SUFFIX = '.py? True';
const NOSE_WANT_FILE_SUFFIX_WITHOUT_EXT = '? True';
Expand Down Expand Up @@ -78,7 +77,7 @@ export function discoverTests(rootDirectory: string, args: string[], token: Canc
});
}

return execPythonFile(pythonSettings.unitTest.nosetestPath, args.concat(['--collect-only', '-vvv']), rootDirectory, true)
return execPythonFile(PythonSettings.getInstance(Uri.file(rootDirectory)).unitTest.nosetestPath, args.concat(['--collect-only', '-vvv']), rootDirectory, true)
.then(data => {
outChannel.appendLine(data);
processOutput(data);
Expand Down
6 changes: 2 additions & 4 deletions src/client/unittests/nosetest/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ import { BaseTestManager } from '../common/baseTestManager';
import { runTest } from './runner';
import { Product } from '../../common/installer';

const settings = PythonSettings.getInstance();

export class TestManager extends BaseTestManager {
constructor(rootDirectory: string, outputChannel: vscode.OutputChannel) {
super('nosetest', Product.nosetest, rootDirectory, outputChannel);
}
discoverTestsImpl(ignoreCache: boolean): Promise<Tests> {
let args = settings.unitTest.nosetestArgs.slice(0);
let args = this.settings.unitTest.nosetestArgs.slice(0);
return discoverTests(this.rootDirectory, args, this.cancellationToken, ignoreCache, this.outputChannel);
}
runTestImpl(tests: Tests, testsToRun?: TestsToRun, runFailedTests?: boolean, debug?: boolean): Promise<any> {
let args = settings.unitTest.nosetestArgs.slice(0);
let args = this.settings.unitTest.nosetestArgs.slice(0);
if (runFailedTests === true && args.indexOf('--failed') === -1) {
args.push('--failed');
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/unittests/nosetest/runner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
import { createTemporaryFile } from '../../common/helpers';
import { OutputChannel, CancellationToken } from 'vscode';
import { OutputChannel, CancellationToken, Uri } from 'vscode';
import { TestsToRun, Tests } from '../common/contracts';
import { updateResults } from '../common/testUtils';
import { updateResultsFromXmlLogFile, PassCalculationFormulae } from '../common/xUnitParser';
Expand All @@ -9,7 +9,6 @@ import { PythonSettings } from '../../common/configSettings';
import * as path from 'path';
import { launchDebugger } from '../common/debugLauncher';

const pythonSettings = PythonSettings.getInstance();
const WITH_XUNIT = '--with-xunit';
const XUNIT_FILE = '--xunit-file';

Expand Down Expand Up @@ -61,6 +60,7 @@ export function runTest(rootDirectory: string, tests: Tests, args: string[], tes
}

return promiseToGetXmlLogFile.then(() => {
const pythonSettings = PythonSettings.getInstance(Uri.file(rootDirectory));
if (debug === true) {
const testLauncherFile = path.join(__dirname, '..', '..', '..', '..', 'pythonFiles', 'PythonTools', 'testlauncher.py');
const nosetestlauncherargs = [rootDirectory, 'my_secret', pythonSettings.unitTest.debugPort.toString(), 'nose'];
Expand Down
4 changes: 1 addition & 3 deletions src/client/unittests/pytest/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import * as path from 'path';
import { PythonSettings } from '../../common/configSettings';
import { OutputChannel } from 'vscode';

const pythonSettings = PythonSettings.getInstance();

const argsToExcludeForDiscovery = ['-x', '--exitfirst',
'--fixtures-per-test', '--pdb', '--runxfail',
'--lf', '--last-failed', '--ff', '--failed-first',
Expand Down Expand Up @@ -85,7 +83,7 @@ export function discoverTests(rootDirectory: string, args: string[], token: vsco
});
}

return execPythonFile(pythonSettings.unitTest.pyTestPath, args.concat(['--collect-only']), rootDirectory, false, null, token)
return execPythonFile(PythonSettings.getInstance(vscode.Uri.file(rootDirectory)).unitTest.pyTestPath, args.concat(['--collect-only']), rootDirectory, false, null, token)
.then(data => {
outChannel.appendLine(data);
processOutput(data);
Expand Down
6 changes: 2 additions & 4 deletions src/client/unittests/pytest/main.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
'use strict';
import { PythonSettings } from '../../common/configSettings';
import { TestsToRun, Tests } from '../common/contracts';
import { runTest } from './runner';
import * as vscode from 'vscode';
import { discoverTests } from './collector';
import { BaseTestManager } from '../common/baseTestManager';
import { Product } from '../../common/installer';

const settings = PythonSettings.getInstance();
export class TestManager extends BaseTestManager {
constructor(rootDirectory: string, outputChannel: vscode.OutputChannel) {
super('pytest', Product.pytest, rootDirectory, outputChannel);
}
discoverTestsImpl(ignoreCache: boolean): Promise<Tests> {
let args = settings.unitTest.pyTestArgs.slice(0);
let args = this.settings.unitTest.pyTestArgs.slice(0);
return discoverTests(this.rootDirectory, args, this.cancellationToken, ignoreCache, this.outputChannel);
}
runTestImpl(tests: Tests, testsToRun?: TestsToRun, runFailedTests?: boolean, debug?: boolean): Promise<any> {
let args = settings.unitTest.pyTestArgs.slice(0);
let args = this.settings.unitTest.pyTestArgs.slice(0);
if (runFailedTests === true && args.indexOf('--lf') === -1 && args.indexOf('--last-failed') === -1) {
args.push('--last-failed');
}
Expand Down
5 changes: 2 additions & 3 deletions src/client/unittests/pytest/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import { createTemporaryFile } from '../../common/helpers';
import { TestsToRun, Tests } from '../common/contracts';
import { updateResults } from '../common/testUtils';
import { CancellationToken, OutputChannel } from 'vscode';
import { CancellationToken, OutputChannel, Uri } from 'vscode';
import { updateResultsFromXmlLogFile, PassCalculationFormulae } from '../common/xUnitParser';
import { run } from '../common/runner';
import { PythonSettings } from '../../common/configSettings';
import * as path from 'path';
import { launchDebugger } from '../common/debugLauncher';

const pythonSettings = PythonSettings.getInstance();

export function runTest(rootDirectory: string, tests: Tests, args: string[], testsToRun?: TestsToRun, token?: CancellationToken, outChannel?: OutputChannel, debug?: boolean): Promise<Tests> {
let testPaths = [];
if (testsToRun && testsToRun.testFolder) {
Expand All @@ -39,6 +37,7 @@ export function runTest(rootDirectory: string, tests: Tests, args: string[], tes
args = args.filter(arg => arg.trim().startsWith('-'));
}
const testArgs = testPaths.concat(args, [`--junitxml=${xmlLogFile}`]);
const pythonSettings = PythonSettings.getInstance(Uri.file(rootDirectory));
if (debug) {
const testLauncherFile = path.join(__dirname, '..', '..', '..', '..', 'pythonFiles', 'PythonTools', 'testlauncher.py');
const pytestlauncherargs = [rootDirectory, 'my_secret', pythonSettings.unitTest.debugPort.toString(), 'pytest'];
Expand Down
6 changes: 2 additions & 4 deletions src/client/unittests/unittest/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import * as path from 'path';
import { PythonSettings } from '../../common/configSettings';
import { OutputChannel } from 'vscode';

const pythonSettings = PythonSettings.getInstance();

export function discoverTests(rootDirectory: string, args: string[], token: vscode.CancellationToken, ignoreCache: boolean, outChannel: OutputChannel): Promise<Tests> {
let startDirectory = '.';
let pattern = 'test*.py';
Expand Down Expand Up @@ -73,7 +71,7 @@ for suite in suites._tests:
});
}
args = [];
return execPythonFile(pythonSettings.pythonPath, args.concat(['-c', pythonScript]), rootDirectory, true, null, token)
return execPythonFile(PythonSettings.getInstance(vscode.Uri.file(rootDirectory)).pythonPath, args.concat(['-c', pythonScript]), rootDirectory, true, null, token)
.then(data => {
outChannel.appendLine(data);
processOutput(data);
Expand Down Expand Up @@ -152,4 +150,4 @@ function addTestId(rootDirectory: string, testId: string, testFiles: TestFile[])
};

testSuite.functions.push(testFunction);
}
}
6 changes: 2 additions & 4 deletions src/client/unittests/unittest/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ import * as vscode from 'vscode';
import { discoverTests } from './collector';
import { BaseTestManager } from '../common/baseTestManager';
import { Product } from '../../common/installer';

const settings = PythonSettings.getInstance();
export class TestManager extends BaseTestManager {
constructor(rootDirectory: string, outputChannel: vscode.OutputChannel) {
super('unitest', Product.unittest, rootDirectory, outputChannel);
}
configure() {
}
discoverTestsImpl(ignoreCache: boolean): Promise<Tests> {
let args = settings.unitTest.unittestArgs.slice(0);
let args = this.settings.unitTest.unittestArgs.slice(0);
return discoverTests(this.rootDirectory, args, this.cancellationToken, ignoreCache, this.outputChannel);
}
runTestImpl(tests: Tests, testsToRun?: TestsToRun, runFailedTests?: boolean, debug?: boolean): Promise<any> {
let args = settings.unitTest.unittestArgs.slice(0);
let args = this.settings.unitTest.unittestArgs.slice(0);
if (runFailedTests === true) {
testsToRun = { testFile: [], testFolder: [], testSuite: [], testFunction: [] };
testsToRun.testFunction = tests.testFunctions.filter(fn => {
Expand Down
Loading

0 comments on commit 3457c62

Please sign in to comment.