Skip to content

Commit

Permalink
use run_language for repository_test
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Feb 21, 2023
1 parent 4f6ba18 commit d23990c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
6 changes: 4 additions & 2 deletions testing/language_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def run_language(
version: str | None = None,
deps: Sequence[str] = (),
is_local: bool = False,
require_serial: bool = True,
color: bool = False,
) -> tuple[int, bytes]:
prefix = Prefix(str(path))
version = version or language.get_default_version()
Expand All @@ -31,8 +33,8 @@ def run_language(
args,
file_args,
is_local=is_local,
require_serial=True,
color=False,
require_serial=require_serial,
color=color,
)
out = out.replace(b'\r\n', b'\n')
return ret, out
31 changes: 15 additions & 16 deletions tests/repository_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,24 @@
from testing.fixtures import make_config_from_repo
from testing.fixtures import make_repo
from testing.fixtures import modify_manifest
from testing.language_helpers import run_language
from testing.util import cwd
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):
with languages[hook.language].in_env(hook.prefix, hook.language_version):
return languages[hook.language].run_hook(
hook.prefix,
hook.entry,
hook.args,
filenames,
is_local=hook.src == 'local',
require_serial=hook.require_serial,
color=color,
)
return run_language(
path=hook.prefix.prefix_dir,
language=languages[hook.language],
exe=hook.entry,
args=hook.args,
file_args=filenames,
version=hook.language_version,
deps=hook.additional_dependencies,
is_local=hook.src == 'local',
require_serial=hook.require_serial,
color=color,
)


def _get_hook_no_install(repo_config, store, hook_id):
Expand Down Expand Up @@ -77,7 +76,7 @@ def _test_hook_repo(
hook = _get_hook(config, store, hook_id)
ret, out = _hook_run(hook, args, color=color)
assert ret == expected_return_code
assert _norm_out(out) == expected
assert out == expected


def test_python_hook(tempdir_factory, store):
Expand Down Expand Up @@ -425,7 +424,7 @@ def test_local_python_repo(store, local_python_config):
assert hook.language_version != C.DEFAULT
ret, out = _hook_run(hook, ('filename',), color=False)
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):
Expand Down

0 comments on commit d23990c

Please sign in to comment.