diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-11-12 13:42:43 -0600 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-11-12 13:43:49 -0600 |
| commit | c81a403fefcde5545bd7d41c66efb7b658d166f5 (patch) | |
| tree | 1aeca354b2cd5a65358f3e63255ee77e91f911e7 /tests | |
| parent | eff9f607bb3990dabd62536ef3511414033587db (diff) | |
| download | flake8-c81a403fefcde5545bd7d41c66efb7b658d166f5.tar.gz | |
Exit non-zero if something goes wrong during a run
If we handle an exception, or early exit, or really anything, we should
exit non-zero (and we used to). This was a minor oversight.
Closes #209
Closes #248
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit/test_application.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/unit/test_application.py b/tests/unit/test_application.py new file mode 100644 index 0000000..6a3ef91 --- /dev/null +++ b/tests/unit/test_application.py @@ -0,0 +1,62 @@ +"""Tests for the Application class.""" +import optparse + +import mock +import pytest + +from flake8.main import application as app + + +def options(**kwargs): + """Generate optparse.Values for our Application.""" + kwargs.setdefault('verbose', 0) + kwargs.setdefault('output_file', None) + kwargs.setdefault('count', False) + kwargs.setdefault('exit_zero', False) + return optparse.Values(kwargs) + + +@pytest.mark.parametrize( + 'result_count, catastrophic, exit_zero', [ + (0, True, True), + (2, False, True), + (2, True, True), + ] +) +def test_exit_does_not_raise(result_count, catastrophic, exit_zero): + """Verify Application.exit doesn't raise SystemExit.""" + with mock.patch('flake8.options.manager.OptionManager') as optionmanager: + optmgr = optionmanager.return_value = mock.Mock() + optmgr.parse_known_args.return_value = (options(), []) + application = app.Application() + + application.result_count = result_count + application.catastrophic_failure = catastrophic + application.options = options(exit_zero=exit_zero) + + assert application.exit() is None + + +@pytest.mark.parametrize( + 'result_count, catastrophic, exit_zero, value', [ + (0, False, False, False), + (0, True, False, True), + (2, False, False, True), + (2, True, False, True), + ] +) +def test_exit_does_raise(result_count, catastrophic, exit_zero, value): + """Verify Application.exit doesn't raise SystemExit.""" + with mock.patch('flake8.options.manager.OptionManager') as optionmanager: + optmgr = optionmanager.return_value = mock.Mock() + optmgr.parse_known_args.return_value = (options(), []) + application = app.Application() + + application.result_count = result_count + application.catastrophic_failure = catastrophic + application.options = options(exit_zero=exit_zero) + + with pytest.raises(SystemExit) as excinfo: + application.exit() + + assert excinfo.value.args[0] is value |
