Skip to content

Commit 1455d98

Browse files
committed
test runner progress.
1 parent aff82c2 commit 1455d98

19 files changed

+178
-59
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.cache
22
test/__pycache__
3-
report.json
3+
_report.json
44
node_modules

_report.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"report": {"environment": {"Python": "2.7.9", "Platform": "Darwin-15.4.0-x86_64-i386-64bit"}, "tests": [{"name": "pass-three.py::Test03Class::()::test_passing_one", "teardown": {"duration": 6.198883056640625e-05, "outcome": "passed", "name": "teardown"}, "setup": {"duration": 0.00016808509826660156, "outcome": "passed", "name": "setup"}, "run_index": 4, "call": {"duration": 8.416175842285156e-05, "outcome": "passed", "name": "call"}, "duration": 0.00048232078552246094, "outcome": "passed"}, {"name": "pass-three.py::Test01Class::()::test_passing_test", "teardown": {"duration": 0.00013494491577148438, "outcome": "passed", "name": "teardown"}, "setup": {"duration": 0.00033593177795410156, "outcome": "passed", "name": "setup"}, "run_index": 1, "call": {"duration": 0.00015497207641601562, "outcome": "passed", "name": "call"}, "duration": 0.0009617805480957031, "outcome": "passed"}, {"name": "pass-three.py::Test02Class::()::test_passing_test", "teardown": {"duration": 6.794929504394531e-05, "outcome": "passed", "name": "teardown"}, "setup": {"duration": 0.00023698806762695312, "outcome": "passed", "name": "setup"}, "run_index": 3, "call": {"duration": 8.702278137207031e-05, "outcome": "passed", "name": "call"}, "duration": 0.0006289482116699219, "outcome": "passed"}, {"name": "pass-three.py::Test03Class::()::test_passing_test", "teardown": {"duration": 0.00014495849609375, "outcome": "passed", "name": "teardown"}, "setup": {"duration": 0.0027310848236083984, "outcome": "passed", "name": "setup"}, "run_index": 5, "call": {"duration": 0.000164031982421875, "outcome": "passed", "name": "call"}, "duration": 0.005771160125732422, "outcome": "passed"}, {"name": "pass-three.py::Test01Class::()::test_passing_one", "teardown": {"duration": 0.0002980232238769531, "outcome": "passed", "name": "teardown"}, "setup": {"duration": 0.010185956954956055, "outcome": "passed", "name": "setup"}, "run_index": 0, "call": {"duration": 0.0004360675811767578, "outcome": "passed", "name": "call"}, "duration": 0.02110600471496582, "outcome": "passed"}, {"name": "pass-three.py::Test02Class::()::test_passing_one", "teardown": {"duration": 0.00010180473327636719, "outcome": "passed", "name": "teardown"}, "setup": {"duration": 0.0004000663757324219, "outcome": "passed", "name": "setup"}, "run_index": 2, "call": {"duration": 0.00014591217041015625, "outcome": "passed", "name": "call"}, "duration": 0.0010478496551513672, "outcome": "passed"}], "created_at": "2016-03-29 09:09:32.380699", "summary": {"duration": 0.0329899787902832, "passed": 6, "num_tests": 6}}}

lib/create-runner.js

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11
"use strict";
22
var path = require('path');
3-
var spawn = require('child_process').spawn;
4-
var node = null;
5-
if (process.platform === 'darwin' && process.resourcesPath) {
6-
node = path.resolve(process.resourcesPath, '..', 'Frameworks', 'Atom Helper.app', 'Contents', 'MacOS', 'Atom Helper');
7-
}
8-
else if (process.platform.match(/win/)) {
9-
node = 'node';
10-
}
11-
else {
12-
node = process.execPath;
13-
}
3+
var child = require('child_process');
144
function createRunner(config, testFile) {
15-
var options = {
16-
cwd: config.dir
17-
};
18-
if (options.env == null) {
19-
options.env = Object.create(process.env);
20-
}
21-
options.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE = 1;
22-
return spawn(node, [
5+
var report = path.join(__dirname, '..', '_report.json');
6+
return child.exec([
237
'py.test',
24-
'--json=report.json',
8+
("--json=" + report),
259
'-x',
26-
'tb=no',
2710
testFile
28-
], options);
11+
].join(' '), function (error, stdout, stderr) {
12+
console.log("stdout: " + stdout);
13+
console.log("stderr: " + stderr);
14+
if (error !== null) {
15+
console.log("exec error: " + error);
16+
}
17+
});
2918
}
30-
exports.createRunner = createRunner;
19+
Object.defineProperty(exports, "__esModule", { value: true });
20+
exports.default = createRunner;

lib/parse-json.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ function parseJson(pathToResults) {
4343
}
4444
return final;
4545
}
46-
exports.parseJson = parseJson;
46+
Object.defineProperty(exports, "__esModule", { value: true });
47+
exports.default = parseJson;

