1
1
import * as should from 'should' ;
2
2
import { PythonShell } from '..'
3
- import { sep } from 'path'
3
+ import { sep , join } from 'path'
4
4
import { EOL as newline } from 'os'
5
+ import { chdir , cwd } from 'process' ;
5
6
6
7
describe ( 'PythonShell' , function ( ) {
7
8
9
+ const pythonFolder = 'test/python'
10
+
8
11
PythonShell . defaultOptions = {
9
- scriptPath : './test/python'
12
+ scriptPath : pythonFolder
10
13
} ;
11
14
12
15
describe ( '#ctor(script, options)' , function ( ) {
@@ -20,6 +23,27 @@ describe('PythonShell', function () {
20
23
done ( ) ;
21
24
} ) ;
22
25
} ) ;
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
23
47
it ( 'should spawn a Python process with options' , function ( done ) {
24
48
let pyshell = new PythonShell ( 'exit-code.py' , {
25
49
pythonOptions : [ '-u' ]
@@ -69,7 +93,7 @@ describe('PythonShell', function () {
69
93
after ( ( ) => {
70
94
PythonShell . defaultOptions = {
71
95
// reset to match initial value
72
- scriptPath : './test/python'
96
+ scriptPath : pythonFolder
73
97
} ;
74
98
} )
75
99
} ) ;
0 commit comments