Skip to content

Commit 3497ae0

Browse files
committed
re-factor testrunner out #239
1 parent 9b8f454 commit 3497ae0

File tree

6 files changed

+16
-24
lines changed

6 files changed

+16
-24
lines changed

src/client/unittest/common/baseTestManager.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,6 @@ export abstract class BaseTestManager {
2626
constructor(private testProvider: string, protected rootDirectory: string, protected outputChannel: vscode.OutputChannel) {
2727
this._status = TestStatus.Unknown;
2828
}
29-
protected stdOut(output: string) {
30-
this.outputChannel.append(output);
31-
// output.split(/\r?\n/g).forEach((line, index, lines) => {
32-
// if (index === 0) {
33-
// if (output.startsWith(os.EOL) || lines.length > 1) {
34-
// return this.outputChannel.appendLine(line);
35-
// }
36-
// return this.outputChannel.append(line);
37-
// }
38-
// if (index === lines.length - 1) {
39-
// return this.outputChannel.append(line);
40-
// }
41-
// this.outputChannel.appendLine(line);
42-
// });
43-
}
4429
public reset() {
4530
this._status = TestStatus.Unknown;
4631
this.tests = null;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {execPythonFile} from './../../common/utils';
2+
import {CancellationToken, OutputChannel} from 'vscode';
3+
4+
export function run(file: string, args: string[], cwd: string, token?: CancellationToken, outChannel?: OutputChannel): Promise<string> {
5+
return execPythonFile(file, args, cwd, true, (data: string) => outChannel.append(data), token);
6+
}

src/client/unittest/nosetest/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ export class TestManager extends BaseTestManager {
2222
if (runFailedTests === true && args.indexOf('--failed') === -1) {
2323
args.push('--failed');
2424
}
25-
return runTest(this.rootDirectory, tests, args, testsToRun, this.stdOut.bind(this), this.cancellationToken);
25+
return runTest(this.rootDirectory, tests, args, testsToRun, this.cancellationToken, this.outputChannel);
2626
}
2727
}

src/client/unittest/nosetest/runner.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import * as path from 'path';
33
import {execPythonFile} from './../../common/utils';
44
import {createDeferred, createTemporaryFile} from '../../common/helpers';
5-
import {OutputChannel, window} from 'vscode';
5+
import {OutputChannel, window, CancellationToken} from 'vscode';
66
import {TestFile, TestsToRun, TestSuite, TestFunction, FlattenedTestFunction, Tests, TestStatus, FlattenedTestSuite} from '../common/contracts';
77
import * as vscode from 'vscode';
88
import {extractBetweenDelimiters, convertFileToPackage, flattenTestFiles, updateResults} from '../common/testUtils';
99
import {BaseTestManager} from '../common/baseTestManager';
10-
import {CancellationToken} from 'vscode';
1110
import {updateResultsFromXmlLogFile, PassCalculationFormulae} from '../common/xUnitParser';
11+
import {run} from '../common/runner';
1212

13-
export function runTest(rootDirectory: string, tests: Tests, args: string[], testsToRun?: TestsToRun, stdOut?: (output: string) => void, token?: CancellationToken): Promise<any> {
13+
export function runTest(rootDirectory: string, tests: Tests, args: string[], testsToRun?: TestsToRun, token?: CancellationToken, outChannel?: OutputChannel): Promise<any> {
1414
let testPaths = [];
1515
if (testsToRun && testsToRun.testFolder) {
1616
testPaths = testPaths.concat(testsToRun.testFolder.map(f => f.nameToRun));
@@ -31,7 +31,7 @@ export function runTest(rootDirectory: string, tests: Tests, args: string[], tes
3131
return createTemporaryFile('.xml').then(xmlLogResult => {
3232
xmlLogFile = xmlLogResult.filePath;
3333
xmlLogFileCleanup = xmlLogResult.cleanupCallback;
34-
return execPythonFile('nosetests', args.concat(['--with-xunit', `--xunit-file=${xmlLogFile}`]).concat(testPaths), rootDirectory, true, stdOut);
34+
return run('nosetests', args.concat(['--with-xunit', `--xunit-file=${xmlLogFile}`]).concat(testPaths), rootDirectory, token, outChannel);
3535
}).then(() => {
3636
return updateResultsFromLogFiles(tests, xmlLogFile);
3737
}).then(result => {

src/client/unittest/pytest/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ export class TestManager extends BaseTestManager {
2020
if (runFailedTests === true && args.indexOf('--lf') === -1 && args.indexOf('--last-failed') === -1) {
2121
args.push('--last-failed');
2222
}
23-
return runTest(this.rootDirectory, tests, args, testsToRun, this.stdOut.bind(this), this.cancellationToken);
23+
return runTest(this.rootDirectory, tests, args, testsToRun, this.cancellationToken, this.outputChannel);
2424
}
2525
}

src/client/unittest/pytest/runner.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import {createDeferred, createTemporaryFile} from '../../common/helpers';
66
import {TestFile, TestsToRun, TestSuite, TestFunction, FlattenedTestFunction, Tests, TestStatus, FlattenedTestSuite} from '../common/contracts';
77
import {extractBetweenDelimiters, flattenTestFiles, updateResults, convertFileToPackage} from '../common/testUtils';
88
import {BaseTestManager} from '../common/baseTestManager';
9-
import {CancellationToken} from 'vscode';
9+
import {CancellationToken, OutputChannel} from 'vscode';
1010
import {updateResultsFromXmlLogFile, PassCalculationFormulae} from '../common/xUnitParser';
11+
import {run} from '../common/runner';
1112

12-
export function runTest(rootDirectory: string, tests: Tests, args: string[], testsToRun?: TestsToRun, stdOut?: (output: string) => void, token?: CancellationToken): Promise<Tests> {
13+
export function runTest(rootDirectory: string, tests: Tests, args: string[], testsToRun?: TestsToRun, token?: CancellationToken, outChannel?: OutputChannel): Promise<Tests> {
1314
let testPaths = [];
1415
if (testsToRun && testsToRun.testFolder) {
1516
testPaths = testPaths.concat(testsToRun.testFolder.map(f => f.nameToRun));
@@ -31,7 +32,7 @@ export function runTest(rootDirectory: string, tests: Tests, args: string[], tes
3132
xmlLogFile = xmlLogResult.filePath;
3233
xmlLogFileCleanup = xmlLogResult.cleanupCallback;
3334
const testArgs = args.concat([`--junitxml=${xmlLogFile}`]).concat(testPaths);
34-
return execPythonFile('py.test', testArgs, rootDirectory, true, stdOut, token);
35+
return run('py.test', testArgs, rootDirectory, token, outChannel);
3536
}).then(() => {
3637
return updateResultsFromLogFiles(tests, xmlLogFile);
3738
}).then(result => {

0 commit comments

Comments
 (0)