Issue #17914: Add os.cpu_count(). Patch by Yogesh Chaudhari, based on an

initial patch by Trent Nelson.
This commit is contained in:
Charles-Francois Natali 2013-05-20 14:40:46 +02:00
parent 93c6770c72
commit 44feda3cd0
6 changed files with 95 additions and 27 deletions

View file

@ -2216,6 +2216,15 @@ class OSErrorTests(unittest.TestCase):
else:
self.fail("No exception thrown by {}".format(func))
class CPUCountTests(unittest.TestCase):
def test_cpu_count(self):
cpus = os.cpu_count()
if cpus is not None:
self.assertIsInstance(cpus, int)
self.assertGreater(cpus, 0)
else:
self.skipTest("Could not determine the number of CPUs")
@support.reap_threads
def test_main():
support.run_unittest(
@ -2246,6 +2255,7 @@ def test_main():
TermsizeTests,
OSErrorTests,
RemoveDirsTests,
CPUCountTests,
)
if __name__ == "__main__":