2525requires_32b = unittest .skipUnless (sys .maxsize < 2 ** 32 ,
2626 'test is only meaningful on 32-bit builds' )
2727
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+
2840class PosixTester (unittest .TestCase ):
2941
3042 def setUp (self ):
@@ -1273,7 +1285,7 @@ def test_sched_priority(self):
12731285 self .assertRaises (OSError , posix .sched_get_priority_min , - 23 )
12741286 self .assertRaises (OSError , posix .sched_get_priority_max , - 23 )
12751287
1276- @unittest . skipUnless ( hasattr ( posix , 'sched_setscheduler' ), "can't change scheduler" )
1288+ @requires_sched
12771289 def test_get_and_set_scheduler_and_param (self ):
12781290 possible_schedulers = [sched for name , sched in posix .__dict__ .items ()
12791291 if name .startswith ("SCHED_" )]
@@ -1646,7 +1658,7 @@ def test_setsigdef_wrong_type(self):
16461658 [sys .executable , "-c" , "pass" ],
16471659 os .environ , setsigdef = [signal .NSIG , signal .NSIG + 1 ])
16481660
1649- @unittest . skipUnless ( hasattr ( posix , 'sched_setscheduler' ), "can't change scheduler" )
1661+ @requires_sched
16501662 def test_setscheduler_only_param (self ):
16511663 policy = os .sched_getscheduler (0 )
16521664 priority = os .sched_get_priority_min (policy )
@@ -1664,7 +1676,7 @@ def test_setscheduler_only_param(self):
16641676 )
16651677 self .assertEqual (os .waitpid (pid , 0 ), (pid , 0 ))
16661678
1667- @unittest . skipUnless ( hasattr ( posix , 'sched_setscheduler' ), "can't change scheduler" )
1679+ @requires_sched
16681680 def test_setscheduler_with_policy (self ):
16691681 policy = os .sched_getscheduler (0 )
16701682 priority = os .sched_get_priority_min (policy )
0 commit comments