summaryrefslogtreecommitdiffstats
path: root/tests/lang_base_test.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-16 11:14:57 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-16 11:14:57 +0000
commitbdd97c38eaba207665d85bc1ad63341337f41ac6 (patch)
tree2b4ae82c13c4910fd431b44f17532d78deb375b8 /tests/lang_base_test.py
parentReleasing debian version 3.4.0-1. (diff)
downloadpre-commit-bdd97c38eaba207665d85bc1ad63341337f41ac6.tar.xz
pre-commit-bdd97c38eaba207665d85bc1ad63341337f41ac6.zip
Merging upstream version 3.5.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.py62
1 files changed, 16 insertions, 46 deletions
diff --git a/tests/lang_base_test.py b/tests/lang_base_test.py
index 1cffa0e..da289ae 100644
--- a/tests/lang_base_test.py
+++ b/tests/lang_base_test.py
@@ -1,6 +1,5 @@
from __future__ import annotations
-import multiprocessing
import os.path
import sys
from unittest import mock
@@ -10,6 +9,7 @@ import pytest
import pre_commit.constants as C
from pre_commit import lang_base
from pre_commit import parse_shebang
+from pre_commit import xargs
from pre_commit.prefix import Prefix
from pre_commit.util import CalledProcessError
@@ -30,19 +30,6 @@ 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
@@ -129,40 +116,23 @@ def test_no_env_noop(tmp_path):
assert before == inside == after
-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
-
-
-def test_target_concurrency_testing_env_var():
- with mock.patch.dict(
- os.environ, {'PRE_COMMIT_NO_CONCURRENCY': '1'}, clear=True,
- ):
- assert lang_base.target_concurrency() == 1
-
-
-def test_target_concurrency_on_travis():
- with mock.patch.dict(os.environ, {'TRAVIS': '1'}, clear=True):
- assert lang_base.target_concurrency() == 2
+@pytest.fixture
+def cpu_count_mck():
+ with mock.patch.object(xargs, 'cpu_count', return_value=4):
+ yield
-def test_target_concurrency_cpu_count_not_implemented(no_sched_getaffinity):
- with mock.patch.object(
- multiprocessing, 'cpu_count', side_effect=NotImplementedError,
- ):
- with mock.patch.dict(os.environ, {}, clear=True):
- assert lang_base.target_concurrency() == 1
+@pytest.mark.parametrize(
+ ('var', 'expected'),
+ (
+ ('PRE_COMMIT_NO_CONCURRENCY', 1),
+ ('TRAVIS', 2),
+ (None, 4),
+ ),
+)
+def test_target_concurrency(cpu_count_mck, var, expected):
+ with mock.patch.dict(os.environ, {var: '1'} if var else {}, clear=True):
+ assert lang_base.target_concurrency() == expected
def test_shuffled_is_deterministic():