mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 13:00:10 -06:00
test things more directly to improve coverage
This commit is contained in:
@@ -12,6 +12,7 @@ from pre_commit.languages import python
|
||||
from pre_commit.prefix import Prefix
|
||||
from pre_commit.util import make_executable
|
||||
from pre_commit.util import win_exe
|
||||
from testing.language_helpers import run_language
|
||||
|
||||
|
||||
def test_read_pyvenv_cfg(tmpdir):
|
||||
@@ -210,3 +211,25 @@ def test_unhealthy_then_replaced(python_dir):
|
||||
os.replace(f'{py_exe}.tmp', py_exe)
|
||||
|
||||
assert python.health_check(prefix, C.DEFAULT) is None
|
||||
|
||||
|
||||
def test_language_versioned_python_hook(tmp_path):
|
||||
setup_py = '''\
|
||||
from setuptools import setup
|
||||
setup(
|
||||
name='example',
|
||||
py_modules=['mod'],
|
||||
entry_points={'console_scripts': ['myexe=mod:main']},
|
||||
)
|
||||
'''
|
||||
tmp_path.joinpath('setup.py').write_text(setup_py)
|
||||
tmp_path.joinpath('mod.py').write_text('def main(): print("ohai")')
|
||||
|
||||
# we patch this to force virtualenv executing with `-p` since we can't
|
||||
# reliably have multiple pythons available in CI
|
||||
with mock.patch.object(
|
||||
python,
|
||||
'_sys_executable_matches',
|
||||
return_value=False,
|
||||
):
|
||||
assert run_language(tmp_path, python, 'myexe') == (0, b'ohai\n')
|
||||
|
||||
14
tests/languages/script_test.py
Normal file
14
tests/languages/script_test.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pre_commit.languages import script
|
||||
from pre_commit.util import make_executable
|
||||
from testing.language_helpers import run_language
|
||||
|
||||
|
||||
def test_script_language(tmp_path):
|
||||
exe = tmp_path.joinpath('main')
|
||||
exe.write_text('#!/usr/bin/env bash\necho hello hello world\n')
|
||||
make_executable(exe)
|
||||
|
||||
expected = (0, b'hello hello world\n')
|
||||
assert run_language(tmp_path, script, 'main') == expected
|
||||
9
tests/languages/system_test.py
Normal file
9
tests/languages/system_test.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pre_commit.languages import system
|
||||
from testing.language_helpers import run_language
|
||||
|
||||
|
||||
def test_system_language(tmp_path):
|
||||
expected = (0, b'hello hello world\n')
|
||||
assert run_language(tmp_path, system, 'echo hello hello world') == expected
|
||||
@@ -143,22 +143,6 @@ def test_python_venv_deprecation(store, caplog):
|
||||
)
|
||||
|
||||
|
||||
def test_language_versioned_python_hook(tempdir_factory, store):
|
||||
# we patch this force virtualenv executing with `-p` since we can't
|
||||
# reliably have multiple pythons available in CI
|
||||
with mock.patch.object(
|
||||
python,
|
||||
'_sys_executable_matches',
|
||||
return_value=False,
|
||||
):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'python3_hooks_repo',
|
||||
'python3-hook',
|
||||
[os.devnull],
|
||||
f'3\n[{os.devnull!r}]\nHello World\n'.encode(),
|
||||
)
|
||||
|
||||
|
||||
def test_system_hook_with_spaces(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'system_hook_with_spaces_repo',
|
||||
|
||||
Reference in New Issue
Block a user