-
-
Notifications
You must be signed in to change notification settings - Fork 384
/
conftest.py
66 lines (49 loc) · 1.92 KB
/
conftest.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
# -*- coding: utf-8 -*-
import ast
from collections import namedtuple
from textwrap import dedent
from typing import Sequence
import pytest
from wemake_python_styleguide.compat import maybe_set_parent
from wemake_python_styleguide.options import defaults
from wemake_python_styleguide.visitors.base import BaseNodeVisitor
@pytest.fixture(scope='session')
def parse_ast_tree():
"""Helper function to convert code to ast."""
def factory(code: str) -> ast.AST:
return maybe_set_parent(ast.parse(dedent(code)))
return factory
@pytest.fixture(scope='session')
def assert_errors():
"""Helper function to assert visitor errors."""
def factory(visitor: BaseNodeVisitor, errors: Sequence[str]):
for index, error in enumerate(visitor.errors):
assert len(errors) > index, visitor.errors
assert error.code == errors[index].code
assert len(visitor.errors) == len(errors)
return factory
@pytest.fixture(scope='session')
def options():
"""Returns the options builder."""
default_values = {
'max_arguments': defaults.MAX_ARGUMENTS,
'max_expressions': defaults.MAX_EXPRESSIONS,
'max_local_variables': defaults.MAX_LOCAL_VARIABLES,
'max_returns': defaults.MAX_RETURNS,
'min_variable_length': defaults.MIN_VARIABLE_LENGTH,
'max_offset_blocks': defaults.MAX_OFFSET_BLOCKS,
'max_elifs': defaults.MAX_ELIFS,
'max_module_members': defaults.MAX_MODULE_MEMBERS,
'max_methods': defaults.MAX_METHODS,
'min_module_name_length': defaults.MIN_MODULE_NAME_LENGTH,
}
Options = namedtuple('options', default_values.keys())
def factory(**kwargs):
final_options = default_values.copy()
final_options.update(kwargs)
return Options(**final_options)
return factory
@pytest.fixture(scope='session')
def default_options(options):
"""Returns the default options."""
return options()