mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-20 01:24:42 +04:00
Merge pull request #2772 from pre-commit/run-language-for-repository-test
use run_language for repository_test
This commit is contained in:
commit
1054afd978
2 changed files with 19 additions and 18 deletions
|
|
@ -16,6 +16,8 @@ def run_language(
|
||||||
version: str | None = None,
|
version: str | None = None,
|
||||||
deps: Sequence[str] = (),
|
deps: Sequence[str] = (),
|
||||||
is_local: bool = False,
|
is_local: bool = False,
|
||||||
|
require_serial: bool = True,
|
||||||
|
color: bool = False,
|
||||||
) -> tuple[int, bytes]:
|
) -> tuple[int, bytes]:
|
||||||
prefix = Prefix(str(path))
|
prefix = Prefix(str(path))
|
||||||
version = version or language.get_default_version()
|
version = version or language.get_default_version()
|
||||||
|
|
@ -31,8 +33,8 @@ def run_language(
|
||||||
args,
|
args,
|
||||||
file_args,
|
file_args,
|
||||||
is_local=is_local,
|
is_local=is_local,
|
||||||
require_serial=True,
|
require_serial=require_serial,
|
||||||
color=False,
|
color=color,
|
||||||
)
|
)
|
||||||
out = out.replace(b'\r\n', b'\n')
|
out = out.replace(b'\r\n', b'\n')
|
||||||
return ret, out
|
return ret, out
|
||||||
|
|
|
||||||
|
|
@ -25,21 +25,20 @@ from pre_commit.util import cmd_output_b
|
||||||
from testing.fixtures import make_config_from_repo
|
from testing.fixtures import make_config_from_repo
|
||||||
from testing.fixtures import make_repo
|
from testing.fixtures import make_repo
|
||||||
from testing.fixtures import modify_manifest
|
from testing.fixtures import modify_manifest
|
||||||
|
from testing.language_helpers import run_language
|
||||||
from testing.util import cwd
|
from testing.util import cwd
|
||||||
from testing.util import get_resource_path
|
from testing.util import get_resource_path
|
||||||
|
|
||||||
|
|
||||||
def _norm_out(b):
|
|
||||||
return b.replace(b'\r\n', b'\n')
|
|
||||||
|
|
||||||
|
|
||||||
def _hook_run(hook, filenames, color):
|
def _hook_run(hook, filenames, color):
|
||||||
with languages[hook.language].in_env(hook.prefix, hook.language_version):
|
return run_language(
|
||||||
return languages[hook.language].run_hook(
|
path=hook.prefix.prefix_dir,
|
||||||
hook.prefix,
|
language=languages[hook.language],
|
||||||
hook.entry,
|
exe=hook.entry,
|
||||||
hook.args,
|
args=hook.args,
|
||||||
filenames,
|
file_args=filenames,
|
||||||
|
version=hook.language_version,
|
||||||
|
deps=hook.additional_dependencies,
|
||||||
is_local=hook.src == 'local',
|
is_local=hook.src == 'local',
|
||||||
require_serial=hook.require_serial,
|
require_serial=hook.require_serial,
|
||||||
color=color,
|
color=color,
|
||||||
|
|
@ -77,7 +76,7 @@ def _test_hook_repo(
|
||||||
hook = _get_hook(config, store, hook_id)
|
hook = _get_hook(config, store, hook_id)
|
||||||
ret, out = _hook_run(hook, args, color=color)
|
ret, out = _hook_run(hook, args, color=color)
|
||||||
assert ret == expected_return_code
|
assert ret == expected_return_code
|
||||||
assert _norm_out(out) == expected
|
assert out == expected
|
||||||
|
|
||||||
|
|
||||||
def test_python_hook(tempdir_factory, store):
|
def test_python_hook(tempdir_factory, store):
|
||||||
|
|
@ -425,7 +424,7 @@ def test_local_python_repo(store, local_python_config):
|
||||||
assert hook.language_version != C.DEFAULT
|
assert hook.language_version != C.DEFAULT
|
||||||
ret, out = _hook_run(hook, ('filename',), color=False)
|
ret, out = _hook_run(hook, ('filename',), color=False)
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert _norm_out(out) == b"['filename']\nHello World\n"
|
assert out == b"['filename']\nHello World\n"
|
||||||
|
|
||||||
|
|
||||||
def test_default_language_version(store, local_python_config):
|
def test_default_language_version(store, local_python_config):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue