This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from education/add-python-to-integration-job
Add Python Runner to Integration Job
- Loading branch information
Showing
4 changed files
with
126 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,103 @@ | ||
const process = require("process"); | ||
const cp = require("child_process"); | ||
const path = require("path"); | ||
const process = require('process') | ||
const cp = require('child_process') | ||
const path = require('path') | ||
|
||
const node = process.execPath; | ||
const ip = path.join(__dirname, "..", "src", "main.js"); | ||
const node = process.execPath | ||
const ip = path.join(__dirname, '..', 'src', 'main.js') | ||
const options = { | ||
env: process.env, | ||
encoding: "utf-8", | ||
}; | ||
|
||
const { parseRunnerResults } = require("../src/main"); | ||
|
||
test("test runs", () => { | ||
process.env.RESULT1_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 1", "status": "pass", "message": null }] }').toString("base64"); | ||
process.env.INPUT_RUNNERS = "result1"; | ||
|
||
const child = cp.spawnSync(node, [ip], options); | ||
const stdout = child.stdout.toString(); | ||
expect(stdout).toContain(`✅ Test 1`); | ||
}); | ||
|
||
test("test fails", () => { | ||
process.env.RESULT1_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 1", "status": "fail", "message": "Test failed with non-zero exit code." }] }').toString("base64"); | ||
process.env.INPUT_RUNNERS = "result1"; | ||
|
||
const child = cp.spawnSync(node, [ip], options); | ||
const stdout = child.stdout.toString(); | ||
expect(stdout).toContain(`❌ Test 1`); | ||
}); | ||
|
||
test("test errors out", () => { | ||
process.env.RESULT1_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 1", "status": "error", "message": "Test failed to execute." }] }').toString("base64"); | ||
process.env.INPUT_RUNNERS = "result1"; | ||
|
||
const child = cp.spawnSync(node, [ip], options); | ||
const stdout = child.stdout.toString(); | ||
expect(stdout).toContain(`Error: Test failed to execute.`); | ||
}); | ||
|
||
test("fails to run if input not in the right format", () => { | ||
process.env.RESULT1_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 1", "status": "pass", "message": null }] }').toString("base64"); | ||
process.env.RESULT2_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 2", "status": "pass", "message": null }] }').toString("base64"); | ||
process.env.INPUT_RUNNERS = "[result1,result2]"; | ||
|
||
const child = cp.spawnSync(node, [ip], options); | ||
const stderr = child.stderr.toString(); | ||
expect(stderr).toContain(`The runners input must be a comma-separated list of strings.`); | ||
}); | ||
|
||
// test('test runs with multiple runners', () => { | ||
// process.env.RESULT1_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 1", "status": "pass", "message": null }] }').toString('base64') | ||
// process.env.RESULT2_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 2", "status": "pass", "message": null }] }').toString('base64') | ||
// process.env.INPUT_RUNNERS = 'result1,result2' | ||
|
||
// const child = cp.spawnSync(node, [ip], options) | ||
// const stdout = child.stdout.toString() | ||
// console.log(stdout) | ||
// expect(stdout).toBe('pass') | ||
// }) | ||
|
||
// test('test fails with multiple runners', () => { | ||
// process.env.RESULT1_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 1", "status": "fail", "message": null }] }').toString('base64') | ||
// process.env.RESULT2_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 2", "status": "pass", "message": null }] }').toString('base64') | ||
// process.env.INPUT_RUNNERS = 'result1,result2' | ||
|
||
// const child = cp.spawnSync(node, [ip], options) | ||
// const stdout = child.stdout.toString() | ||
// console.log(stdout) | ||
// expect(stdout).toBe('fail') | ||
// }) | ||
|
||
test("test autograding-output.parseRunnerResults", function () { | ||
process.env.INPUT_RUNNERS = "result1,result2"; | ||
|
||
let testResults1 = parseRunnerResults(process.env.INPUT_RUNNERS); | ||
expect(testResults1.length).toBe(2); | ||
expect(testResults1[0].runner).toBe("result1"); | ||
expect(testResults1[1].runner).toBe("result2"); | ||
|
||
process.env.INPUT_RUNNERS = "[result1,result2]"; | ||
expect(() => parseRunnerResults(process.env.INPUT_RUNNERS)).toThrow("The runners input must be a comma-separated list of strings."); | ||
}); | ||
encoding: 'utf-8', | ||
} | ||
|
||
const {parseRunnerResults} = require('../src/main') | ||
|
||
test('test runs', () => { | ||
process.env.RESULT1_RESULTS = Buffer.from( | ||
'{ "tests": [{ "name": "Test 1", "status": "pass", "message": null }] }', | ||
).toString('base64') | ||
process.env.INPUT_RUNNERS = 'result1' | ||
|
||
const child = cp.spawnSync(node, [ip], options) | ||
const stdout = child.stdout.toString() | ||
expect(stdout).toContain(`✅ Test 1`) | ||
}) | ||
|
||
test('test fails', () => { | ||
process.env.RESULT1_RESULTS = Buffer.from( | ||
'{ "tests": [{ "name": "Test 1", "status": "fail", "message": "Test failed with non-zero exit code." }] }', | ||
).toString('base64') | ||
process.env.INPUT_RUNNERS = 'result1' | ||
|
||
const child = cp.spawnSync(node, [ip], options) | ||
const stdout = child.stdout.toString() | ||
expect(stdout).toContain(`❌ Test 1`) | ||
}) | ||
|
||
test('test errors out', () => { | ||
process.env.RESULT1_RESULTS = Buffer.from( | ||
'{ "tests": [{ "name": "Test 1", "status": "error", "message": "Test failed to execute." }] }', | ||
).toString('base64') | ||
process.env.INPUT_RUNNERS = 'result1' | ||
|
||
const child = cp.spawnSync(node, [ip], options) | ||
const stdout = child.stdout.toString() | ||
expect(stdout).toContain(`Error: Test failed to execute.`) | ||
}) | ||
|
||
test('fails to run if input not in the right format', () => { | ||
process.env.RESULT1_RESULTS = Buffer.from( | ||
'{ "tests": [{ "name": "Test 1", "status": "pass", "message": null }] }', | ||
).toString('base64') | ||
process.env.RESULT2_RESULTS = Buffer.from( | ||
'{ "tests": [{ "name": "Test 2", "status": "pass", "message": null }] }', | ||
).toString('base64') | ||
process.env.INPUT_RUNNERS = '[result1,result2]' | ||
|
||
const child = cp.spawnSync(node, [ip], options) | ||
const stderr = child.stderr.toString() | ||
expect(stderr).toContain(`The runners input must be a comma-separated list of strings.`) | ||
}) | ||
|
||
test('test runs with multiple runners', () => { | ||
process.env.RESULT1_RESULTS = Buffer.from( | ||
'{ "tests": [{ "name": "Test 1", "status": "pass", "message": null }] }', | ||
).toString('base64') | ||
process.env.RESULT2_RESULTS = Buffer.from( | ||
'{ "tests": [{ "name": "Test 2", "status": "pass", "message": null }] }', | ||
).toString('base64') | ||
process.env.INPUT_RUNNERS = 'result1,result2' | ||
|
||
const child = cp.spawnSync(node, [ip], options) | ||
const stdout = child.stdout.toString() | ||
console.log(stdout) | ||
expect(stdout).toContain('✅') | ||
}) | ||
|
||
test('test fails with multiple runners', () => { | ||
process.env.RESULT1_RESULTS = Buffer.from( | ||
'{ "tests": [{ "name": "Test 1", "status": "fail", "message": null }] }', | ||
).toString('base64') | ||
process.env.RESULT2_RESULTS = Buffer.from( | ||
'{ "tests": [{ "name": "Test 2", "status": "pass", "message": null }] }', | ||
).toString('base64') | ||
process.env.INPUT_RUNNERS = 'result1,result2' | ||
|
||
const child = cp.spawnSync(node, [ip], options) | ||
const stdout = child.stdout.toString() | ||
console.log(stdout) | ||
expect(stdout).toContain('❌') | ||
}) | ||
|
||
test('test autograding-output.parseRunnerResults', function () { | ||
process.env.INPUT_RUNNERS = 'result1,result2' | ||
|
||
const testResults1 = parseRunnerResults(process.env.INPUT_RUNNERS) | ||
expect(testResults1.length).toBe(2) | ||
expect(testResults1[0].runner).toBe('result1') | ||
expect(testResults1[1].runner).toBe('result2') | ||
|
||
process.env.INPUT_RUNNERS = '[result1,result2]' | ||
expect(() => parseRunnerResults(process.env.INPUT_RUNNERS)).toThrow( | ||
'The runners input must be a comma-separated list of strings.', | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters