1
1
const fs = require ( 'fs' )
2
+ const chalk = require ( "chalk" )
2
3
const shell = require ( 'shelljs' )
3
4
const { Utils, TestingError } = require ( './utils/index.js' )
4
5
5
6
module . exports = {
6
- capture : "sys" ,
7
- color : "yes" ,
8
7
validate : async function ( { exercise, configuration } ) {
9
8
10
9
if ( ! shell . which ( 'pytest' ) ) {
@@ -28,7 +27,7 @@ def pytest_generate_tests(metafunc):
28
27
metafunc.parametrize("stdin",metafunc.configuration.getoption('stdin'))
29
28
if 'app' in metafunc.fixturenames:
30
29
try:
31
- sys.path.append('${ configuration . configPath . output } ')
30
+ sys.path.append('${ configuration . outputPath } ')
32
31
import cached_app
33
32
metafunc.parametrize("app",[cached_app.execute_app])
34
33
except SyntaxError:
@@ -46,8 +45,9 @@ def pytest_generate_tests(metafunc):
46
45
run : async ( { exercise, socket, configuration } ) => {
47
46
48
47
const getEntry = ( ) => {
48
+ console . log ( exercise ) ;
49
49
let entryPath = exercise . files . map ( f => './' + f . path ) . find ( f => f . indexOf ( 'test.py' ) > - 1 || f . indexOf ( 'tests.py' ) > - 1 )
50
- if ( ! fs . existsSync ( entryPath ) ) throw TestingError ( `🚫 No tests.py script found on the exercise files ` )
50
+ if ( ! fs . existsSync ( entryPath ) ) throw TestingError ( `🚫 No tests.py script found on the exercise in ${ entryPath } ` )
51
51
52
52
const appPath = exercise . files . map ( f => './' + f . path ) . find ( f => f . indexOf ( 'app.py' ) > - 1 )
53
53
if ( fs . existsSync ( appPath ) ) {
@@ -58,7 +58,7 @@ def pytest_generate_tests(metafunc):
58
58
// Adding main execute_app function for all the code
59
59
content = `def execute_app():\n${ Utils . indent ( content , 4 ) } `
60
60
}
61
- const directory = `${ configuration . configPath . output } /cached_app.py`
61
+ const directory = `${ configuration . outputPath } /cached_app.py`
62
62
fs . writeFileSync ( directory , content )
63
63
}
64
64
else if ( configuration . grading === "isolated" ) throw TestingError ( `🚫 No app.py script found on the exercise files` )
@@ -74,10 +74,10 @@ def pytest_generate_tests(metafunc):
74
74
const count = Utils . getMatches ( / i n p u t \( (?: [ " ' ` ] { 1 } ( .* ) [ " ' ` ] { 1 } ) ? \) / gm, content )
75
75
let answers = ( count . length == 0 ) ? [ ] : await socket . ask ( count )
76
76
77
- return `pytest ${ getEntry ( ) } --testdox --capture=${ this . capture } --color=${ this . color } --stdin='${ JSON . stringify ( answers ) } '`
77
+ return `pytest ${ getEntry ( ) } --testdox --capture=sys --color=yes --stdin='${ JSON . stringify ( answers ) } '`
78
78
}
79
79
else {
80
- return `pytest ${ getEntry ( ) } --testdox --capture=${ this . capture } --color=${ this . color } `
80
+ return `pytest ${ getEntry ( ) } --testdox --capture=sys --color=yes `
81
81
}
82
82
}
83
83
@@ -95,7 +95,9 @@ def pytest_generate_tests(metafunc):
95
95
96
96
let _stdout = [ rawStdout ]
97
97
if ( errors . length > 0 ) {
98
- msg = `\n\n ${ 'Your code must to comply with the following tests:' . red } \n\n${ [ ...new Set ( errors ) ] . map ( ( e , i ) => ` ${ e . status !== 'failed' ? '✓ (done)' . green . bold : 'x (fail)' . red . bold } ${ i } . ${ e . title . white } ` ) . join ( '\n' ) } \n\n`
98
+ msg = `\n\n
99
+ ${ chalk . red ( 'Your code must to comply with the following tests:' ) } \n\n
100
+ ${ [ ...new Set ( errors ) ] . map ( ( e , i ) => ` ${ e . status !== 'failed' ? chalk . green . bold ( '✓ (done)' ) : chalk . red . bold ( 'x (fail)' ) } ${ i } . ${ chalk . white ( e . title ) } ` ) . join ( '\n' ) } \n\n`
99
101
_stdout . push ( msg )
100
102
}
101
103
return _stdout
@@ -111,7 +113,7 @@ def pytest_generate_tests(metafunc):
111
113
stderr = resp . stderr
112
114
if ( code != 0 ) break
113
115
}
114
- if ( code != 0 ) return getStdout ( stdout || stderr )
116
+ if ( code != 0 ) throw TestingError ( getStdout ( stdout || stderr ) . join ( ) )
115
117
else return stdout
116
118
}
117
119
}
0 commit comments