33import sys
44from unittest import mock
55
6+ import re_assert
7+
68import pre_commit .constants as C
79from pre_commit import git
810from pre_commit .commands import install_uninstall
@@ -143,7 +145,7 @@ def _get_commit_output(tempdir_factory, touch_file='foo', **kwargs):
143145)
144146
145147
146- NORMAL_PRE_COMMIT_RUN = re . compile (
148+ NORMAL_PRE_COMMIT_RUN = re_assert . Matches (
147149 fr'^\[INFO\] Initializing environment for .+\.\n'
148150 fr'Bash hook\.+Passed\n'
149151 fr'\[master [a-f0-9]{{7}}\] commit!\n'
@@ -159,7 +161,7 @@ def test_install_pre_commit_and_run(tempdir_factory, store):
159161
160162 ret , output = _get_commit_output (tempdir_factory )
161163 assert ret == 0
162- assert NORMAL_PRE_COMMIT_RUN .match (output )
164+ NORMAL_PRE_COMMIT_RUN .assert_matches (output )
163165
164166
165167def test_install_pre_commit_and_run_custom_path (tempdir_factory , store ):
@@ -171,7 +173,7 @@ def test_install_pre_commit_and_run_custom_path(tempdir_factory, store):
171173
172174 ret , output = _get_commit_output (tempdir_factory )
173175 assert ret == 0
174- assert NORMAL_PRE_COMMIT_RUN .match (output )
176+ NORMAL_PRE_COMMIT_RUN .assert_matches (output )
175177
176178
177179def test_install_in_submodule_and_run (tempdir_factory , store ):
@@ -185,7 +187,7 @@ def test_install_in_submodule_and_run(tempdir_factory, store):
185187 assert install (C .CONFIG_FILE , store , hook_types = ['pre-commit' ]) == 0
186188 ret , output = _get_commit_output (tempdir_factory )
187189 assert ret == 0
188- assert NORMAL_PRE_COMMIT_RUN .match (output )
190+ NORMAL_PRE_COMMIT_RUN .assert_matches (output )
189191
190192
191193def test_install_in_worktree_and_run (tempdir_factory , store ):
@@ -198,7 +200,7 @@ def test_install_in_worktree_and_run(tempdir_factory, store):
198200 assert install (C .CONFIG_FILE , store , hook_types = ['pre-commit' ]) == 0
199201 ret , output = _get_commit_output (tempdir_factory )
200202 assert ret == 0
201- assert NORMAL_PRE_COMMIT_RUN .match (output )
203+ NORMAL_PRE_COMMIT_RUN .assert_matches (output )
202204
203205
204206def test_commit_am (tempdir_factory , store ):
@@ -243,7 +245,7 @@ def test_install_idempotent(tempdir_factory, store):
243245
244246 ret , output = _get_commit_output (tempdir_factory )
245247 assert ret == 0
246- assert NORMAL_PRE_COMMIT_RUN .match (output )
248+ NORMAL_PRE_COMMIT_RUN .assert_matches (output )
247249
248250
249251def _path_without_us ():
@@ -297,7 +299,7 @@ def test_environment_not_sourced(tempdir_factory, store):
297299 )
298300
299301
300- FAILING_PRE_COMMIT_RUN = re . compile (
302+ FAILING_PRE_COMMIT_RUN = re_assert . Matches (
301303 r'^\[INFO\] Initializing environment for .+\.\n'
302304 r'Failing hook\.+Failed\n'
303305 r'- hook id: failing_hook\n'
@@ -316,10 +318,10 @@ def test_failing_hooks_returns_nonzero(tempdir_factory, store):
316318
317319 ret , output = _get_commit_output (tempdir_factory )
318320 assert ret == 1
319- assert FAILING_PRE_COMMIT_RUN .match (output )
321+ FAILING_PRE_COMMIT_RUN .assert_matches (output )
320322
321323
322- EXISTING_COMMIT_RUN = re . compile (
324+ EXISTING_COMMIT_RUN = re_assert . Matches (
323325 fr'^legacy hook\n'
324326 fr'\[master [a-f0-9]{{7}}\] commit!\n'
325327 fr'{ FILES_CHANGED } '
@@ -342,7 +344,7 @@ def test_install_existing_hooks_no_overwrite(tempdir_factory, store):
342344 # Make sure we installed the "old" hook correctly
343345 ret , output = _get_commit_output (tempdir_factory , touch_file = 'baz' )
344346 assert ret == 0
345- assert EXISTING_COMMIT_RUN .match (output )
347+ EXISTING_COMMIT_RUN .assert_matches (output )
346348
347349 # Now install pre-commit (no-overwrite)
348350 assert install (C .CONFIG_FILE , store , hook_types = ['pre-commit' ]) == 0
@@ -351,7 +353,7 @@ def test_install_existing_hooks_no_overwrite(tempdir_factory, store):
351353 ret , output = _get_commit_output (tempdir_factory )
352354 assert ret == 0
353355 assert output .startswith ('legacy hook\n ' )
354- assert NORMAL_PRE_COMMIT_RUN .match (output [len ('legacy hook\n ' ):])
356+ NORMAL_PRE_COMMIT_RUN .assert_matches (output [len ('legacy hook\n ' ):])
355357
356358
357359def test_legacy_overwriting_legacy_hook (tempdir_factory , store ):
@@ -377,10 +379,10 @@ def test_install_existing_hook_no_overwrite_idempotent(tempdir_factory, store):
377379 ret , output = _get_commit_output (tempdir_factory )
378380 assert ret == 0
379381 assert output .startswith ('legacy hook\n ' )
380- assert NORMAL_PRE_COMMIT_RUN .match (output [len ('legacy hook\n ' ):])
382+ NORMAL_PRE_COMMIT_RUN .assert_matches (output [len ('legacy hook\n ' ):])
381383
382384
383- FAIL_OLD_HOOK = re . compile (
385+ FAIL_OLD_HOOK = re_assert . Matches (
384386 r'fail!\n'
385387 r'\[INFO\] Initializing environment for .+\.\n'
386388 r'Bash hook\.+Passed\n' ,
@@ -401,7 +403,7 @@ def test_failing_existing_hook_returns_1(tempdir_factory, store):
401403 # We should get a failure from the legacy hook
402404 ret , output = _get_commit_output (tempdir_factory )
403405 assert ret == 1
404- assert FAIL_OLD_HOOK .match (output )
406+ FAIL_OLD_HOOK .assert_matches (output )
405407
406408
407409def test_install_overwrite_no_existing_hooks (tempdir_factory , store ):
@@ -413,7 +415,7 @@ def test_install_overwrite_no_existing_hooks(tempdir_factory, store):
413415
414416 ret , output = _get_commit_output (tempdir_factory )
415417 assert ret == 0
416- assert NORMAL_PRE_COMMIT_RUN .match (output )
418+ NORMAL_PRE_COMMIT_RUN .assert_matches (output )
417419
418420
419421def test_install_overwrite (tempdir_factory , store ):
@@ -426,7 +428,7 @@ def test_install_overwrite(tempdir_factory, store):
426428
427429 ret , output = _get_commit_output (tempdir_factory )
428430 assert ret == 0
429- assert NORMAL_PRE_COMMIT_RUN .match (output )
431+ NORMAL_PRE_COMMIT_RUN .assert_matches (output )
430432
431433
432434def test_uninstall_restores_legacy_hooks (tempdir_factory , store ):
@@ -441,7 +443,7 @@ def test_uninstall_restores_legacy_hooks(tempdir_factory, store):
441443 # Make sure we installed the "old" hook correctly
442444 ret , output = _get_commit_output (tempdir_factory , touch_file = 'baz' )
443445 assert ret == 0
444- assert EXISTING_COMMIT_RUN .match (output )
446+ EXISTING_COMMIT_RUN .assert_matches (output )
445447
446448
447449def test_replace_old_commit_script (tempdir_factory , store ):
@@ -463,7 +465,7 @@ def test_replace_old_commit_script(tempdir_factory, store):
463465
464466 ret , output = _get_commit_output (tempdir_factory )
465467 assert ret == 0
466- assert NORMAL_PRE_COMMIT_RUN .match (output )
468+ NORMAL_PRE_COMMIT_RUN .assert_matches (output )
467469
468470
469471def test_uninstall_doesnt_remove_not_our_hooks (in_git_dir ):
@@ -476,7 +478,7 @@ def test_uninstall_doesnt_remove_not_our_hooks(in_git_dir):
476478 assert pre_commit .exists ()
477479
478480
479- PRE_INSTALLED = re . compile (
481+ PRE_INSTALLED = re_assert . Matches (
480482 fr'Bash hook\.+Passed\n'
481483 fr'\[master [a-f0-9]{{7}}\] commit!\n'
482484 fr'{ FILES_CHANGED } '
@@ -493,7 +495,7 @@ def test_installs_hooks_with_hooks_True(tempdir_factory, store):
493495 )
494496
495497 assert ret == 0
496- assert PRE_INSTALLED .match (output )
498+ PRE_INSTALLED .assert_matches (output )
497499
498500
499501def test_install_hooks_command (tempdir_factory , store ):
@@ -506,7 +508,7 @@ def test_install_hooks_command(tempdir_factory, store):
506508 )
507509
508510 assert ret == 0
509- assert PRE_INSTALLED .match (output )
511+ PRE_INSTALLED .assert_matches (output )
510512
511513
512514def test_installed_from_venv (tempdir_factory , store ):
@@ -533,7 +535,7 @@ def test_installed_from_venv(tempdir_factory, store):
533535 },
534536 )
535537 assert ret == 0
536- assert NORMAL_PRE_COMMIT_RUN .match (output )
538+ NORMAL_PRE_COMMIT_RUN .assert_matches (output )
537539
538540
539541def _get_push_output (tempdir_factory , remote = 'origin' , opts = ()):
@@ -880,7 +882,7 @@ def test_prepare_commit_msg_legacy(
880882
881883
882884def test_pre_merge_commit_integration (tempdir_factory , store ):
883- expected = re . compile (
885+ output_pattern = re_assert . Matches (
884886 r'^\[INFO\] Initializing environment for .+\n'
885887 r'Bash hook\.+Passed\n'
886888 r"Merge made by the 'recursive' strategy.\n"
@@ -902,7 +904,7 @@ def test_pre_merge_commit_integration(tempdir_factory, store):
902904 tempdir_factory = tempdir_factory ,
903905 )
904906 assert ret == 0
905- assert expected . match (output )
907+ output_pattern . assert_matches (output )
906908
907909
908910def test_install_disallow_missing_config (tempdir_factory , store ):
0 commit comments