mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
replace fake_log_handler with caplog
This commit is contained in:
parent
bb50e00447
commit
c7cbb1e6ad
2 changed files with 8 additions and 16 deletions
|
|
@ -261,15 +261,6 @@ def cap_out():
|
||||||
yield Fixture(stream)
|
yield Fixture(stream)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def fake_log_handler():
|
|
||||||
handler = mock.Mock(level=logging.INFO)
|
|
||||||
logger = logging.getLogger('pre_commit')
|
|
||||||
logger.addHandler(handler)
|
|
||||||
yield handler
|
|
||||||
logger.removeHandler(handler)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session', autouse=True)
|
@pytest.fixture(scope='session', autouse=True)
|
||||||
def set_git_templatedir(tmpdir_factory):
|
def set_git_templatedir(tmpdir_factory):
|
||||||
tdir = str(tmpdir_factory.mktemp('git_template_dir'))
|
tdir = str(tmpdir_factory.mktemp('git_template_dir'))
|
||||||
|
|
|
||||||
|
|
@ -640,7 +640,7 @@ def test_fail_hooks(store):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_unknown_keys(store, fake_log_handler):
|
def test_unknown_keys(store, caplog):
|
||||||
config = {
|
config = {
|
||||||
'repo': 'local',
|
'repo': 'local',
|
||||||
'hooks': [{
|
'hooks': [{
|
||||||
|
|
@ -653,8 +653,8 @@ def test_unknown_keys(store, fake_log_handler):
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
_get_hook(config, store, 'too-much')
|
_get_hook(config, store, 'too-much')
|
||||||
expected = 'Unexpected key(s) present on local => too-much: foo, hello'
|
msg, = caplog.messages
|
||||||
assert fake_log_handler.handle.call_args[0][0].msg == expected
|
assert msg == 'Unexpected key(s) present on local => too-much: foo, hello'
|
||||||
|
|
||||||
|
|
||||||
def test_reinstall(tempdir_factory, store, log_info_mock):
|
def test_reinstall(tempdir_factory, store, log_info_mock):
|
||||||
|
|
@ -832,27 +832,28 @@ def test_default_stages(store, local_python_config):
|
||||||
assert hook.stages == ['push']
|
assert hook.stages == ['push']
|
||||||
|
|
||||||
|
|
||||||
def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
|
def test_hook_id_not_present(tempdir_factory, store, caplog):
|
||||||
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
||||||
config = make_config_from_repo(path)
|
config = make_config_from_repo(path)
|
||||||
config['hooks'][0]['id'] = 'i-dont-exist'
|
config['hooks'][0]['id'] = 'i-dont-exist'
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
_get_hook(config, store, 'i-dont-exist')
|
_get_hook(config, store, 'i-dont-exist')
|
||||||
assert fake_log_handler.handle.call_args[0][0].msg == (
|
_, msg = caplog.messages
|
||||||
|
assert msg == (
|
||||||
f'`i-dont-exist` is not present in repository file://{path}. '
|
f'`i-dont-exist` is not present in repository file://{path}. '
|
||||||
f'Typo? Perhaps it is introduced in a newer version? '
|
f'Typo? Perhaps it is introduced in a newer version? '
|
||||||
f'Often `pre-commit autoupdate` fixes this.'
|
f'Often `pre-commit autoupdate` fixes this.'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_too_new_version(tempdir_factory, store, fake_log_handler):
|
def test_too_new_version(tempdir_factory, store, caplog):
|
||||||
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
||||||
with modify_manifest(path) as manifest:
|
with modify_manifest(path) as manifest:
|
||||||
manifest[0]['minimum_pre_commit_version'] = '999.0.0'
|
manifest[0]['minimum_pre_commit_version'] = '999.0.0'
|
||||||
config = make_config_from_repo(path)
|
config = make_config_from_repo(path)
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
_get_hook(config, store, 'bash_hook')
|
_get_hook(config, store, 'bash_hook')
|
||||||
msg = fake_log_handler.handle.call_args[0][0].msg
|
_, msg = caplog.messages
|
||||||
pattern = re_assert.Matches(
|
pattern = re_assert.Matches(
|
||||||
r'^The hook `bash_hook` requires pre-commit version 999\.0\.0 but '
|
r'^The hook `bash_hook` requires pre-commit version 999\.0\.0 but '
|
||||||
r'version \d+\.\d+\.\d+ is installed. '
|
r'version \d+\.\d+\.\d+ is installed. '
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue