@@ -117,14 +117,19 @@ describe('PythonShell', function () {
117117 before ( ( ) => {
118118 PythonShell . defaultOptions = { } ;
119119 } )
120- it ( 'should be able to execute a string of python code' , function ( done ) {
120+ it ( 'should be able to execute a string of python code using callbacks ' , function ( done ) {
121121 PythonShell . runString ( 'print("hello");print("world")' , null , function ( err , results ) {
122122 if ( err ) return done ( err ) ;
123123 results . should . be . an . Array ( ) . and . have . lengthOf ( 2 ) ;
124124 results . should . eql ( [ 'hello' , 'world' ] ) ;
125125 done ( ) ;
126126 } ) ;
127127 } ) ;
128+ it ( 'should be able to execute a string of python code using promises' , async function ( ) {
129+ let results = await PythonShell . runString ( 'print("hello");print("world")' ) ;
130+ results . should . be . an . Array ( ) . and . have . lengthOf ( 2 ) ;
131+ results . should . eql ( [ 'hello' , 'world' ] ) ;
132+ } ) ;
128133 after ( ( ) => {
129134 PythonShell . defaultOptions = {
130135 // reset to match initial value
@@ -134,7 +139,7 @@ describe('PythonShell', function () {
134139 } ) ;
135140
136141 describe ( '#run(script, options)' , function ( ) {
137- it ( 'should run the script and return output data' , function ( done ) {
142+ it ( 'should run the script and return output data using callbacks ' , function ( done ) {
138143 PythonShell . run ( 'echo_args.py' , {
139144 args : [ 'hello' , 'world' ]
140145 } , function ( err , results ) {
@@ -144,13 +149,29 @@ describe('PythonShell', function () {
144149 done ( ) ;
145150 } ) ;
146151 } ) ;
152+ it ( 'should run the script and return output data using promise' , async function ( ) {
153+ let results = await PythonShell . run ( 'echo_args.py' , {
154+ args : [ 'hello' , 'world' ]
155+ } ) ;
156+ results . should . be . an . Array ( ) . and . have . lengthOf ( 2 ) ;
157+ results . should . eql ( [ 'hello' , 'world' ] ) ;
158+ } ) ;
147159 it ( 'should try to run the script and fail appropriately' , function ( done ) {
148160 PythonShell . run ( 'unknown_script.py' , null , function ( err , results ) {
149161 err . should . be . an . Error ;
150162 err . exitCode . should . be . exactly ( 2 ) ;
151163 done ( ) ;
152164 } ) ;
153165 } ) ;
166+ it ( 'should try to run the script and fail appropriately' , async function ( ) {
167+ try {
168+ let results = await PythonShell . run ( 'unknown_script.py' ) ;
169+ throw new Error ( `should not get here because the script should fail` + results ) ;
170+ } catch ( err ) {
171+ err . should . be . an . Error ;
172+ err . exitCode . should . be . exactly ( 2 ) ;
173+ }
174+ } ) ;
154175 it ( 'should include both output and error' , function ( done ) {
155176 PythonShell . run ( 'echo_hi_then_error.py' , null , function ( err , results ) {
156177 err . should . be . an . Error ;
0 commit comments