Skip to content

Commit 4ba8b5e

Browse files
committed
fixing #146
1 parent 074e55c commit 4ba8b5e

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class PythonShell extends EventEmitter{
113113
let pythonOptions = toArray(options.pythonOptions);
114114
let scriptArgs = toArray(options.args);
115115

116-
this.scriptPath = join(options.scriptPath || './', scriptPath);
116+
this.scriptPath = join(options.scriptPath || '', scriptPath);
117117
this.command = pythonOptions.concat(this.scriptPath, scriptArgs);
118118
this.mode = options.mode || 'text';
119119
this.formatter = resolve('format', options.formatter || this.mode);

test/test-python-shell.ts

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import * as should from 'should';
22
import {PythonShell} from '..'
3-
import {sep} from 'path'
3+
import {sep, join} from 'path'
44
import {EOL as newline} from 'os'
5+
import { chdir, cwd } from 'process';
56

67
describe('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

Comments
 (0)