hookmeup

A Git hook to automate your Pipenv and Django workflow
git clone git://git.danielmoch.com/hookmeup.git
Log | Files | Refs | README | LICENSE

commit e17f7197e4c4f6df92624c63a5c01d475629b473
parent 8b0a88f4a98a77414486f5a48d6ca6d8d039cb45
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Fri, 31 Aug 2018 21:01:17 -0400

Gracefully handle HookMeUpError

Diffstat:
Mhookmeup/__init__.py | 6+++++-
Mtests/test_main.py | 13+++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/hookmeup/__init__.py b/hookmeup/__init__.py @@ -5,6 +5,7 @@ from argparse import Namespace from . import hookmeup +from .hookmeup import HookMeUpError __author__ = 'Daniel Moch' __version__ = '0.1.2' @@ -54,4 +55,7 @@ def main(): func = args.func arg_dict = vars(args) del arg_dict['func'] - func(arg_dict) + try: + func(arg_dict) + except HookMeUpError as ex: + print(str(ex)) diff --git a/tests/test_main.py b/tests/test_main.py @@ -5,6 +5,7 @@ import pytest import hookmeup +from hookmeup.hookmeup import HookMeUpError @pytest.fixture def mock_hookmeup(mocker): @@ -80,3 +81,15 @@ def test_no_args(mock_hookmeup, mocker): hookmeup.main() hookmeup.hookmeup.post_checkout.assert_not_called() hookmeup.hookmeup.install.assert_not_called() + +def test_error(mocker): + """Test case where hookmeup throws an exception""" + mocker.patch( + 'hookmeup.hookmeup.install', + new=mocker.MagicMock(side_effect=HookMeUpError('test error')) + ) + mocker.patch.object(sys, 'argv', ['hookmeup', 'install']) + mocker.patch('hookmeup.print') + hookmeup.main() + assert hookmeup.hookmeup.install.call_count == 1 + hookmeup.print.called_with('hookmeup: test error')