mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #315 from pre-commit/allow_curly_braces_in_args
Allow '.format('-like strings in arguments. Resolves #314.
This commit is contained in:
commit
c24f78b1a5
3 changed files with 19 additions and 19 deletions
|
|
@ -7,10 +7,6 @@ import subprocess
|
|||
from pre_commit.util import cmd_output
|
||||
|
||||
|
||||
def _replace_cmd(cmd, **kwargs):
|
||||
return [part.format(**kwargs) for part in cmd]
|
||||
|
||||
|
||||
class PrefixedCommandRunner(object):
|
||||
"""A PrefixedCommandRunner allows you to run subprocess commands with
|
||||
comand substitution.
|
||||
|
|
@ -37,7 +33,9 @@ class PrefixedCommandRunner(object):
|
|||
|
||||
def run(self, cmd, **kwargs):
|
||||
self._create_path_if_not_exists()
|
||||
replaced_cmd = _replace_cmd(cmd, prefix=self.prefix_dir)
|
||||
replaced_cmd = [
|
||||
part.replace('{prefix}', self.prefix_dir) for part in cmd
|
||||
]
|
||||
return cmd_output(*replaced_cmd, __popen=self.__popen, **kwargs)
|
||||
|
||||
def path(self, *parts):
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import mock
|
|||
import pytest
|
||||
|
||||
from pre_commit import five
|
||||
from pre_commit.prefixed_command_runner import _replace_cmd
|
||||
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
|
||||
from pre_commit.util import CalledProcessError
|
||||
|
||||
|
|
@ -59,19 +58,6 @@ def makedirs_mock():
|
|||
return mock.Mock(spec=os.makedirs)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('input', 'kwargs', 'expected_output'), (
|
||||
([], {}, []),
|
||||
(['foo'], {}, ['foo']),
|
||||
([], {'foo': 'bar'}, []),
|
||||
(['{foo}/baz'], {'foo': 'bar'}, ['bar/baz']),
|
||||
(['foo'], {'foo': 'bar'}, ['foo']),
|
||||
(['foo', '{bar}'], {'bar': 'baz'}, ['foo', 'baz']),
|
||||
))
|
||||
def test_replace_cmd(input, kwargs, expected_output):
|
||||
ret = _replace_cmd(input, **kwargs)
|
||||
assert ret == expected_output
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('input', 'expected_prefix'), (
|
||||
norm_slash(('.', './')),
|
||||
norm_slash(('foo', 'foo/')),
|
||||
|
|
|
|||
|
|
@ -178,6 +178,22 @@ def test_run_hook_with_spaced_args(tempdir_factory, store):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_run_hook_with_curly_braced_arguments(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'arg_per_line_hooks_repo',
|
||||
'arg-per-line',
|
||||
[],
|
||||
b"arg: hi {1}\narg: I'm {a} problem\n",
|
||||
config_kwargs={
|
||||
'hooks': [{
|
||||
'id': 'arg-per-line',
|
||||
'args': ['hi {1}', "I'm {a} problem"],
|
||||
}]
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@xfailif_no_pcre_support
|
||||
@pytest.mark.integration
|
||||
def test_pcre_hook_no_match(tempdir_factory, store):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue