-
Notifications
You must be signed in to change notification settings - Fork 15
/
plugin.py
113 lines (106 loc) · 3.93 KB
/
plugin.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import argparse
from typing import List
from flake8.options.manager import OptionManager
from flake8_plugin_utils import Plugin
from .config import (
DEFAULT_CONFIG,
Config,
ParametrizeNamesType,
ParametrizeValuesRowType,
ParametrizeValuesType,
enum_choices,
)
from .visitors import (
AssertionVisitor,
FailVisitor,
FixturesVisitor,
ImportsVisitor,
MarksVisitor,
ParametrizeVisitor,
PatchVisitor,
RaisesVisitor,
UnittestAssertionVisitor,
)
__version__ = '1.4.0'
class PytestStylePlugin(Plugin[Config]):
name = 'flake8-pytest-style'
version = __version__
visitors = [
AssertionVisitor,
FailVisitor,
FixturesVisitor,
ImportsVisitor,
MarksVisitor,
PatchVisitor,
ParametrizeVisitor,
RaisesVisitor,
UnittestAssertionVisitor,
]
@classmethod
def add_options(cls, option_manager: OptionManager) -> None:
option_manager.add_option(
'--pytest-fixture-no-parentheses',
action='store_true',
parse_from_config=True,
default=not DEFAULT_CONFIG.fixture_parentheses,
help='Omit parentheses for @pytest.fixture decorators'
' without parameters. (Default: %(default)s)',
)
option_manager.add_option(
'--pytest-raises-require-match-for',
comma_separated_list=True,
parse_from_config=True,
default=DEFAULT_CONFIG.raises_require_match_for,
help='List of exceptions for which flake8-pytest-style requires'
' a match= argument in pytest.raises(). (Default: %(default)s)',
)
option_manager.add_option(
'--pytest-parametrize-names-type',
choices=enum_choices(ParametrizeNamesType),
parse_from_config=True,
default=DEFAULT_CONFIG.parametrize_names_type.value,
help='Preferred type for multiple parameter names in'
' @pytest.mark.parametrize. (Default: %(default)s)',
)
option_manager.add_option(
'--pytest-parametrize-values-type',
choices=enum_choices(ParametrizeValuesType),
parse_from_config=True,
default=DEFAULT_CONFIG.parametrize_values_type.value,
help='Preferred type for values in @pytest.mark.parametrize.'
' (Default: %(default)s)',
)
option_manager.add_option(
'--pytest-parametrize-values-row-type',
choices=enum_choices(ParametrizeValuesRowType),
parse_from_config=True,
default=DEFAULT_CONFIG.parametrize_values_row_type.value,
help='Preferred type for each row in @pytest.mark.parametrize'
' in case of multiple parameters. (Default: %(default)s)',
)
option_manager.add_option(
'--pytest-mark-no-parentheses',
action='store_true',
parse_from_config=True,
default=not DEFAULT_CONFIG.mark_parentheses,
help='Omit parentheses for @pytest.mark.foo decorators'
' without parameters. (Default: %(default)s)',
)
@classmethod
def parse_options_to_config( # pylint: disable=unused-argument
cls, option_manager: OptionManager, options: argparse.Namespace, args: List[str]
) -> Config:
return Config(
fixture_parentheses=not options.pytest_fixture_no_parentheses,
raises_require_match_for=options.pytest_raises_require_match_for,
parametrize_names_type=ParametrizeNamesType(
options.pytest_parametrize_names_type
),
parametrize_values_type=ParametrizeValuesType(
options.pytest_parametrize_values_type
),
parametrize_values_row_type=ParametrizeValuesRowType(
options.pytest_parametrize_values_row_type
),
mark_parentheses=not options.pytest_mark_no_parentheses,
)