MCPcopy Create free account
hub / github.com/dask/dask / test_cpu_count_cgroups_v2

Function test_cpu_count_cgroups_v2

dask/tests/test_system.py:134–157  ·  view source on GitHub ↗
(quota, group_name, monkeypatch, monkeypatch_cpu_count)

Source from the content-addressed store, hash-verified

132@pytest.mark.parametrize("group_name", ["/", "/user.slice", "/user.slice/more.slice"])
133@pytest.mark.parametrize("quota", ["max", "2005"])
134def test_cpu_count_cgroups_v2(quota, group_name, monkeypatch, monkeypatch_cpu_count):
135 if not group_name.endswith("/"):
136 group_name = f"{group_name}/"
137
138 paths = {
139 "/proc/self/cgroup": io.StringIO(f"0::{group_name}"),
140 f"/sys/fs/cgroup{group_name}cpu.max": io.StringIO(f"{quota} 10"),
141 }
142 builtin_open = builtins.open
143
144 def myopen(path, *args, **kwargs):
145 if path in paths:
146 return paths.get(path)
147 return builtin_open(path, *args, **kwargs)
148
149 monkeypatch.setattr(builtins, "open", myopen)
150 monkeypatch.setattr(sys, "platform", "linux")
151
152 count = cpu_count()
153 if quota == "max":
154 assert count == 250
155 else:
156 # Rounds up
157 assert count == 201

Callers

nothing calls this directly

Calls 1

cpu_countFunction · 0.90

Tested by

no test coverage detected