mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
rewrite args with spaces test to not require python
This commit is contained in:
parent
fe73f519c7
commit
63a180a935
1 changed files with 13 additions and 16 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
@ -17,6 +18,7 @@ from pre_commit.clientlib import CONFIG_SCHEMA
|
||||||
from pre_commit.clientlib import load_manifest
|
from pre_commit.clientlib import load_manifest
|
||||||
from pre_commit.hook import Hook
|
from pre_commit.hook import Hook
|
||||||
from pre_commit.languages import python
|
from pre_commit.languages import python
|
||||||
|
from pre_commit.languages import system
|
||||||
from pre_commit.prefix import Prefix
|
from pre_commit.prefix import Prefix
|
||||||
from pre_commit.repository import _hook_installed
|
from pre_commit.repository import _hook_installed
|
||||||
from pre_commit.repository import all_hooks
|
from pre_commit.repository import all_hooks
|
||||||
|
|
@ -99,22 +101,6 @@ def test_python_hook_default_version(tempdir_factory, store):
|
||||||
test_python_hook(tempdir_factory, store)
|
test_python_hook(tempdir_factory, store)
|
||||||
|
|
||||||
|
|
||||||
def test_python_hook_args_with_spaces(tempdir_factory, store):
|
|
||||||
_test_hook_repo(
|
|
||||||
tempdir_factory, store, 'python_hooks_repo',
|
|
||||||
'foo',
|
|
||||||
[],
|
|
||||||
b"['i have spaces', 'and\"\\'quotes', '$and !this']\n"
|
|
||||||
b'Hello World\n',
|
|
||||||
config_kwargs={
|
|
||||||
'hooks': [{
|
|
||||||
'id': 'foo',
|
|
||||||
'args': ['i have spaces', 'and"\'quotes', '$and !this'],
|
|
||||||
}],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_python_hook_weird_setup_cfg(in_git_dir, tempdir_factory, store):
|
def test_python_hook_weird_setup_cfg(in_git_dir, tempdir_factory, store):
|
||||||
in_git_dir.join('setup.cfg').write('[install]\ninstall_scripts=/usr/sbin')
|
in_git_dir.join('setup.cfg').write('[install]\ninstall_scripts=/usr/sbin')
|
||||||
|
|
||||||
|
|
@ -583,3 +569,14 @@ def test_non_installable_hook_error_for_additional_dependencies(store, caplog):
|
||||||
'using language `system` which does not install an environment. '
|
'using language `system` which does not install an environment. '
|
||||||
'Perhaps you meant to use a specific language?'
|
'Perhaps you meant to use a specific language?'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_args_with_spaces_and_quotes(tmp_path):
|
||||||
|
ret = run_language(
|
||||||
|
tmp_path, system,
|
||||||
|
f"{shlex.quote(sys.executable)} -c 'import sys; print(sys.argv[1:])'",
|
||||||
|
('i have spaces', 'and"\'quotes', '$and !this'),
|
||||||
|
)
|
||||||
|
|
||||||
|
expected = b"['i have spaces', 'and\"\\'quotes', '$and !this']\n"
|
||||||
|
assert ret == (0, expected)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue