summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2018-09-12 23:00:27 (GMT)
committerGitHub <noreply@github.com>2018-09-12 23:00:27 (GMT)
commite105e551dbf072d773aaa1fd6f8cbda218c273f0 (patch)
treed38b36d68dd3a1831232a3a54dffa35ee29f7bfc
parent6d726868cd1743623a28b8e048e31b9c3c52a399 (diff)
downloadcpython-e105e551dbf072d773aaa1fd6f8cbda218c273f0.zip
cpython-e105e551dbf072d773aaa1fd6f8cbda218c273f0.tar.gz
cpython-e105e551dbf072d773aaa1fd6f8cbda218c273f0.tar.bz2
[3.6] closes bpo-34650: Check if sched_getscheduler returns ENOSYS before declaring it supported. (GH-9237)
musl doesn't support the scheduler API, but declares stubs that alway return ENOSYS.. (cherry picked from commit c7042224b8a67748f125c22836862483f81a87a6) Co-authored-by: Benjamin Peterson <benjamin@python.org>
-rw-r--r--Lib/test/test_posix.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index a204377..2dae473 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -22,6 +22,18 @@ _DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(),
requires_32b = unittest.skipUnless(sys.maxsize < 2**32,
'test is only meaningful on 32-bit builds')
+def _supports_sched():
+ if not hasattr(posix, 'sched_getscheduler'):
+ return False
+ try:
+ posix.sched_getscheduler(0)
+ except OSError as e:
+ if e.errno == errno.ENOSYS:
+ return False
+ return True
+
+requires_sched = unittest.skipUnless(_supports_sched(), 'requires POSIX scheduler API')
+
class PosixTester(unittest.TestCase):
def setUp(self):
@@ -1136,7 +1148,7 @@ class PosixTester(unittest.TestCase):
self.assertRaises(OSError, posix.sched_get_priority_min, -23)
self.assertRaises(OSError, posix.sched_get_priority_max, -23)
- @unittest.skipUnless(hasattr(posix, 'sched_setscheduler'), "can't change scheduler")
+ @requires_sched
def test_get_and_set_scheduler_and_param(self):
possible_schedulers = [sched for name, sched in posix.__dict__.items()
if name.startswith("SCHED_")]