11
11
import signal
12
12
import sys
13
13
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
15
15
16
16
if is_linux :
17
17
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):
27
27
def test_000_run_me_first (self ):
28
28
WEIRD_CASES = { signal .SIGINT : signal .default_int_handler }
29
29
if is_posix :
30
- WEIRD_CASES [signal .SIGKILL ] = None
31
- WEIRD_CASES [signal .SIGSTOP ] = None
32
30
WEIRD_CASES [signal .SIGPIPE ] = signal .SIG_IGN
33
31
WEIRD_CASES [signal .SIGXFSZ ] = signal .SIG_IGN
32
+ if is_osx :
33
+ WEIRD_CASES [signal .SIGKILL ] = None
34
+ WEIRD_CASES [signal .SIGSTOP ] = None
34
35
35
36
for x in [x for x in SUPPORTED_SIGNALS ]:
36
37
with self .subTest (sig = x ):
37
38
self .assertEqual (signal .getsignal (x ), WEIRD_CASES .get (x , signal .SIG_DFL ))
38
39
40
+ # test that unsupported signals have no handler
39
41
for x in range (1 , signal .NSIG ):
40
42
if x in SUPPORTED_SIGNALS : continue
43
+ if is_linux and 35 <= x <= 64 : continue # Real-time signals
41
44
self .assertEqual (signal .getsignal (x ), None )
42
45
43
46
@@ -59,6 +62,9 @@ def test_module_constants(self):
59
62
60
63
# when run with CPython, this verifies that SIG_codes are correct and matching CPython
61
64
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
62
68
self .assertEqual (getattr (signal , sig ), SIG_codes [sig ])
63
69
64
70
@@ -77,19 +83,23 @@ def test_signal_signal_neg(self):
77
83
def a (b , c ):
78
84
pass
79
85
86
+ # test that unsupported signals raise OSError on trying to set a handler
80
87
for x in range (1 , signal .NSIG ):
81
88
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 ,
83
91
signal .signal , x , a )
84
92
85
93
for x in [- 2 , - 1 , 0 , signal .NSIG , signal .NSIG + 1 , signal .NSIG + 2 ]:
86
94
self .assertRaisesMessage (ValueError , "signal number out of range" ,
87
95
signal .signal , x , a )
88
96
97
+ # TODO
89
98
def bad_sig0 (): pass
90
99
def bad_sig1 (a ): pass
91
100
def bad_sig3 (a ,b ,c ): pass
92
101
102
+ # test that bad handler objects are caught with TypeError
93
103
for y in SUPPORTED_SIGNALS :
94
104
bad_handlers = [- 2 , - 1 , 2 , 3 , 4 , 10 , 22 , 23 , 24 , None ]
95
105
for x in bad_handlers :
0 commit comments