mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #601 from pre-commit/less_special_system_exit
Use SystemExit instead of PreCommitSystemExit
This commit is contained in:
commit
8b14c6c5ae
3 changed files with 4 additions and 10 deletions
|
|
@ -14,11 +14,6 @@ from pre_commit.errors import FatalError
|
||||||
from pre_commit.store import Store
|
from pre_commit.store import Store
|
||||||
|
|
||||||
|
|
||||||
# For testing purposes
|
|
||||||
class PreCommitSystemExit(SystemExit):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def _to_bytes(exc):
|
def _to_bytes(exc):
|
||||||
try:
|
try:
|
||||||
return bytes(exc)
|
return bytes(exc)
|
||||||
|
|
@ -39,7 +34,7 @@ def _log_and_exit(msg, exc, formatted):
|
||||||
with open(os.path.join(store.directory, 'pre-commit.log'), 'wb') as log:
|
with open(os.path.join(store.directory, 'pre-commit.log'), 'wb') as log:
|
||||||
output.write(error_msg, stream=log)
|
output.write(error_msg, stream=log)
|
||||||
output.write_line(formatted, stream=log)
|
output.write_line(formatted, stream=log)
|
||||||
raise PreCommitSystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ def test_error_handler_uncaught_error(mocked_log_and_exit):
|
||||||
|
|
||||||
|
|
||||||
def test_log_and_exit(cap_out, mock_out_store_directory):
|
def test_log_and_exit(cap_out, mock_out_store_directory):
|
||||||
with pytest.raises(error_handler.PreCommitSystemExit):
|
with pytest.raises(SystemExit):
|
||||||
error_handler._log_and_exit(
|
error_handler._log_and_exit(
|
||||||
'msg', FatalError('hai'), "I'm a stacktrace",
|
'msg', FatalError('hai'), "I'm a stacktrace",
|
||||||
)
|
)
|
||||||
|
|
@ -96,7 +96,7 @@ def test_log_and_exit(cap_out, mock_out_store_directory):
|
||||||
|
|
||||||
|
|
||||||
def test_error_handler_non_ascii_exception(mock_out_store_directory):
|
def test_error_handler_non_ascii_exception(mock_out_store_directory):
|
||||||
with pytest.raises(error_handler.PreCommitSystemExit):
|
with pytest.raises(SystemExit):
|
||||||
with error_handler.error_handler():
|
with error_handler.error_handler():
|
||||||
raise ValueError('☃')
|
raise ValueError('☃')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pre_commit import main
|
from pre_commit import main
|
||||||
from pre_commit.error_handler import PreCommitSystemExit
|
|
||||||
from pre_commit.util import cwd
|
from pre_commit.util import cwd
|
||||||
from testing.auto_namedtuple import auto_namedtuple
|
from testing.auto_namedtuple import auto_namedtuple
|
||||||
|
|
||||||
|
|
@ -120,7 +119,7 @@ def test_expected_fatal_error_no_git_repo(
|
||||||
tempdir_factory, cap_out, mock_out_store_directory,
|
tempdir_factory, cap_out, mock_out_store_directory,
|
||||||
):
|
):
|
||||||
with cwd(tempdir_factory.get()):
|
with cwd(tempdir_factory.get()):
|
||||||
with pytest.raises(PreCommitSystemExit):
|
with pytest.raises(SystemExit):
|
||||||
main.main([])
|
main.main([])
|
||||||
assert cap_out.get() == (
|
assert cap_out.get() == (
|
||||||
'An error has occurred: FatalError: git failed. '
|
'An error has occurred: FatalError: git failed. '
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue