summaryrefslogtreecommitdiffstats
path: root/tests/lang_base_test.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-09-04 09:08:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-09-04 09:08:20 +0000
commit6b73455b1719f4bfff006c7d9881935cc1e6a350 (patch)
tree393586e5ce18b866b8382c6a1ead7922d4b37039 /tests/lang_base_test.py
parentReleasing debian version 3.3.3-2. (diff)
downloadpre-commit-6b73455b1719f4bfff006c7d9881935cc1e6a350.tar.xz
pre-commit-6b73455b1719f4bfff006c7d9881935cc1e6a350.zip
Merging upstream version 3.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/lang_base_test.py')
-rw-r--r--tests/lang_base_test.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/lang_base_test.py b/tests/lang_base_test.py
index a532b6a..1cffa0e 100644
--- a/tests/lang_base_test.py
+++ b/tests/lang_base_test.py
@@ -30,6 +30,19 @@ def homedir_mck():
yield
+@pytest.fixture
+def no_sched_getaffinity():
+ # Simulates an OS without os.sched_getaffinity available (mac/windows)
+ # https://docs.python.org/3/library/os.html#interface-to-the-scheduler
+ with mock.patch.object(
+ os,
+ 'sched_getaffinity',
+ create=True,
+ side_effect=AttributeError,
+ ):
+ yield
+
+
def test_exe_exists_does_not_exist(find_exe_mck, homedir_mck):
find_exe_mck.return_value = None
assert lang_base.exe_exists('ruby') is False
@@ -116,7 +129,17 @@ def test_no_env_noop(tmp_path):
assert before == inside == after
-def test_target_concurrency_normal():
+def test_target_concurrency_sched_getaffinity(no_sched_getaffinity):
+ with mock.patch.object(
+ os,
+ 'sched_getaffinity',
+ return_value=set(range(345)),
+ ):
+ with mock.patch.dict(os.environ, clear=True):
+ assert lang_base.target_concurrency() == 345
+
+
+def test_target_concurrency_without_sched_getaffinity(no_sched_getaffinity):
with mock.patch.object(multiprocessing, 'cpu_count', return_value=123):
with mock.patch.dict(os.environ, {}, clear=True):
assert lang_base.target_concurrency() == 123
@@ -134,7 +157,7 @@ def test_target_concurrency_on_travis():
assert lang_base.target_concurrency() == 2
-def test_target_concurrency_cpu_count_not_implemented():
+def test_target_concurrency_cpu_count_not_implemented(no_sched_getaffinity):
with mock.patch.object(
multiprocessing, 'cpu_count', side_effect=NotImplementedError,
):