Skip to content

Commit 600e2dd

Browse files
committed
Tests refactoring is finished, closes #295, closes #305
1 parent 810583e commit 600e2dd

File tree

26 files changed

+357
-148
lines changed

26 files changed

+357
-148
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ We used to have incremental versioning before `0.1.0`.
1717

1818
### Bugfixes
1919

20+
- Multiple fixes to error text formats to be more readable
2021
- Fixes `UNDERSCORED_NUMBER_PATTERN` to match names like `come_22_me`
2122
- Fixes `UpperCaseAttributeViolation` not being displayed in the docs
2223
- Fixes consistency checks being duplicated in the docs
@@ -28,6 +29,7 @@ We used to have incremental versioning before `0.1.0`.
2829
- Fixes `TooManyElifsViolation` to show correct text
2930
- Fixes `TooDeepNestingViolation` to show correct text
3031
- Fixes `TooManyMethodsViolation` to show correct text
32+
- Fixes `ReassigningVariableToItselfViolation` to show correct text
3133
- Renames `UnderscoredNumberNameViolation` to `UnderscoredNumberNameViolation`
3234

3335
### Misc

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "wemake-python-styleguide"
33
version = "0.3.0"
4-
description = "The most strict and opinionated python linter ever"
4+
description = "The strictest and most opinionated python linter ever"
55

66
license = "MIT"
77

tests/test_violations/test_docs.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,15 @@ def test_violation_name(all_violations):
2626
for violation in all_violations:
2727
class_name = violation.__qualname__
2828
assert class_name.endswith('Violation'), class_name
29+
30+
31+
def test_violation_error_text(all_violations):
32+
"""Ensures that all violations have correctly format error text."""
33+
for violation in all_violations:
34+
if violation.should_use_text:
35+
error_format = ': {0}'
36+
37+
assert error_format in violation.error_template
38+
assert violation.error_template.endswith(error_format)
39+
else:
40+
assert '{0}' not in violation.error_template

tests/test_visitors/test_ast/test_builtins/test_magic_numbers.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ def function_name(param1, param2={0}):
1818
return param1 / param2
1919
"""
2020

21-
async_function_definition = """
22-
async def function_name(param1, param2={0}):
23-
return param1 / param2
24-
"""
25-
2621
list_definition = '[{0}]'
2722
dict_definition_key = '{{{0}: "value"}}'
2823
dict_definition_value = '{{"first": {0}}}'
@@ -53,12 +48,12 @@ def method(self):
5348
"""
5449

5550
list_index = """
56-
some_list = [1, 2, 3]
51+
some_list = [10, 20, 30]
5752
some_list[{0}]
5853
"""
5954

6055
dict_key = """
61-
some_dict = {{1: 1, 2: 2}}
56+
some_dict = {{11: 12, 13: 14}}
6257
some_dict[{0}]
6358
"""
6459

@@ -67,7 +62,6 @@ def method(self):
6762
assignment,
6863
assignment_unary,
6964
function_definition,
70-
async_function_definition,
7165
list_definition,
7266
dict_definition_key,
7367
dict_definition_value,
@@ -89,9 +83,10 @@ def test_magic_number(
8983
code,
9084
number,
9185
default_options,
86+
mode,
9287
):
9388
"""Testing that there are no magic numbers in this code."""
94-
tree = parse_ast_tree(code.format(number))
89+
tree = parse_ast_tree(mode(code.format(number)))
9590

9691
visitor = MagicNumberVisitor(default_options, tree=tree)
9792
visitor.run()
@@ -123,9 +118,10 @@ def test_magic_number_whitelist(
123118
code,
124119
number,
125120
default_options,
121+
mode,
126122
):
127123
"""Testing that magic numbers in this code are whitelisted."""
128-
tree = parse_ast_tree(code.format(number))
124+
tree = parse_ast_tree(mode(code.format(number)))
129125

130126
visitor = MagicNumberVisitor(default_options, tree=tree)
131127
visitor.run()
@@ -158,9 +154,10 @@ def test_magic_number_warning(
158154
code,
159155
number,
160156
default_options,
157+
mode,
161158
):
162159
"""Testing that magic numbers in this code are warnings."""
163-
tree = parse_ast_tree(code.format(number))
160+
tree = parse_ast_tree(mode(code.format(number)))
164161

