fix excess whitespace in traceback in error

This commit is contained in:
Anthony Sottile 2020-09-07 15:01:50 -07:00
parent 918821b7e0
commit 3a0406847b
6 changed files with 59 additions and 48 deletions

View file

@ -3,6 +3,8 @@ import re
import sys
from unittest import mock
import re_assert
import pre_commit.constants as C
from pre_commit import git
from pre_commit.commands import install_uninstall
@ -143,7 +145,7 @@ FILES_CHANGED = (
)
NORMAL_PRE_COMMIT_RUN = re.compile(
NORMAL_PRE_COMMIT_RUN = re_assert.Matches(
fr'^\[INFO\] Initializing environment for .+\.\n'
fr'Bash hook\.+Passed\n'
fr'\[master [a-f0-9]{{7}}\] commit!\n'
@ -159,7 +161,7 @@ def test_install_pre_commit_and_run(tempdir_factory, store):
ret, output = _get_commit_output(tempdir_factory)
assert ret == 0
assert NORMAL_PRE_COMMIT_RUN.match(output)
NORMAL_PRE_COMMIT_RUN.assert_matches(output)
def 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):
ret, output = _get_commit_output(tempdir_factory)
assert ret == 0
assert NORMAL_PRE_COMMIT_RUN.match(output)
NORMAL_PRE_COMMIT_RUN.assert_matches(output)
def test_install_in_submodule_and_run(tempdir_factory, store):
@ -185,7 +187,7 @@ def test_install_in_submodule_and_run(tempdir_factory, store):
assert install(C.CONFIG_FILE, store, hook_types=['pre-commit']) == 0
ret, output = _get_commit_output(tempdir_factory)
assert ret == 0
assert NORMAL_PRE_COMMIT_RUN.match(output)
NORMAL_PRE_COMMIT_RUN.assert_matches(output)
def test_install_in_worktree_and_run(tempdir_factory, store):
@ -198,7 +200,7 @@ def test_install_in_worktree_and_run(tempdir_factory, store):
assert install(C.CONFIG_FILE, store, hook_types=['pre-commit']) == 0
ret, output = _get_commit_output(tempdir_factory)
assert ret == 0
assert NORMAL_PRE_COMMIT_RUN.match(output)
NORMAL_PRE_COMMIT_RUN.assert_matches(output)
def test_commit_am(tempdir_factory, store):
@ -243,7 +245,7 @@ def test_install_idempotent(tempdir_factory, store):
ret, output = _get_commit_output(tempdir_factory)
assert ret == 0
assert NORMAL_PRE_COMMIT_RUN.match(output)
NORMAL_PRE_COMMIT_RUN.assert_matches(output)
def _path_without_us():
@ -297,7 +299,7 @@ def test_environment_not_sourced(tempdir_factory, store):
)
FAILING_PRE_COMMIT_RUN = re.compile(
FAILING_PRE_COMMIT_RUN = re_assert.Matches(
r'^\[INFO\] Initializing environment for .+\.\n'
r'Failing hook\.+Failed\n'
r'- hook id: failing_hook\n'
@ -316,10 +318,10 @@ def test_failing_hooks_returns_nonzero(tempdir_factory, store):
ret, output = _get_commit_output(tempdir_factory)
assert ret == 1
assert FAILING_PRE_COMMIT_RUN.match(output)
FAILING_PRE_COMMIT_RUN.assert_matches(output)
EXISTING_COMMIT_RUN = re.compile(
EXISTING_COMMIT_RUN = re_assert.Matches(
fr'^legacy hook\n'
fr'\[master [a-f0-9]{{7}}\] commit!\n'
fr'{FILES_CHANGED}'
@ -342,7 +344,7 @@ def test_install_existing_hooks_no_overwrite(tempdir_factory, store):
# Make sure we installed the "old" hook correctly
ret, output = _get_commit_output(tempdir_factory, touch_file='baz')
assert ret == 0
assert EXISTING_COMMIT_RUN.match(output)
EXISTING_COMMIT_RUN.assert_matches(output)
# Now install pre-commit (no-overwrite)
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):
ret, output = _get_commit_output(tempdir_factory)
assert ret == 0
assert output.startswith('legacy hook\n')
assert NORMAL_PRE_COMMIT_RUN.match(output[len('legacy hook\n'):])
NORMAL_PRE_COMMIT_RUN.assert_matches(output[len('legacy hook\n'):])
def test_legacy_overwriting_legacy_hook(tempdir_factory, store):
@ -377,10 +379,10 @@ def test_install_existing_hook_no_overwrite_idempotent(tempdir_factory, store):
ret, output = _get_commit_output(tempdir_factory)
assert ret == 0
assert output.startswith('legacy hook\n')
assert NORMAL_PRE_COMMIT_RUN.match(output[len('legacy hook\n'):])
NORMAL_PRE_COMMIT_RUN.assert_matches(output[len('legacy hook\n'):])
FAIL_OLD_HOOK = re.compile(
FAIL_OLD_HOOK = re_assert.Matches(
r'fail!\n'
r'\[INFO\] Initializing environment for .+\.\n'
r'Bash hook\.+Passed\n',
@ -401,7 +403,7 @@ def test_failing_existing_hook_returns_1(tempdir_factory, store):
# We should get a failure from the legacy hook
ret, output = _get_commit_output(tempdir_factory)
assert ret == 1
assert FAIL_OLD_HOOK.match(output)
FAIL_OLD_HOOK.assert_matches(output)
def test_install_overwrite_no_existing_hooks(tempdir_factory, store):
@ -413,7 +415,7 @@ def test_install_overwrite_no_existing_hooks(tempdir_factory, store):
ret, output = _get_commit_output(tempdir_factory)
assert ret == 0
assert NORMAL_PRE_COMMIT_RUN.match(output)
NORMAL_PRE_COMMIT_RUN.assert_matches(output)
def test_install_overwrite(tempdir_factory, store):
@ -426,7 +428,7 @@ def test_install_overwrite(tempdir_factory, store):
ret, output = _get_commit_output(tempdir_factory)
assert ret == 0
assert NORMAL_PRE_COMMIT_RUN.match(output)
NORMAL_PRE_COMMIT_RUN.assert_matches(output)
def test_uninstall_restores_legacy_hooks(tempdir_factory, store):
@ -441,7 +443,7 @@ def test_uninstall_restores_legacy_hooks(tempdir_factory, store):
# Make sure we installed the "old" hook correctly
ret, output = _get_commit_output(tempdir_factory, touch_file='baz')
assert ret == 0
assert EXISTING_COMMIT_RUN.match(output)
EXISTING_COMMIT_RUN.assert_matches(output)
def test_replace_old_commit_script(tempdir_factory, store):
@ -463,7 +465,7 @@ def test_replace_old_commit_script(tempdir_factory, store):
ret, output = _get_commit_output(tempdir_factory)
assert ret == 0
assert NORMAL_PRE_COMMIT_RUN.match(output)
NORMAL_PRE_COMMIT_RUN.assert_matches(output)
def 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):
assert pre_commit.exists()
PRE_INSTALLED = re.compile(
PRE_INSTALLED = re_assert.Matches(
fr'Bash hook\.+Passed\n'
fr'\[master [a-f0-9]{{7}}\] commit!\n'
fr'{FILES_CHANGED}'
@ -493,7 +495,7 @@ def test_installs_hooks_with_hooks_True(tempdir_factory, store):
)
assert ret == 0
assert PRE_INSTALLED.match(output)
PRE_INSTALLED.assert_matches(output)
def test_install_hooks_command(tempdir_factory, store):
@ -506,7 +508,7 @@ def test_install_hooks_command(tempdir_factory, store):
)
assert ret == 0
assert PRE_INSTALLED.match(output)
PRE_INSTALLED.assert_matches(output)
def test_installed_from_venv(tempdir_factory, store):
@ -533,7 +535,7 @@ def test_installed_from_venv(tempdir_factory, store):
},
)
assert ret == 0
assert NORMAL_PRE_COMMIT_RUN.match(output)
NORMAL_PRE_COMMIT_RUN.assert_matches(output)
def _get_push_output(tempdir_factory, remote='origin', opts=()):
@ -880,7 +882,7 @@ def test_prepare_commit_msg_legacy(
def test_pre_merge_commit_integration(tempdir_factory, store):
expected = re.compile(
output_pattern = re_assert.Matches(
r'^\[INFO\] Initializing environment for .+\n'
r'Bash hook\.+Passed\n'
r"Merge made by the 'recursive' strategy.\n"
@ -902,7 +904,7 @@ def test_pre_merge_commit_integration(tempdir_factory, store):
tempdir_factory=tempdir_factory,
)
assert ret == 0
assert expected.match(output)
output_pattern.assert_matches(output)
def test_install_disallow_missing_config(tempdir_factory, store):

View file

@ -3,6 +3,8 @@ import re
import time
from unittest import mock
import re_assert
from pre_commit import git
from pre_commit.commands.try_repo import try_repo
from pre_commit.util import cmd_output
@ -43,7 +45,7 @@ def test_try_repo_repo_only(cap_out, tempdir_factory):
_run_try_repo(tempdir_factory, verbose=True)
start, config, rest = _get_out(cap_out)
assert start == ''
assert re.match(
config_pattern = re_assert.Matches(
'^repos:\n'
'- repo: .+\n'
' rev: .+\n'
@ -51,8 +53,8 @@ def test_try_repo_repo_only(cap_out, tempdir_factory):
' - id: bash_hook\n'
' - id: bash_hook2\n'
' - id: bash_hook3\n$',
config,
)
config_pattern.assert_matches(config)
assert rest == '''\
Bash hook............................................(no files to check)Skipped
- hook id: bash_hook
@ -71,14 +73,14 @@ def test_try_repo_with_specific_hook(cap_out, tempdir_factory):
_run_try_repo(tempdir_factory, hook='bash_hook', verbose=True)
start, config, rest = _get_out(cap_out)
assert start == ''
assert re.match(
config_pattern = re_assert.Matches(
'^repos:\n'
'- repo: .+\n'
' rev: .+\n'
' hooks:\n'
' - id: bash_hook\n$',
config,
)
config_pattern.assert_matches(config)
assert rest == '''\
Bash hook............................................(no files to check)Skipped
- hook id: bash_hook
@ -128,14 +130,14 @@ def test_try_repo_uncommitted_changes(cap_out, tempdir_factory):
start, config, rest = _get_out(cap_out)
assert start == '[WARNING] Creating temporary repo with uncommitted changes...\n' # noqa: E501
assert re.match(
config_pattern = re_assert.Matches(
'^repos:\n'
'- repo: .+shadow-repo\n'
' rev: .+\n'
' hooks:\n'
' - id: bash_hook\n$',
config,
)
config_pattern.assert_matches(config)
assert rest == 'modified name!...........................................................Passed\n' # noqa: E501