@@ -30,6 +30,19 @@ def fake_expanduser(pth):
3030 yield
3131
3232
33+ @pytest .fixture
34+ def no_sched_getaffinity ():
35+ # Simulates an OS without os.sched_getaffinity available (mac/windows)
36+ # https://docs.python.org/3/library/os.html#interface-to-the-scheduler
37+ with mock .patch .object (
38+ os ,
39+ 'sched_getaffinity' ,
40+ create = True ,
41+ side_effect = AttributeError ,
42+ ):
43+ yield
44+
45+
3346def test_exe_exists_does_not_exist (find_exe_mck , homedir_mck ):
3447 find_exe_mck .return_value = None
3548 assert lang_base .exe_exists ('ruby' ) is False
@@ -116,7 +129,17 @@ def test_no_env_noop(tmp_path):
116129 assert before == inside == after
117130
118131
119- def test_target_concurrency_normal ():
132+ def test_target_concurrency_sched_getaffinity (no_sched_getaffinity ):
133+ with mock .patch .object (
134+ os ,
135+ 'sched_getaffinity' ,
136+ return_value = set (range (345 )),
137+ ):
138+ with mock .patch .dict (os .environ , clear = True ):
139+ assert lang_base .target_concurrency () == 345
140+
141+
142+ def test_target_concurrency_without_sched_getaffinity (no_sched_getaffinity ):
120143 with mock .patch .object (multiprocessing , 'cpu_count' , return_value = 123 ):
121144 with mock .patch .dict (os .environ , {}, clear = True ):
122145 assert lang_base .target_concurrency () == 123
@@ -134,7 +157,7 @@ def test_target_concurrency_on_travis():
134157 assert lang_base .target_concurrency () == 2
135158
136159
137- def test_target_concurrency_cpu_count_not_implemented ():
160+ def test_target_concurrency_cpu_count_not_implemented (no_sched_getaffinity ):
138161 with mock .patch .object (
139162 multiprocessing , 'cpu_count' , side_effect = NotImplementedError ,
140163 ):
0 commit comments