lib/runner.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ var path = require('path');
33
var exists_1 = require('./exists');
44
var create_runner_1 = require('./create-runner');
55
var parse_json_1 = require('./parse-json');
6-
var pathToResults = path.resolve(__dirname, '', 'report.json');
6+
var pathToResults = path.resolve(__dirname, '..', '_report.json');
77
function runner(testFile, config, handleResult) {
8-
var runner = create_runner_1.createRunner(config, testFile);
8+
var runner = create_runner_1.default(config, testFile);
99
var final = null;
1010
return new Promise(function (resolve, reject) {
1111
runner.stdout.on('data', function (data) {
1212
data = data.toString();
13+
console.log(data);
1314
if (!exists_1.default(pathToResults)) {
1415
console.log('error finding test output file: ', data);
1516
return;
1617
}
17-
final = parse_json_1.parseJson(pathToResults);
18+
final = parse_json_1.default(pathToResults);
1819
final.change = final.taskPosition - config.taskPosition;
1920
final.pass = final.change > 0;
2021
handleResult(final);

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,15 @@
2828
"homepage": "https://github.com/coderoad/pytest-coderoad#readme",
2929
"devDependencies": {
3030
"ava": "^0.13.0"
31+
},
32+
"ava": {
33+
"files": [
34+
"test/*.spec.js",
35+
"!node_modules"
36+
],
37+
"source": [
38+
"test/*.spec.js"
39+
],
40+
"failFast": true
3141
}
3242
}

src/create-runner.ts

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
11
import * as path from 'path';
2-
const spawn = require('child_process').spawn;
2+
const child = require('child_process');
33

4-
// get absolute path to node exec
5-
let node = null;
6-
if (process.platform === 'darwin' && process.resourcesPath) {
7-
node = path.resolve(process.resourcesPath, '..', 'Frameworks', 'Atom Helper.app', 'Contents', 'MacOS', 'Atom Helper');
8-
} else if (process.platform.match(/win/)) {
9-
node = 'node';
10-
} else {
11-
node = process.execPath;
12-
}
4+
export default function createRunner(config: CR.Config, testFile: string) {
135

14-
export function createRunner(config: CR.Config, testFile: string) {
15-
// node electron setup
16-
let options: any = {
17-
cwd: config.dir
18-
};
19-
if (options.env == null) {
20-
options.env = Object.create(process.env);
21-
}
22-
options.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE = 1;
6+
let report = path.join(__dirname, '..', '_report.json');
237

24-
// spawn child process calling test runner
25-
return spawn(node, [
8+
return child.exec([
269
'py.test',
27-
'--json=report.json',
10+
`--json=${report}`,
2811
'-x', // stop after first failure
29-
'tb=no', // no printing traceback to console
3012
testFile
31-
], options);
13+
].join(' '), (error, stdout, stderr) => {
14+
console.log(`stdout: ${stdout}`);
15+
console.log(`stderr: ${stderr}`);
16+
if (error !== null) {
17+
console.log(`exec error: ${error}`);
18+
}
19+
});
3220
}

src/parse-json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function formatFailureMessage(message: string): string {
66
return message.split('_').join(' ');
77
}
88

9-
export function parseJson(pathToResults: string): ParseFinal {
9+
export default function parseJson(pathToResults: string): ParseFinal {
1010
let result = JSON.parse(JSON.stringify(require(pathToResults)));
1111
if (!result.report || !result.report.tests.length || !result.report.summary) {
1212
console.log('error with test output in report.json');

src/runner.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as path from 'path';
22
import exists from './exists';
3-
import {createRunner} from './create-runner';
4-
import {parseJson} from './parse-json';
3+
import createRunner from './create-runner';
4+
import parseJson from './parse-json';
55

6-
const pathToResults = path.resolve(__dirname, '', 'report.json');
6+
const pathToResults = path.resolve(__dirname, '..', '_report.json');
77

88
export default function runner(testFile: string, config: CR.Config,
99
handleResult: (result) => CR.TestResult) {
@@ -15,6 +15,7 @@ export default function runner(testFile: string, config: CR.Config,
1515
runner.stdout.on('data', function(data): void {
1616

1717
data = data.toString();
18+
console.log(data);
1819

1920
if (!exists(pathToResults)) {
2021
console.log('error finding test output file: ', data);

test/create-runner.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import test from 'ava';
2+
import * as path from 'path';
3+
import {getCreateRunner} from './runner-setup';
4+
5+
test('creates a test runner', t => {
6+
let testFile = path.join(__dirname, 'demos', 'single-test.py');
7+
let createRunner = getCreateRunner(testFile);
8+
t.ok(createRunner);
9+
});

0 commit comments

Comments
 (0)