Implement 'negate' to simplify pcre

This commit is contained in:
Anthony Sottile 2016-03-21 19:56:41 -07:00
parent b7d395410b
commit a932315a15
5 changed files with 51 additions and 39 deletions

View file

@ -9,7 +9,6 @@ import pytest
from pre_commit.util import clean_path_on_failure
from pre_commit.util import cwd
from pre_commit.util import memoize_by_cwd
from pre_commit.util import shell_escape
from pre_commit.util import tmpdir
@ -79,18 +78,6 @@ def test_clean_path_on_failure_cleans_for_system_exit(in_tmpdir):
assert not os.path.exists('foo')
@pytest.mark.parametrize(
('input_str', 'expected'),
(
('', "''"),
('foo"bar', "'foo\"bar'"),
("foo'bar", "'foo'\"'\"'bar'")
),
)
def test_shell_escape(input_str, expected):
assert shell_escape(input_str) == expected
def test_tmpdir():
with tmpdir() as tempdir:
assert os.path.exists(tempdir)

View file

@ -45,3 +45,28 @@ def test_xargs_smoke():
assert ret == 0
assert out == b'hello world\n'
assert err == b''
exit_cmd = ('bash', '-c', 'exit $1', '--')
# Abuse max_length to control the exit code
max_length = len(' '.join(exit_cmd)) + 2
def test_xargs_negate():
ret, _, _ = xargs.xargs(
exit_cmd, ('1',), negate=True, _max_length=max_length,
)
assert ret == 0
ret, _, _ = xargs.xargs(
exit_cmd, ('1', '0'), negate=True, _max_length=max_length,
)
assert ret == 1
def test_xargs_retcode_normal():
ret, _, _ = xargs.xargs(exit_cmd, ('0',), _max_length=max_length)
assert ret == 0
ret, _, _ = xargs.xargs(exit_cmd, ('0', '1'), _max_length=max_length)
assert ret == 1