25
25
requires_32b = unittest .skipUnless (sys .maxsize < 2 ** 32 ,
26
26
'test is only meaningful on 32-bit builds' )
27
27
28
+ def _supports_sched ():
29
+ if not hasattr (posix , 'sched_getscheduler' ):
30
+ return False
31
+ try :
32
+ posix .sched_getscheduler (0 )
33
+ except OSError as e :
34
+ if e .errno == errno .ENOSYS :
35
+ return False
36
+ return True
37
+
38
+ requires_sched = unittest .skipUnless (_supports_sched (), 'requires POSIX scheduler API' )
39
+
28
40
class PosixTester (unittest .TestCase ):
29
41
30
42
def setUp (self ):
@@ -1273,7 +1285,7 @@ def test_sched_priority(self):
1273
1285
self .assertRaises (OSError , posix .sched_get_priority_min , - 23 )
1274
1286
self .assertRaises (OSError , posix .sched_get_priority_max , - 23 )
1275
1287
1276
- @unittest . skipUnless ( hasattr ( posix , 'sched_setscheduler' ), "can't change scheduler" )
1288
+ @requires_sched
1277
1289
def test_get_and_set_scheduler_and_param (self ):
1278
1290
possible_schedulers = [sched for name , sched in posix .__dict__ .items ()
1279
1291
if name .startswith ("SCHED_" )]
@@ -1646,7 +1658,7 @@ def test_setsigdef_wrong_type(self):
1646
1658
[sys .executable , "-c" , "pass" ],
1647
1659
os .environ , setsigdef = [signal .NSIG , signal .NSIG + 1 ])
1648
1660
1649
- @unittest . skipUnless ( hasattr ( posix , 'sched_setscheduler' ), "can't change scheduler" )
1661
+ @requires_sched
1650
1662
def test_setscheduler_only_param (self ):
1651
1663
policy = os .sched_getscheduler (0 )
1652
1664
priority = os .sched_get_priority_min (policy )
@@ -1664,7 +1676,7 @@ def test_setscheduler_only_param(self):
1664
1676
)
1665
1677
self .assertEqual (os .waitpid (pid , 0 ), (pid , 0 ))
1666
1678
1667
- @unittest . skipUnless ( hasattr ( posix , 'sched_setscheduler' ), "can't change scheduler" )
1679
+ @requires_sched
1668
1680
def test_setscheduler_with_policy (self ):
1669
1681
policy = os .sched_getscheduler (0 )
1670
1682
priority = os .sched_get_priority_min (policy )
0 commit comments