Show More
@@ -22,6 +22,7 b' Authors' | |||||
22 | # stdlib |
|
22 | # stdlib | |
23 | import ast |
|
23 | import ast | |
24 | import os |
|
24 | import os | |
|
25 | import signal | |||
25 | import shutil |
|
26 | import shutil | |
26 | import sys |
|
27 | import sys | |
27 | import tempfile |
|
28 | import tempfile | |
@@ -425,26 +426,48 b' class TestSafeExecfileNonAsciiPath(unittest.TestCase):' | |||||
425 | """ |
|
426 | """ | |
426 | ip.safe_execfile(self.fname, {}, raise_exceptions=True) |
|
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 | @onlyif_unicode_paths |
|
449 | @onlyif_unicode_paths | |
431 | def test_1(self): |
|
450 | def test_1(self): | |
432 | """Test system_raw with non-ascii cmd |
|
451 | """Test system_raw with non-ascii cmd | |
433 | """ |
|
452 | """ | |
434 |
cmd = u |
|
453 | cmd = u'''python -c "'åäö'" ''' | |
435 | ip.system_raw(cmd) |
|
454 | ip.system_raw(cmd) | |
436 |
|
||||
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 |
|
455 | |||
442 | class TestSystemPiped(unittest.TestCase): |
|
456 | # TODO: Exit codes are currently ignored on Windows. | |
443 | # TODO: Exit codes are currently ignored on Windows. |
|
457 | class TestSystemPipedExitCode(unittest.TestCase, ExitCodeChecks): | |
|
458 | system = ip.system_piped | |||
|
459 | ||||
444 | @skip_win32 |
|
460 | @skip_win32 | |
445 | def test_exit_code(self): |
|
461 | def test_exit_code_ok(self): | |
446 | ip.system_piped('exit 1') |
|
462 | ExitCodeChecks.test_exit_code_ok(self) | |
447 | self.assertEqual(ip.user_ns['_exit_code'], 1) |
|
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 | class TestModules(unittest.TestCase, tt.TempFileMixin): |
|
472 | class TestModules(unittest.TestCase, tt.TempFileMixin): | |
450 | def test_extraneous_loads(self): |
|
473 | def test_extraneous_loads(self): |
@@ -187,9 +187,9 b' class ProcessHandler(object):' | |||||
187 |
|
187 | |||
188 | # We follow the subprocess pattern, returning either the exit status |
|
188 | # We follow the subprocess pattern, returning either the exit status | |
189 | # as a positive number, or the terminating signal as a negative |
|
189 | # as a positive number, or the terminating signal as a negative | |
190 | # number |
|
190 | # number. sh returns 128+n for signals | |
191 |
if child. |
|
191 | if child.exitstatus > 128: | |
192 |
return -child. |
|
192 | return -(child.exitstatus - 128) | |
193 | return child.exitstatus |
|
193 | return child.exitstatus | |
194 |
|
194 | |||
195 |
|
195 |
General Comments 0
You need to be logged in to leave comments.
Login now