File: test_application.py

package info (click to toggle)
python-flake8 3.2.1-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 1,076 kB
  • sloc: python: 5,037; sh: 20; makefile: 18
file content (62 lines) | stat: -rw-r--r-- 1,981 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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