Merge pull request #3585 from pre-commit/hazmat

add pre-commit hazmat
This commit is contained in:
anthony sottile 2025-11-22 14:03:09 -05:00 committed by GitHub
commit 3358a3b540
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 243 additions and 2 deletions

View file

@ -9,6 +9,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
@ -157,6 +158,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', '.'))