Skip to content

Commit

Permalink
Version 0.0.9 release
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Sep 6, 2018
1 parent 656aa73 commit 5b23c65
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 127 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
We follow Semantic Versions since the `0.1.0` release.


## Version 0.0.9

This is just a supporting release.
There are no new features introduced.

### Bugfixes

- Fixes `Attribute has no 'id'` error
- Fixes `missing 'typing_extension'` error

### Misc

- Errors are now tested
- Complexity tests are refactored


## Version 0.0.8 aka The Complex Complexity

### Features
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "wemake-python-styleguide"
version = "0.0.8"
version = "0.0.9"
description = "Opinionated styleguide that we use in wemake.services"

license = "MIT"
Expand Down
15 changes: 12 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ def _is_error_class(cls) -> bool:
@pytest.fixture(scope='session')
def all_errors():
"""Loads all errors from the package."""
return list( # TODO: fix errors' checks
map(itemgetter(1), inspect.getmembers(errors, _is_error_class)),
)
modules = [
errors.imports,
errors.general,
errors.classes,
errors.complexity,
]

classes = []
for module in modules:
classes.extend(inspect.getmembers(module, _is_error_class))

return list(map(itemgetter(1), classes))


@pytest.fixture(scope='session')
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
56 changes: 0 additions & 56 deletions tests/fixtures/wrong_variable.py

This file was deleted.

6 changes: 1 addition & 5 deletions tests/test_checkers/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@


@pytest.mark.parametrize('filename, option_flag, option_value, error_code', [
('wrong_variables.py', '--max-local-variables', '100', b'Z150'),
('wrong_arguments.py', '--max-arguments', '100', b'Z151'),
('wrong_returns.py', '--max-returns', '100', b'Z153'),
('wrong_expressions.py', '--max-expressions', '100', b'Z154'),
('wrong_variables.py', '--min-variable-length', '0', b'Z115'),
])
def test_max_variables_cli_option(
absolute_path,
Expand All @@ -20,7 +16,7 @@ def test_max_variables_cli_option(
error_code,
):
"""Test to check that cli options work."""
fixture = absolute_path('fixtures', 'complexity', filename)
fixture = absolute_path('fixtures', 'config', filename)
process = subprocess.Popen(
['flake8', fixture, option_flag, option_value],
stdout=subprocess.PIPE,
Expand Down
48 changes: 8 additions & 40 deletions tests/test_checkers/test_high_complexity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,21 @@
import subprocess


def test_too_many_variables_in_fixture(absolute_path):
"""End-to-End test to check variables count."""
filename = absolute_path('fixtures', 'complexity', 'wrong_variables.py')
process = subprocess.Popen(
['flake8', '--select', 'Z', filename],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, _ = process.communicate()

assert stdout.count(b'Z202') == 2


def test_too_many_arguments_in_fixture(absolute_path):
"""End-to-End test to check arguments count."""
filename = absolute_path('fixtures', 'complexity', 'wrong_arguments.py')
process = subprocess.Popen(
['flake8', '--select', 'Z', filename],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, _ = process.communicate()

assert stdout.count(b'Z203') == 4
"""
End-to-End test to check arguments count.
It is required due to how 'function_type' parameter
works inside 'flake8'.
def test_too_many_returns_in_fixture(absolute_path):
"""End-to-End test to check returns count."""
filename = absolute_path('fixtures', 'complexity', 'wrong_returns.py')
Otherwise it is not set, unit tests can not cover `is_method` correctly.
"""
filename = absolute_path('fixtures', 'config', 'wrong_arguments.py')
process = subprocess.Popen(
['flake8', '--select', 'Z', filename],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, _ = process.communicate()

assert stdout.count(b'Z205') == 1


def test_too_many_expressions_in_fixture(absolute_path):
"""End-to-End test to check expressions count."""
filename = absolute_path('fixtures', 'complexity', 'wrong_expressions.py')
process = subprocess.Popen(
['flake8', '--select', 'Z', filename],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, _ = process.communicate()

assert stdout.count(b'Z206') == 1
assert stdout.count(b'Z203') == 4
19 changes: 0 additions & 19 deletions tests/test_checkers/test_wrong_variable.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-

import pytest

from wemake_python_styleguide.visitors.complexity.function import (
FunctionComplexityVisitor,
TooManyExpressionsViolation,
)

function_without_expressions = """
def function(): ...
"""

function_with_expressions = """
def function():
print(12)
print(12 / 1)
"""


@pytest.mark.parametrize('code', [
function_without_expressions,
function_with_expressions,
])
def test_expressions_correct_count(
assert_errors, parse_ast_tree, code, default_options,
):
"""Testing that expressions counted correctly."""
tree = parse_ast_tree(code)

visiter = FunctionComplexityVisitor(default_options)
visiter.visit(tree)

assert_errors(visiter, [])


@pytest.mark.parametrize('code', [
function_with_expressions,
])
def test_expressions_wrong_count(assert_errors, parse_ast_tree, options, code):
"""Testing that many expressions raises a warning."""
tree = parse_ast_tree(code)

option_values = options(max_expressions=1)
visiter = FunctionComplexityVisitor(option_values)
visiter.visit(tree)

assert_errors(visiter, [TooManyExpressionsViolation])
49 changes: 49 additions & 0 deletions tests/test_visitors/test_complexity/test_function/test_returns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-

import pytest

from wemake_python_styleguide.visitors.complexity.function import (
FunctionComplexityVisitor,
TooManyReturnsViolation,
)

function_without_returns = """
def function(): ...
"""

function_with_returns = """
def function():
if 1 > 2:
return 1
return 0
"""


@pytest.mark.parametrize('code', [
function_without_returns,
function_with_returns,
])
def test_returns_correct_count(
assert_errors, parse_ast_tree, code, default_options,
):
"""Testing that returns counted correctly."""
tree = parse_ast_tree(code)

visiter = FunctionComplexityVisitor(default_options)
visiter.visit(tree)

assert_errors(visiter, [])


@pytest.mark.parametrize('code', [
function_with_returns,
])
def test_returns_wrong_count(assert_errors, parse_ast_tree, options, code):
"""Testing that many returns raises a warning."""
tree = parse_ast_tree(code)

option_values = options(max_returns=1)
visiter = FunctionComplexityVisitor(option_values)
visiter.visit(tree)

assert_errors(visiter, [TooManyReturnsViolation])
7 changes: 5 additions & 2 deletions wemake_python_styleguide/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import ast
from typing import TYPE_CHECKING, Sequence, Tuple, Type, Union

from typing_extensions import Protocol

if TYPE_CHECKING: # pragma: no cover
from typing_extensions import Protocol # noqa: Z101

# This solves cycle imports problem:
from .visitors.base import visitor # noqa: Z100,Z101,F401
else:
# We do not need to do anything if typechecker is not working:
Protocol = object

#: Visitors container, that has all enable visitors' classes:
VisitorSequence = Sequence[Type['visitor.BaseNodeVisitor']]
Expand Down
2 changes: 1 addition & 1 deletion wemake_python_styleguide/visitors/wrong_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _check_metadata(self, node: ast.Assign):
return

for target_node in node.targets:
target_node_id = getattr(target_node, 'id')
target_node_id = getattr(target_node, 'id', None)
if target_node_id in BAD_MODULE_METADATA_VARIABLES:
self.add_error(
WrongModuleMetadataViolation(node, text=target_node_id),
Expand Down

0 comments on commit 5b23c65

Please sign in to comment.