mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-18 08:34:41 +04:00
move languages.all and languages.helpers out of languages
This commit is contained in:
parent
5bc56889e9
commit
d3883ce7f7
30 changed files with 274 additions and 282 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pre_commit.languages.all import languages
|
||||
from pre_commit.all_languages import languages
|
||||
|
||||
|
||||
def test_python_venv_is_an_alias_to_python():
|
||||
|
|
@ -8,8 +8,8 @@ from unittest import mock
|
|||
import pytest
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import lang_base
|
||||
from pre_commit import parse_shebang
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.prefix import Prefix
|
||||
from pre_commit.util import CalledProcessError
|
||||
|
||||
|
|
@ -32,42 +32,42 @@ def homedir_mck():
|
|||
|
||||
def test_exe_exists_does_not_exist(find_exe_mck, homedir_mck):
|
||||
find_exe_mck.return_value = None
|
||||
assert helpers.exe_exists('ruby') is False
|
||||
assert lang_base.exe_exists('ruby') is False
|
||||
|
||||
|
||||
def test_exe_exists_exists(find_exe_mck, homedir_mck):
|
||||
find_exe_mck.return_value = os.path.normpath('/usr/bin/ruby')
|
||||
assert helpers.exe_exists('ruby') is True
|
||||
assert lang_base.exe_exists('ruby') is True
|
||||
|
||||
|
||||
def test_exe_exists_false_if_shim(find_exe_mck, homedir_mck):
|
||||
find_exe_mck.return_value = os.path.normpath('/foo/shims/ruby')
|
||||
assert helpers.exe_exists('ruby') is False
|
||||
assert lang_base.exe_exists('ruby') is False
|
||||
|
||||
|
||||
def test_exe_exists_false_if_homedir(find_exe_mck, homedir_mck):
|
||||
find_exe_mck.return_value = os.path.normpath('/home/me/somedir/ruby')
|
||||
assert helpers.exe_exists('ruby') is False
|
||||
assert lang_base.exe_exists('ruby') is False
|
||||
|
||||
|
||||
def test_exe_exists_commonpath_raises_ValueError(find_exe_mck, homedir_mck):
|
||||
find_exe_mck.return_value = os.path.normpath('/usr/bin/ruby')
|
||||
with mock.patch.object(os.path, 'commonpath', side_effect=ValueError):
|
||||
assert helpers.exe_exists('ruby') is True
|
||||
assert lang_base.exe_exists('ruby') is True
|
||||
|
||||
|
||||
def test_exe_exists_true_when_homedir_is_slash(find_exe_mck):
|
||||
find_exe_mck.return_value = os.path.normpath('/usr/bin/ruby')
|
||||
with mock.patch.object(os.path, 'expanduser', return_value=os.sep):
|
||||
assert helpers.exe_exists('ruby') is True
|
||||
assert lang_base.exe_exists('ruby') is True
|
||||
|
||||
|
||||
def test_basic_get_default_version():
|
||||
assert helpers.basic_get_default_version() == C.DEFAULT
|
||||
assert lang_base.basic_get_default_version() == C.DEFAULT
|
||||
|
||||
|
||||
def test_basic_health_check():
|
||||
assert helpers.basic_health_check(Prefix('.'), 'default') is None
|
||||
assert lang_base.basic_health_check(Prefix('.'), 'default') is None
|
||||
|
||||
|
||||
def test_failed_setup_command_does_not_unicode_error():
|
||||
|
|
@ -79,12 +79,12 @@ def test_failed_setup_command_does_not_unicode_error():
|
|||
|
||||
# an assertion that this does not raise `UnicodeError`
|
||||
with pytest.raises(CalledProcessError):
|
||||
helpers.run_setup_cmd(Prefix('.'), (sys.executable, '-c', script))
|
||||
lang_base.setup_cmd(Prefix('.'), (sys.executable, '-c', script))
|
||||
|
||||
|
||||
def test_assert_no_additional_deps():
|
||||
with pytest.raises(AssertionError) as excinfo:
|
||||
helpers.assert_no_additional_deps('lang', ['hmmm'])
|
||||
lang_base.assert_no_additional_deps('lang', ['hmmm'])
|
||||
msg, = excinfo.value.args
|
||||
assert msg == (
|
||||
'for now, pre-commit does not support additional_dependencies for '
|
||||
|
|
@ -96,19 +96,19 @@ def test_assert_no_additional_deps():
|
|||
def test_target_concurrency_normal():
|
||||
with mock.patch.object(multiprocessing, 'cpu_count', return_value=123):
|
||||
with mock.patch.dict(os.environ, {}, clear=True):
|
||||
assert helpers.target_concurrency() == 123
|
||||
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 helpers.target_concurrency() == 1
|
||||
assert lang_base.target_concurrency() == 1
|
||||
|
||||
|
||||
def test_target_concurrency_on_travis():
|
||||
with mock.patch.dict(os.environ, {'TRAVIS': '1'}, clear=True):
|
||||
assert helpers.target_concurrency() == 2
|
||||
assert lang_base.target_concurrency() == 2
|
||||
|
||||
|
||||
def test_target_concurrency_cpu_count_not_implemented():
|
||||
|
|
@ -116,17 +116,17 @@ def test_target_concurrency_cpu_count_not_implemented():
|
|||
multiprocessing, 'cpu_count', side_effect=NotImplementedError,
|
||||
):
|
||||
with mock.patch.dict(os.environ, {}, clear=True):
|
||||
assert helpers.target_concurrency() == 1
|
||||
assert lang_base.target_concurrency() == 1
|
||||
|
||||
|
||||
def test_shuffled_is_deterministic():
|
||||
seq = [str(i) for i in range(10)]
|
||||
expected = ['4', '0', '5', '1', '8', '6', '2', '3', '7', '9']
|
||||
assert helpers._shuffled(seq) == expected
|
||||
assert lang_base._shuffled(seq) == expected
|
||||
|
||||
|
||||
def test_xargs_require_serial_is_not_shuffled():
|
||||
ret, out = helpers.run_xargs(
|
||||
ret, out = lang_base.run_xargs(
|
||||
('echo',), [str(i) for i in range(10)],
|
||||
require_serial=True,
|
||||
color=False,
|
||||
|
|
@ -6,9 +6,9 @@ import pytest
|
|||
import re_assert
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import lang_base
|
||||
from pre_commit.envcontext import envcontext
|
||||
from pre_commit.languages import golang
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.store import _make_local_repo
|
||||
from testing.language_helpers import run_language
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ ACTUAL_GET_DEFAULT_VERSION = golang.get_default_version.__wrapped__
|
|||
|
||||
@pytest.fixture
|
||||
def exe_exists_mck():
|
||||
with mock.patch.object(helpers, 'exe_exists') as mck:
|
||||
with mock.patch.object(lang_base, 'exe_exists') as mck:
|
||||
yield mck
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ import pytest
|
|||
import re_assert
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import lang_base
|
||||
from pre_commit.all_languages import languages
|
||||
from pre_commit.clientlib import CONFIG_SCHEMA
|
||||
from pre_commit.clientlib import load_manifest
|
||||
from pre_commit.hook import Hook
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.languages import python
|
||||
from pre_commit.languages.all import languages
|
||||
from pre_commit.prefix import Prefix
|
||||
from pre_commit.repository import _hook_installed
|
||||
from pre_commit.repository import all_hooks
|
||||
|
|
@ -275,7 +275,7 @@ def test_repository_state_compatibility(tempdir_factory, store, v):
|
|||
|
||||
config = make_config_from_repo(path)
|
||||
hook = _get_hook(config, store, 'foo')
|
||||
envdir = helpers.environment_dir(
|
||||
envdir = lang_base.environment_dir(
|
||||
hook.prefix,
|
||||
python.ENVIRONMENT_DIR,
|
||||
hook.language_version,
|
||||
|
|
@ -327,7 +327,7 @@ def test_control_c_control_c_on_install(tempdir_factory, store):
|
|||
# raise as well.
|
||||
with pytest.raises(MyKeyboardInterrupt):
|
||||
with mock.patch.object(
|
||||
helpers, 'run_setup_cmd', side_effect=MyKeyboardInterrupt,
|
||||
lang_base, 'setup_cmd', side_effect=MyKeyboardInterrupt,
|
||||
):
|
||||
with mock.patch.object(
|
||||
shutil, 'rmtree', side_effect=MyKeyboardInterrupt,
|
||||
|
|
@ -336,7 +336,7 @@ def test_control_c_control_c_on_install(tempdir_factory, store):
|
|||
|
||||
# Should have made an environment, however this environment is broken!
|
||||
hook, = hooks
|
||||
envdir = helpers.environment_dir(
|
||||
envdir = lang_base.environment_dir(
|
||||
hook.prefix,
|
||||
python.ENVIRONMENT_DIR,
|
||||
hook.language_version,
|
||||
|
|
@ -359,7 +359,7 @@ def test_invalidated_virtualenv(tempdir_factory, store):
|
|||
hook = _get_hook(config, store, 'foo')
|
||||
|
||||
# Simulate breaking of the virtualenv
|
||||
envdir = helpers.environment_dir(
|
||||
envdir = lang_base.environment_dir(
|
||||
hook.prefix,
|
||||
python.ENVIRONMENT_DIR,
|
||||
hook.language_version,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue