11var expect = require ( 'chai' ) . expect ;
22var runner = require ( '../runner' ) ;
3+ const exec = require ( 'child_process' ) . exec ;
34
45describe ( '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+
518 // These specs are compatible with both Python 2 and 3
619 [ '2' , '3' , '3.6' ] . forEach ( lv => {
720 describe ( '.run' , function ( ) {
@@ -178,7 +191,12 @@ describe('python runner', function() {
178191 ] . join ( '\n' ) ,
179192 testFramework : 'unittest'
180193 } , 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+ }
182200 done ( ) ;
183201 } ) ;
184202 } ) ;
@@ -187,6 +205,18 @@ describe('python runner', function() {
187205} ) ;
188206
189207describe ( '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+
190220 for ( const v of [ '2' , '3' , '3.6' ] ) {
191221 it ( `should be on independent lines (Python${ v } cw-2)` , function ( done ) {
192222 runner . run ( {
@@ -225,3 +255,127 @@ describe('Output format commands', function() {
225255 } ) ;
226256 }
227257} ) ;
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