Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Oct 1, 2023
1 parent 134ed9e commit 2bec7f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,7 @@ def add_dll_directory(path):
nt._remove_dll_directory
)


if _exists('sched_getaffinity') and os._get_cpu_config() < 0:
def process_cpu_count():
"""
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,15 @@ def test_cpu_count(self):
code = "import os; print(os.cpu_count(), os.process_cpu_count())"
res = assert_python_ok('-X', 'cpu_count=4321', '-c', code)
self.assertEqual(self.res2int(res), (4321, 4321))
res = assert_python_ok('-c', code, PYTHONCPUCOUNT='1234')
self.assertEqual(self.res2int(res), (1234, 1234))

def test_cpu_count_default(self):
code = "import os; print(os.cpu_count(), os.process_cpu_count())"
res = assert_python_ok('-X', 'cpu_count=default', '-c', code)
self.assertEqual(self.res2int(res), (os.cpu_count(), os.process_cpu_count()))
res = assert_python_ok('-X', 'cpu_count=default', '-c', code, PYTHONCPUCOUNT='1234')
self.assertEqual(self.res2int(res), (os.cpu_count(), os.process_cpu_count()))

def res2int(self, res):
out = res.out.strip().decode("utf-8")
Expand Down

0 comments on commit 2bec7f4

Please sign in to comment.