11import * as should from 'should' ;
22import { PythonShell } from '..'
3- import { sep } from 'path'
3+ import { sep , join } from 'path'
44import { EOL as newline } from 'os'
5+ import { chdir , cwd } from 'process' ;
56
67describe ( 'PythonShell' , function ( ) {
78
9+ const pythonFolder = 'test/python'
10+
811 PythonShell . defaultOptions = {
9- scriptPath : './test/python'
12+ scriptPath : pythonFolder
1013 } ;
1114
1215 describe ( '#ctor(script, options)' , function ( ) {
@@ -20,6 +23,27 @@ describe('PythonShell', function () {
2023 done ( ) ;
2124 } ) ;
2225 } ) ;
26+ it ( 'should spawn a Python process even if scriptPath option is not specified' , function ( done ) {
27+ let originalDirectory = cwd ( )
28+ PythonShell . defaultOptions = { } ;
29+ chdir ( join ( __dirname , "python" ) ) ;
30+
31+ let pyshell = new PythonShell ( 'exit-code.py' ) ;
32+ pyshell . command . should . eql ( [ 'exit-code.py' ] ) ;
33+ pyshell . terminated . should . be . false ;
34+ pyshell . end ( function ( err ) {
35+ if ( err ) return done ( err ) ;
36+ pyshell . terminated . should . be . true ;
37+ done ( ) ;
38+ } ) ;
39+
40+ //reset values to intial status
41+ PythonShell . defaultOptions = {
42+ scriptPath : pythonFolder
43+ } ;
44+ chdir ( originalDirectory )
45+ } ) ;
46+ // executing python-shell with a absolute path is tested in runString suite
2347 it ( 'should spawn a Python process with options' , function ( done ) {
2448 let pyshell = new PythonShell ( 'exit-code.py' , {
2549 pythonOptions : [ '-u' ]
@@ -69,7 +93,7 @@ describe('PythonShell', function () {
6993 after ( ( ) => {
7094 PythonShell . defaultOptions = {
7195 // reset to match initial value
72- scriptPath : './test/python'
96+ scriptPath : pythonFolder
7397 } ;
7498 } )
7599 } ) ;
0 commit comments