Skip to content

Commit a2c79a3

Browse files
committed
formatting & remove deprecated buffer
1 parent aefada7 commit a2c79a3

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

test/test-python-shell.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as should from 'should';
2-
import {PythonShell} from '..'
3-
import {sep, join} from 'path'
4-
import {EOL as newline} from 'os'
2+
import { PythonShell } from '..'
3+
import { sep, join } from 'path'
4+
import { EOL as newline } from 'os'
55
import { chdir, cwd } from 'process';
66

77
describe('PythonShell', function () {
@@ -58,8 +58,8 @@ describe('PythonShell', function () {
5858
it('should fail to spawn python with bad path', function (done) {
5959
let pyshell = new PythonShell('exit-code.py', {
6060
pythonPath: 'foeisjofseij'
61-
}, );
62-
pyshell.on('error', (err)=>{
61+
});
62+
pyshell.on('error', (err) => {
6363
err.code.should.eql('ENOENT')
6464
done()
6565
})
@@ -78,14 +78,14 @@ describe('PythonShell', function () {
7878
// note checkSyntax is a wrapper around checkSyntaxFile
7979
// so this tests checkSyntaxFile as well
8080

81-
it('should check syntax', function ( done) {
82-
PythonShell.checkSyntax("x=1").then(()=>{
81+
it('should check syntax', function (done) {
82+
PythonShell.checkSyntax("x=1").then(() => {
8383
done();
8484
})
8585
})
8686

87-
it('should invalidate bad syntax', function ( done) {
88-
PythonShell.checkSyntax("x=").catch(()=>{
87+
it('should invalidate bad syntax', function (done) {
88+
PythonShell.checkSyntax("x=").catch(() => {
8989
done();
9090
})
9191
})
@@ -114,7 +114,7 @@ describe('PythonShell', function () {
114114
// })
115115

116116
describe('#runString(script, options)', function () {
117-
before(()=>{
117+
before(() => {
118118
PythonShell.defaultOptions = {};
119119
})
120120
it('should be able to execute a string of python code', function (done) {
@@ -125,7 +125,7 @@ describe('PythonShell', function () {
125125
done();
126126
});
127127
});
128-
after(()=>{
128+
after(() => {
129129
PythonShell.defaultOptions = {
130130
// reset to match initial value
131131
scriptPath: pythonFolder
@@ -167,7 +167,7 @@ describe('PythonShell', function () {
167167
});
168168
});
169169
it('should run the script and fail with an extended stack trace even when mode is binary', function (done) {
170-
PythonShell.run('error.py', {mode: "binary"}, function (err, results) {
170+
PythonShell.run('error.py', { mode: "binary" }, function (err, results) {
171171
err.should.be.an.Error;
172172
err.exitCode.should.be.exactly(1);
173173
err.stack.should.containEql('----- Python Traceback -----');
@@ -183,7 +183,7 @@ describe('PythonShell', function () {
183183
function end() {
184184
count++;
185185
if (count === numberOfTimesToRun) {
186-
done();
186+
done();
187187
}
188188
}
189189
function runSingleErrorScript(callback) {
@@ -205,7 +205,7 @@ describe('PythonShell', function () {
205205
function end() {
206206
count++;
207207
if (count === numberOfTimesToRun) {
208-
done();
208+
done();
209209
}
210210
}
211211
function runSingleScript(callback) {
@@ -220,10 +220,10 @@ describe('PythonShell', function () {
220220
}
221221

222222
});
223-
224-
it('should be able to run modules', function(done){
223+
224+
it('should be able to run modules', function (done) {
225225
PythonShell.defaultOptions = {};
226-
226+
227227
PythonShell.run('-m', {
228228
args: ['timeit', '-n 1', `'x=5'`]
229229
}, function (err, results) {
@@ -236,12 +236,12 @@ describe('PythonShell', function () {
236236
if (err) return done(err);
237237
results.should.be.an.Array();
238238
results[0].should.be.an.String();
239-
results[0].slice(0,6).should.eql('1 loop');
239+
results[0].slice(0, 6).should.eql('1 loop');
240240
done();
241241
});
242242
})
243243

244-
after(()=>{
244+
after(() => {
245245
// should be able to run modules test should theoretically reset this
246246
// but we have this to in case something goes horribly wrong with the test
247247
PythonShell.defaultOptions = {
@@ -263,7 +263,7 @@ describe('PythonShell', function () {
263263
should(pyshell.stdin).be.eql(null);
264264
should(pyshell.stdout).be.eql(null);
265265
should(pyshell.stderr).be.eql(null);
266-
should.throws(() => {pyshell.send("asd")});
266+
should.throws(() => { pyshell.send("asd") });
267267
});
268268
});
269269

@@ -274,11 +274,11 @@ describe('PythonShell', function () {
274274
});
275275
let output = '';
276276
pyshell.stdout.on('data', function (data) {
277-
output += ''+data;
277+
output += '' + data;
278278
});
279279
pyshell.send('hello').send('world').end(function (err) {
280280
if (err) return done(err);
281-
output.should.be.exactly('hello'+newline+'world'+newline);
281+
output.should.be.exactly('hello' + newline + 'world' + newline);
282282
done();
283283
});
284284
});
@@ -288,11 +288,11 @@ describe('PythonShell', function () {
288288
});
289289
let output = '';
290290
pyshell.stdout.on('data', function (data) {
291-
output += ''+data;
291+
output += '' + data;
292292
});
293293
pyshell.send({ a: 'b' }).send(null).send([1, 2, 3]).end(function (err) {
294294
if (err) return done(err);
295-
output.should.be.exactly('{"a": "b"}'+newline+'null'+newline+'[1, 2, 3]'+newline);
295+
output.should.be.exactly('{"a": "b"}' + newline + 'null' + newline + '[1, 2, 3]' + newline);
296296
done();
297297
});
298298
});
@@ -304,11 +304,11 @@ describe('PythonShell', function () {
304304
});
305305
let output = '';
306306
pyshell.stdout.on('data', function (data) {
307-
output += ''+data;
307+
output += '' + data;
308308
});
309309
pyshell.send('hello').send('world').end(function (err) {
310310
if (err) return done(err);
311-
output.should.be.exactly('HELLO'+newline+'WORLD'+newline+'');
311+
output.should.be.exactly('HELLO' + newline + 'WORLD' + newline + '');
312312
done();
313313
});
314314
});
@@ -318,9 +318,9 @@ describe('PythonShell', function () {
318318
});
319319
let output = '';
320320
pyshell.stdout.on('data', function (data) {
321-
output += ''+data;
321+
output += '' + data;
322322
});
323-
pyshell.send(new Buffer('i am not a string')).end(function (err) {
323+
pyshell.send(Buffer.from('i am not a string')).end(function (err) {
324324
if (err) return done(err);
325325
output.should.be.exactly('i am not a string');
326326
done();
@@ -364,7 +364,7 @@ describe('PythonShell', function () {
364364
pyshell.on('message', function (message) {
365365
message.should.be.an.Object;
366366
message.should.eql({ a: true });
367-
}).receive('{"a"').receive(':').receive('true}'+newline+'').end(done);
367+
}).receive('{"a"').receive(':').receive('true}' + newline + '').end(done);
368368
});
369369
it('should not be invoked when mode is "binary"', function (done) {
370370
let pyshell = new PythonShell('echo_args.py', {
@@ -440,7 +440,7 @@ describe('PythonShell', function () {
440440
describe('.end(callback)', function () {
441441
it('should end normally when exit code is zero', function (done) {
442442
let pyshell = new PythonShell('exit-code.py');
443-
pyshell.end(function (err,code,signal) {
443+
pyshell.end(function (err, code, signal) {
444444
if (err) return done(err);
445445
code.should.be.exactly(0);
446446
done();
@@ -461,7 +461,7 @@ describe('PythonShell', function () {
461461
it('should emit error when the program exits because of an unhandled exception', function (done) {
462462
let pyshell = new PythonShell('error.py');
463463
pyshell.on('pythonError', function (err) {
464-
err.message.should.be.equalOneOf('ZeroDivisionError: integer division or modulo by zero','ZeroDivisionError: division by zero');
464+
err.message.should.be.equalOneOf('ZeroDivisionError: integer division or modulo by zero', 'ZeroDivisionError: division by zero');
465465
err.should.have.property('traceback');
466466
err.traceback.should.containEql('Traceback (most recent call last)');
467467
done();
@@ -472,7 +472,7 @@ describe('PythonShell', function () {
472472
pyshell.on('pythonError', function (err) {
473473
done(new Error("an error should not have been raised"));
474474
});
475-
pyshell.on('close', function(){
475+
pyshell.on('close', function () {
476476
done();
477477
})
478478
});
@@ -509,7 +509,7 @@ describe('PythonShell', function () {
509509
it('run the end callback if specified', function (done) {
510510
let pyshell = new PythonShell('infinite_loop.py');
511511
let endCalled = false;
512-
pyshell.end(()=>{
512+
pyshell.end(() => {
513513
endCalled = true;
514514
})
515515
pyshell.terminate();
@@ -519,12 +519,12 @@ describe('PythonShell', function () {
519519
it('terminate with correct kill signal', function (done) {
520520
let pyshell = new PythonShell('infinite_loop.py');
521521
let endCalled = false;
522-
pyshell.end(()=>{
522+
pyshell.end(() => {
523523
endCalled = true;
524524
})
525525
pyshell.terminate('SIGKILL');
526526
pyshell.terminated.should.be.true;
527-
setTimeout(()=>{pyshell.exitSignal.should.be.exactly('SIGKILL');},500);
527+
setTimeout(() => { pyshell.exitSignal.should.be.exactly('SIGKILL'); }, 500);
528528
done();
529529
});
530530
});

0 commit comments

Comments
 (0)