1
1
var expect = require ( 'chai' ) . expect ;
2
2
var runner = require ( '../runner' ) ;
3
+ const exec = require ( 'child_process' ) . exec ;
3
4
4
5
describe ( 'python runner' , function ( ) {
6
+ afterEach ( function cleanup ( done ) {
7
+ exec ( [
8
+ 'rm -rf' ,
9
+ '/home/codewarrior/*.py' ,
10
+ '/home/codewarrior/__pycache__' ,
11
+ '/home/codewarrior/test' ,
12
+ ] . join ( ' ' ) , function ( err ) {
13
+ if ( err ) return done ( err ) ;
14
+ return done ( ) ;
15
+ } ) ;
16
+ } ) ;
17
+
5
18
// These specs are compatible with both Python 2 and 3
6
19
[ '2' , '3' , '3.6' ] . forEach ( lv => {
7
20
describe ( '.run' , function ( ) {
@@ -178,7 +191,12 @@ describe('python runner', function() {
178
191
] . join ( '\n' ) ,
179
192
testFramework : 'unittest'
180
193
} , function ( buffer ) {
181
- expect ( buffer . stdout ) . to . contain ( '\n<ERROR::>Unhandled Exception: exceptions are my favorite, I always throw them\n' ) ;
194
+ if ( lv . startsWith ( '3' ) ) {
195
+ expect ( buffer . stdout ) . to . contain ( '\n<ERROR::>Unhandled Exception' ) ;
196
+ }
197
+ else {
198
+ expect ( buffer . stdout ) . to . contain ( '\n<ERROR::>Unhandled Exception: exceptions are my favorite, I always throw them\n' ) ;
199
+ }
182
200
done ( ) ;
183
201
} ) ;
184
202
} ) ;
@@ -187,6 +205,18 @@ describe('python runner', function() {
187
205
} ) ;
188
206
189
207
describe ( 'Output format commands' , function ( ) {
208
+ afterEach ( function cleanup ( done ) {
209
+ exec ( [
210
+ 'rm -rf' ,
211
+ '/home/codewarrior/*.py' ,
212
+ '/home/codewarrior/__pycache__' ,
213
+ '/home/codewarrior/test' ,
214
+ ] . join ( ' ' ) , function ( err ) {
215
+ if ( err ) return done ( err ) ;
216
+ return done ( ) ;
217
+ } ) ;
218
+ } ) ;
219
+
190
220
for ( const v of [ '2' , '3' , '3.6' ] ) {
191
221
it ( `should be on independent lines (Python${ v } cw-2)` , function ( done ) {
192
222
runner . run ( {
@@ -225,3 +255,127 @@ describe('Output format commands', function() {
225
255
} ) ;
226
256
}
227
257
} ) ;
258
+
259
+ describe ( 'unittest no concat' , function ( ) {
260
+ afterEach ( function cleanup ( done ) {
261
+ exec ( [
262
+ 'rm -rf' ,
263
+ '/home/codewarrior/*.py' ,
264
+ '/home/codewarrior/__pycache__' ,
265
+ '/home/codewarrior/test' ,
266
+ ] . join ( ' ' ) , function ( err ) {
267
+ if ( err ) return done ( err ) ;
268
+ return done ( ) ;
269
+ } ) ;
270
+ } ) ;
271
+
272
+ for ( const v of [ '3.x' , '3.6' ] ) {
273
+ it ( `should handle a basic assertion (${ v } )` , function ( done ) {
274
+ runner . run ( {
275
+ language : 'python' ,
276
+ languageVersion : v ,
277
+ testFramework : 'unittest' ,
278
+ solution : [
279
+ 'def add(a, b): return a + b'
280
+ ] . join ( '\n' ) ,
281
+ fixture : [
282
+ // Test class name is no longer restricted.
283
+ 'class TestAddition(unittest.TestCase):' ,
284
+ ' def test_add(self):' ,
285
+ ' self.assertEqual(add(1, 1), 2)'
286
+ ] . join ( '\n' ) ,
287
+ } , function ( buffer ) {
288
+ expect ( buffer . stdout ) . to . contain ( '\n<PASSED::>' ) ;
289
+ done ( ) ;
290
+ } ) ;
291
+ } ) ;
292
+
293
+ it ( `should handle a failed assetion (${ v } )` , function ( done ) {
294
+ runner . run ( {
295
+ language : 'python' ,
296
+ languageVersion : v ,
297
+ testFramework : 'unittest' ,
298
+ solution : [
299
+ 'def add(a, b): return a - b'
300
+ ] . join ( '\n' ) ,
301
+ fixture : [
302
+ 'class TestAddition(unittest.TestCase):' ,
303
+ ' def test_add(self):' ,
304
+ ' self.assertEqual(add(1, 1), 2)' ,
305
+ ''
306
+ ] . join ( '\n' ) ,
307
+ } , function ( buffer ) {
308
+ expect ( buffer . stdout ) . to . contain ( '\n<FAILED::>' ) ;
309
+ done ( ) ;
310
+ } ) ;
311
+ } ) ;
312
+
313
+ it ( `syntax error in solution show line numbers (${ v } )` , function ( done ) {
314
+ runner . run ( {
315
+ language : 'python' ,
316
+ languageVersion : v ,
317
+ testFramework : 'unittest' ,
318
+ solution : [
319
+ 'def add(a, b): return a b'
320
+ ] . join ( '\n' ) ,
321
+ fixture : [
322
+ 'class TestAddition(unittest.TestCase):' ,
323
+ ' def test_add(self):' ,
324
+ ' self.assertEqual(add(1, 1), 2)' ,
325
+ ''
326
+ ] . join ( '\n' ) ,
327
+ } , function ( buffer ) {
328
+ expect ( buffer . stdout ) . to . contain ( '\n<ERROR::>' ) ;
329
+ expect ( buffer . stdout ) . to . contain ( 'solution.py", line 1' ) ;
330
+ expect ( buffer . stdout ) . to . contain ( 'SyntaxError' ) ;
331
+ done ( ) ;
332
+ } ) ;
333
+ } ) ;
334
+
335
+ it ( `should handle error (${ v } )` , function ( done ) {
336
+ runner . run ( {
337
+ language : 'python' ,
338
+ languageVersion : v ,
339
+ testFramework : 'unittest' ,
340
+ solution : [
341
+ 'def add(a, b): return a / b'
342
+ ] . join ( '\n' ) ,
343
+ fixture : [
344
+ 'class TestAddition(unittest.TestCase):' ,
345
+ ' def test_add(self):' ,
346
+ ' self.assertEqual(add(1, 0), 1)' ,
347
+ ''
348
+ ] . join ( '\n' ) ,
349
+ } , function ( buffer ) {
350
+ expect ( buffer . stdout ) . to . contain ( '\n<ERROR::>' ) ;
351
+ done ( ) ;
352
+ } ) ;
353
+ } ) ;
354
+
355
+ it ( `should handle tests in multiple suites (${ v } )` , function ( done ) {
356
+ // combined into one suite
357
+ runner . run ( {
358
+ language : 'python' ,
359
+ languageVersion : v ,
360
+ testFramework : 'unittest' ,
361
+ solution : [
362
+ 'def add(a, b): return a + b'
363
+ ] . join ( '\n' ) ,
364
+ fixture : [
365
+ 'class TestAddition1(unittest.TestCase):' ,
366
+ ' def test_add1(self):' ,
367
+ ' self.assertEqual(add(1, 1), 2)' ,
368
+ '' ,
369
+ 'class TestAddition2(unittest.TestCase):' ,
370
+ ' def test_add2(self):' ,
371
+ ' self.assertEqual(add(2, 2), 4)' ,
372
+ '' ,
373
+ ] . join ( '\n' ) ,
374
+ } , function ( buffer ) {
375
+ expect ( buffer . stdout ) . to . contain ( '\n<IT::>test_add1' ) ;
376
+ expect ( buffer . stdout ) . to . contain ( '\n<IT::>test_add2' ) ;
377
+ done ( ) ;
378
+ } ) ;
379
+ } ) ;
380
+ }
381
+ } ) ;
0 commit comments