@@ -30,6 +30,19 @@ def fake_expanduser(pth):
30
30
yield
31
31
32
32
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
+
33
46
def test_exe_exists_does_not_exist (find_exe_mck , homedir_mck ):
34
47
find_exe_mck .return_value = None
8000
35
48
assert lang_base .exe_exists ('ruby' ) is False
@@ -116,7 +129,17 @@ def test_no_env_noop(tmp_path):
116
129
assert before == inside == after
117
130
118
131
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 ):
120
143
with mock .patch .object (multiprocessing , 'cpu_count' , return_value = 123 ):
121
144
with mock .patch .dict (os .environ , {}, clear = True ):
122
145
assert lang_base .target_concurrency () == 123
@@ -134,7 +157,7 @@ def test_target_concurrency_on_travis():
134
157
assert lang_base .target_concurrency () == 2
135
158
136
159
137
- def test_target_concurrency_cpu_count_not_implemented ():
160
+ def test_target_concurrency_cpu_count_not_implemented (no_sched_getaffinity ):
138
161
with mock .patch .object (
139
162
multiprocessing , 'cpu_count' , side_effect = NotImplementedError ,
140
163
):
0 commit comments