1111import signal
1212import sys
1313
14- from iptest import IronPythonTestCase , is_windows , is_posix , is_osx , is_linux , run_test
14+ from iptest import IronPythonTestCase , is_cli , is_windows , is_posix , is_osx , is_linux , run_test
1515
1616if is_linux :
1717 SIG_codes = {'SIGABRT' : 6 , 'SIGALRM' : 14 , 'SIGBUS' : 7 , 'SIGCHLD' : 17 , 'SIGCLD' : 17 , 'SIGCONT' : 18 , 'SIGFPE' : 8 , 'SIGHUP' : 1 , 'SIGILL' : 4 , 'SIGINT' : 2 , 'SIGIO' : 29 , 'SIGIOT' : 6 , 'SIGKILL' : 9 , 'SIGPIPE' : 13 , 'SIGPOLL' : 29 , 'SIGPROF' : 27 , 'SIGPWR' : 30 , 'SIGQUIT' : 3 , 'SIGRTMAX' : 64 , 'SIGRTMIN' : 34 , 'SIGSEGV' : 11 , 'SIGSTKFLT' : 16 , 'SIGSTOP' : 19 , 'SIGSYS' : 31 , 'SIGTERM' : 15 , 'SIGTRAP' : 5 , 'SIGTSTP' : 20 , 'SIGTTIN' : 21 , 'SIGTTOU' : 22 , 'SIGURG' : 23 , 'SIGUSR1' : 10 , 'SIGUSR2' : 12 , 'SIGVTALRM' : 26 , 'SIGWINCH' : 28 , 'SIGXCPU' : 24 , 'SIGXFSZ' : 25 }
@@ -27,17 +27,20 @@ class SignalTest(IronPythonTestCase):
2727 def test_000_run_me_first (self ):
2828 WEIRD_CASES = { signal .SIGINT : signal .default_int_handler }
2929 if is_posix :
30- WEIRD_CASES [signal .SIGKILL ] = None
31- WEIRD_CASES [signal .SIGSTOP ] = None
3230 WEIRD_CASES [signal .SIGPIPE ] = signal .SIG_IGN
3331 WEIRD_CASES [signal .SIGXFSZ ] = signal .SIG_IGN
32+ if is_osx :
33+ WEIRD_CASES [signal .SIGKILL ] = None
34+ WEIRD_CASES [signal .SIGSTOP ] = None
3435
3536 for x in [x for x in SUPPORTED_SIGNALS ]:
3637 with self .subTest (sig = x ):
3738 self .assertEqual (signal .getsignal (x ), WEIRD_CASES .get (x , signal .SIG_DFL ))
3839
40+ # test that unsupported signals have no handler
3941 for x in range (1 , signal .NSIG ):
4042 if x in SUPPORTED_SIGNALS : continue
43+ if is_linux and 35 <= x <= 64 : continue # Real-time signals
4144 self .assertEqual (signal .getsignal (x ), None )
4245
4346
@@ -59,6 +62,9 @@ def test_module_constants(self):
5962
6063 # when run with CPython, this verifies that SIG_codes are correct and matching CPython
6164 for sig in SIG_codes :
65+ if sys .version_info < (3 , 11 ) and not is_cli and sig == 'SIGSTKFLT' :
66+ # SIGSTKFLT is not defined in CPython < 3.11
67+ continue
6268 self .assertEqual (getattr (signal , sig ), SIG_codes [sig ])
6369
6470
@@ -77,19 +83,23 @@ def test_signal_signal_neg(self):
7783 def a (b , c ):
7884 pass
7985
86+ # test that unsupported signals raise OSError on trying to set a handler
8087 for x in range (1 , signal .NSIG ):
8188 if x in SUPPORTED_SIGNALS : continue
82- self .assertRaises (ValueError ,
89+ if is_linux and 35 <= x <= 64 : continue # Real-time signals
90+ self .assertRaises (OSError ,
8391 signal .signal , x , a )
8492
8593 for x in [- 2 , - 1 , 0 , signal .NSIG , signal .NSIG + 1 , signal .NSIG + 2 ]:
8694 self .assertRaisesMessage (ValueError , "signal number out of range" ,
8795 signal .signal , x , a )
8896
97+ # TODO
8998 def bad_sig0 (): pass
9099 def bad_sig1 (a ): pass
91100 def bad_sig3 (a ,b ,c ): pass
92101
102+ # test that bad handler objects are caught with TypeError
93103 for y in SUPPORTED_SIGNALS :
94104 bad_handlers = [- 2 , - 1 , 2 , 3 , 4 , 10 , 22 , 23 , 24 , None ]
95105 for x in bad_handlers :
0 commit comments