165162
visitor = MagicNumberVisitor(default_options, tree=tree)
166163
visitor.run()

tests/test_visitors/test_ast/test_classes/test_base_class.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
)
88
from wemake_python_styleguide.visitors.ast.classes import WrongClassVisitor
99

10-
class_without_base = 'class WithoutBase: ...'
11-
class_with_empty_base = 'class EmptyBase(): ...'
10+
class_without_base = 'class Meta: ...'
11+
class_with_empty_base = 'class Meta(): ...'
1212

1313
nested_class_without_base = """
1414
class Model(object):
@@ -22,7 +22,7 @@ class Meta(): ...
2222

2323
# Correct:
2424

25-
class_with_base = 'class Example({0}): ...'
25+
class_with_base = 'class Meta({0}): ...'
2626

2727
nested_class_with_base = """
2828
class Model({0}):
@@ -38,6 +38,7 @@ class Meta({0}): ...
3838
])
3939
def test_wrong_base_class(
4040
assert_errors,
41+
assert_error_text,
4142
parse_ast_tree,
4243
code,
4344
default_options,
@@ -49,6 +50,7 @@ def test_wrong_base_class(
4950
visitor.run()
5051

5152
assert_errors(visitor, [RequiredBaseClassViolation])
53+
assert_error_text(visitor, 'Meta')
5254

5355

5456
@pytest.mark.parametrize('code', [

tests/test_visitors/test_ast/test_classes/test_magic_methods.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def {0}(): ...
1717
@pytest.mark.parametrize('method', MAGIC_METHODS_BLACKLIST)
1818
def test_wrong_magic_used(
1919
assert_errors,
20+
assert_error_text,
2021
parse_ast_tree,
2122
method,
2223
mode,
@@ -29,6 +30,7 @@ def test_wrong_magic_used(
2930
visitor.run()
3031

3132
assert_errors(visitor, [BadMagicMethodViolation])
33+
assert_error_text(visitor, method)
3234

3335

3436
@pytest.mark.parametrize('method', [

tests/test_visitors/test_ast/test_complexity/test_nested/test_nested_classes.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,21 @@ class {0}(object): ...
3434
])
3535
def test_nested_class(
3636
assert_errors,
37+
assert_error_text,
3738
parse_ast_tree,
3839
code,
3940
default_options,
4041
mode,
4142
):
4243
"""Testing that nested classes are restricted."""
43-
tree = parse_ast_tree(mode(code.format('NestedClass')))
44+
nested_name = 'NestedClass'
45+
tree = parse_ast_tree(mode(code.format(nested_name)))
4446

4547
visitor = NestedComplexityVisitor(default_options, tree=tree)
4648
visitor.run()
4749

4850
assert_errors(visitor, [NestedClassViolation])
51+
assert_error_text(visitor, nested_name)
4952

5053

5154
@pytest.mark.parametrize('whitelist_name', NESTED_CLASSES_WHITELIST)
@@ -79,6 +82,7 @@ def test_whitelist_nested_classes(
7982
])
8083
def test_whitelist_nested_classes_in_functions(
8184
assert_errors,
85+
assert_error_text,
8286
parse_ast_tree,
8387
whitelist_name,
8488
code,
@@ -92,6 +96,7 @@ def test_whitelist_nested_classes_in_functions(
9296
visitor.run()
9397

9498
assert_errors(visitor, [NestedClassViolation])
99+
assert_error_text(visitor, whitelist_name)
95100

96101

97102
def test_ordinary_class(

tests/test_visitors/test_ast/test_complexity/test_nested/test_nested_functions.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,22 @@ def container(self):
9393
nested_function_in_async_method,
9494
nested_async_function_in_async_method,
9595
])
96-
def test_nested_function(assert_errors, parse_ast_tree, code, default_options):
96+
def test_nested_function(
97+
assert_errors,
98+
assert_error_text,
99+
parse_ast_tree,
100+
code,
101+
default_options,
102+
):
97103
"""Testing that nested functions are restricted."""
98-
tree = parse_ast_tree(code.format('nested'))
104+
nested_name = 'nested'
105+
tree = parse_ast_tree(code.format(nested_name))
99106

100107
visitor = NestedComplexityVisitor(default_options, tree=tree)
101108
visitor.run()
102109

103110
assert_errors(visitor, [NestedFunctionViolation])
111+
assert_error_text(visitor, nested_name)
104112

105113

106114
@pytest.mark.parametrize('whitelist_name', NESTED_FUNCTIONS_WHITELIST)
@@ -115,7 +123,11 @@ def test_nested_function(assert_errors, parse_ast_tree, code, default_options):
115123
nested_async_function_in_async_method,
116124
])
117125
def test_whitelist_nested_functions(
118-
assert_errors, parse_ast_tree, whitelist_name, code, default_options,
126+
assert_errors,
127+
parse_ast_tree,
128+
whitelist_name,
129+
code,
130+
default_options,
119131
):
120132
"""Testing that it is possible to nest whitelisted functions."""
121133
tree = parse_ast_tree(code.format(whitelist_name))
@@ -133,7 +145,10 @@ def test_whitelist_nested_functions(
133145
lambda_in_async_method,
134146
])
135147
def test_lambda_nested_functions(
136-
assert_errors, parse_ast_tree, code, default_options,
148+
assert_errors,
149+
parse_ast_tree,
150+
code,
151+
default_options,
137152
):
138153
"""Testing that it is possible to nest lambda inside functions."""
139154
tree = parse_ast_tree(code)
@@ -144,7 +159,12 @@ def test_lambda_nested_functions(
144159
assert_errors(visitor, [])
145160

146161

147-
def test_lambda_nested_lambdas(assert_errors, parse_ast_tree, default_options):
162+
def test_lambda_nested_lambdas(
163+
assert_errors,
164+
assert_error_text,
165+
parse_ast_tree,
166+
default_options,
167+
):
148168
"""
149169
Testing that it is restricted to nest lambdas.
150170
@@ -159,3 +179,4 @@ def container():
159179
visitor.run()
160180

161181
assert_errors(visitor, [NestedFunctionViolation])
182+
assert_error_text(visitor, 'lambda')

tests/test_visitors/test_ast/test_functions/test_wrong_function_calls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def proxy(*args, **kwargs):
2727
])
2828
def test_wrong_function_called(
2929
assert_errors,
30+
assert_error_text,
3031
parse_ast_tree,
3132
bad_function,
3233
code,
@@ -40,6 +41,7 @@ def test_wrong_function_called(
4041
visitor.run()
4142

4243
assert_errors(visitor, [WrongFunctionCallViolation])
44+
assert_error_text(visitor, bad_function)
4345

4446

4547
@pytest.mark.parametrize('good_function', [

tests/test_visitors/test_ast/test_imports/test_dotted_raw_import.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
'nested.dotted.path',
2323
])
2424
def test_wrong_dotted_import(
25-
assert_errors, parse_ast_tree, code, to_import, default_options,
25+
assert_errors,
26+
assert_error_text,
27+
parse_ast_tree,
28+
code,
29+
to_import,
30+
default_options,
2631
):
2732
"""Testing that dotted raw imports are restricted."""
2833
tree = parse_ast_tree(code.format(to_import))
@@ -31,6 +36,7 @@ def test_wrong_dotted_import(
3136
visitor.run()
3237

3338
assert_errors(visitor, [DottedRawImportViolation])
39+
assert_error_text(visitor, to_import)
3440

3541

3642
@pytest.mark.parametrize('code', [
@@ -42,7 +48,11 @@ def test_wrong_dotted_import(
4248
'sys',
4349
])
4450
def test_correct_flat_import(
45-
assert_errors, parse_ast_tree, code, to_import, default_options,
51+
assert_errors,
52+
parse_ast_tree,
53+
code,
54+
to_import,
55+
default_options,
4656
):
4757
"""Testing that flat raw imports are allowed."""
4858
tree = parse_ast_tree(code.format(to_import))
@@ -63,7 +73,11 @@ def test_correct_flat_import(
6373
'nested.dotted.path',
6474
])
6575
def test_regular_from_import(
66-
assert_errors, parse_ast_tree, code, to_import, default_options,
76+
assert_errors,
77+
parse_ast_tree,
78+
code,
79+
to_import,
80+
default_options,
6781
):
6882
"""Testing that dotted `from` imports are allowed."""
6983
tree = parse_ast_tree(code.format(to_import))

0 commit comments

Comments
 (0)