Attempt to add a mechanism for tagging hooks

This commit is contained in:
Josh Abrams 2022-11-12 02:06:55 -05:00
parent 1f59f4cba8
commit 189490a938
8 changed files with 67 additions and 8 deletions

View file

@ -144,12 +144,14 @@ def _do_run(cap_out, store, repo, args, environ={}, config_file=C.CONFIG_FILE):
def _test_run(
cap_out, store, repo, opts, expected_outputs, expected_ret, stage,
config_file=C.CONFIG_FILE,
config_file=C.CONFIG_FILE, environ_override=None
):
if stage:
stage_a_file()
if environ_override is None:
environ_override = {}
args = run_opts(**opts)
ret, printed = _do_run(cap_out, store, repo, args, config_file=config_file)
ret, printed = _do_run(cap_out, store, repo, args, config_file=config_file, environ=environ_override)
assert ret == expected_ret, (ret, expected_ret, printed)
for expected_output_part in expected_outputs:
@ -352,6 +354,7 @@ def test_show_diff_on_failure(
({}, (b'Bash hook', b'Passed'), 0, True),
({'verbose': True}, (b'foo.py\nHello World',), 0, True),
({'hook': 'bash_hook'}, (b'Bash hook', b'Passed'), 0, True),
({'tags': ['foo']}, (b'Bash hook', b'Passed'), 0, True),
(
{'hook': 'nope'},
(b'No hook with id `nope` in stage `commit`',),
@ -364,6 +367,18 @@ def test_show_diff_on_failure(
1,
True,
),
(
{'tags': ['bar', 'baz']},
(b'No hooks with tags matching `[\'bar\', \'baz\']` in stage `commit`',),
1,
True,
),
(
{'tags': ['bar', 'baz'], 'hook_stage': 'push'},
(b'No hooks with tags matching `[\'bar\', \'baz\']` in stage `push`',),
1,
True,
),
(
{'all_files': True, 'verbose': True},
(b'foo.py',),
@ -618,6 +633,18 @@ def test_skip_aliased_hook(cap_out, store, aliased_repo):
for msg in (b'Bash hook', b'Skipped'):
assert printed.count(msg) == 1
def test_skip_tag(cap_out, store, repo_with_passing_hook):
_test_run(
cap_out,
store,
repo_with_passing_hook,
{},
(b'Bash hook', b'Skipped'),
0,
True,
environ_override={'SKIP': 'foo'}
)
def test_skip_bypasses_installation(cap_out, store, repo_with_passing_hook):
config = {