add pre-commit hazmat

This commit is contained in:
anthony sottile 2025-11-21 16:38:55 -05:00
parent 9c7ea88ab9
commit bdf68790b7
7 changed files with 243 additions and 2 deletions

View file

@ -8,6 +8,7 @@ import pytest
import pre_commit.constants as C
from pre_commit import main
from pre_commit.commands import hazmat
from pre_commit.errors import FatalError
from pre_commit.util import cmd_output
from testing.auto_namedtuple import auto_namedtuple
@ -158,6 +159,17 @@ def test_all_cmds(command, mock_commands, mock_store_dir):
assert_only_one_mock_called(mock_commands)
def test_hazmat(mock_store_dir):
with mock.patch.object(hazmat, 'impl') as mck:
main.main(('hazmat', 'cd', 'subdir', '--', 'cmd', '--', 'f1', 'f2'))
assert mck.call_count == 1
(arg,), dct = mck.call_args
assert dct == {}
assert arg.tool == 'cd'
assert arg.subdir == 'subdir'
assert arg.cmd == ['cmd', '--', 'f1', 'f2']
def test_try_repo(mock_store_dir):
with mock.patch.object(main, 'try_repo') as patch:
main.main(('try-repo', '.'))