##// END OF EJS Templates
Test process exit codes with terminating signal
Thomas Kluyver -
Show More
@@ -22,6 +22,7 b' Authors'
22 22 # stdlib
23 23 import ast
24 24 import os
25 import signal
25 26 import shutil
26 27 import sys
27 28 import tempfile
@@ -425,26 +426,48 b' class TestSafeExecfileNonAsciiPath(unittest.TestCase):'
425 426 """
426 427 ip.safe_execfile(self.fname, {}, raise_exceptions=True)
427 428
429 class ExitCodeChecks(tt.TempFileMixin):
430 def test_exit_code_ok(self):
431 self.system('exit 0')
432 self.assertEqual(ip.user_ns['_exit_code'], 0)
433
434 def test_exit_code_error(self):
435 self.system('exit 1')
436 self.assertEqual(ip.user_ns['_exit_code'], 1)
437
438 @skipif(not hasattr(signal, 'SIGALRM'))
439 def test_exit_code_signal(self):
440 self.mktmp("import signal, time\n"
441 "signal.setitimer(signal.ITIMER_REAL, 0.1)\n"
442 "time.sleep(1)\n")
443 self.system("%s %s" % (sys.executable, self.fname))
444 self.assertEqual(ip.user_ns['_exit_code'], -signal.SIGALRM)
445
446 class TestSystemRaw(unittest.TestCase, ExitCodeChecks):
447 system = ip.system_raw
428 448
429 class TestSystemRaw(unittest.TestCase):
430 449 @onlyif_unicode_paths
431 450 def test_1(self):
432 451 """Test system_raw with non-ascii cmd
433 452 """
434 cmd = ur'''python -c "'åäö'" '''
453 cmd = u'''python -c "'åäö'" '''
435 454 ip.system_raw(cmd)
436 455
437 def test_exit_code(self):
438 """Test that the exit code is parsed correctly."""
439 ip.system_raw('exit 1')
440 self.assertEqual(ip.user_ns['_exit_code'], 1)
441
442 class TestSystemPiped(unittest.TestCase):
443 456 # TODO: Exit codes are currently ignored on Windows.
457 class TestSystemPipedExitCode(unittest.TestCase, ExitCodeChecks):
458 system = ip.system_piped
459
444 460 @skip_win32
445 def test_exit_code(self):
446 ip.system_piped('exit 1')
447 self.assertEqual(ip.user_ns['_exit_code'], 1)
461 def test_exit_code_ok(self):
462 ExitCodeChecks.test_exit_code_ok(self)
463
464 @skip_win32
465 def test_exit_code_error(self):
466 ExitCodeChecks.test_exit_code_error(self)
467
468 @skip_win32
469 def test_exit_code_signal(self):
470 ExitCodeChecks.test_exit_code_signal(self)
448 471
449 472 class TestModules(unittest.TestCase, tt.TempFileMixin):
450 473 def test_extraneous_loads(self):
@@ -187,9 +187,9 b' class ProcessHandler(object):'
187 187
188 188 # We follow the subprocess pattern, returning either the exit status
189 189 # as a positive number, or the terminating signal as a negative
190 # number
191 if child.signalstatus is not None:
192 return -child.signalstatus
190 # number. sh returns 128+n for signals
191 if child.exitstatus > 128:
192 return -(child.exitstatus - 128)
193 193 return child.exitstatus
194 194
195 195
General Comments 0
You need to be logged in to leave comments. Login now