-
-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from wemake-services/version-0014
WIP: version 0.0.14
- Loading branch information
Showing
75 changed files
with
1,659 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "wemake-python-styleguide" | ||
version = "0.0.13" | ||
version = "0.0.14" | ||
description = "The most opinionated linter ever, used by wemake.services" | ||
|
||
license = "MIT" | ||
|
@@ -9,7 +9,7 @@ authors = [ | |
"Nikita Sobolev <[email protected]>" | ||
] | ||
|
||
readme = "README.md" # Markdown files are supported | ||
readme = "README.md" | ||
|
||
repository = "https://github.com/wemake-services/wemake-python-styleguide" | ||
homepage = "https://github.com/wemake-services/wemake-python-styleguide" | ||
|
@@ -20,10 +20,11 @@ keywords = [ | |
"linting", | ||
"wemake.services", | ||
"styleguide", | ||
"code quality" | ||
] | ||
|
||
classifiers = [ | ||
"Development Status :: 3 - Alpha", | ||
"Development Status :: 4 - Beta", | ||
"Environment :: Console", | ||
"Framework :: Flake8", | ||
"Intended Audience :: Developers", | ||
|
@@ -38,6 +39,7 @@ Z = "wemake_python_styleguide.checker:Checker" | |
[tool.poetry.dependencies] | ||
python = "^3.6 || ^3.7" | ||
flake8 = "^3.5" | ||
attrs = "^18.2" | ||
|
||
# This is a fix for issue-118 | ||
pycodestyle = "==2.3.1" | ||
|
@@ -49,27 +51,29 @@ flake8-comprehensions = "^1.4" | |
flake8-docstrings = "^1.3" | ||
flake8-string-format = "^0.2" | ||
flake8-coding = "^1.3" | ||
flake8-module-name = "^0.1" | ||
flake8-bugbear = "^18.2" | ||
flake8-pep3101 = "^1.2" | ||
flake8-super-call = "^1.0" | ||
flake8-debugger = "^3.1" | ||
flake8-isort = "^2.5" | ||
flake8-eradicate = "^0.1" | ||
pep8-naming = "^0.7" | ||
flake8-bandit = "^1.0" | ||
|
||
[tool.poetry.dev-dependencies] | ||
pytest-cov = "^2.6" | ||
pytest-flake8 = "^1.0" | ||
pytest-randomly = "^1.2" | ||
pytest-isort = "^0.2" | ||
pytest = "^3.8" | ||
flake8-pytest = "^1.3" | ||
mypy = "^0.610.0" | ||
flake8-print = "^3.1" | ||
mypy = "^0.630" | ||
sphinx = "^1.8" | ||
sphinx-autodoc-typehints = "^1.3" | ||
sphinxcontrib-napoleon = "^0.6" | ||
doc8 = "^0.8" | ||
m2r = "^0.2" | ||
sphinx_readable_theme = "^1.3" | ||
typing_extensions = "^3.6" | ||
added-value = "^0.8.0" | ||
pytest-isort = "^0.2.1" | ||
added-value = "^0.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import ast | ||
|
||
from wemake_python_styleguide.errors.base import ( | ||
ASTStyleViolation, | ||
BaseStyleViolation, | ||
) | ||
|
||
|
||
def test_visitor_returns_location(): | ||
"""Ensures that `BaseNodeVisitor` return correct error message.""" | ||
visitor = ASTStyleViolation(node=ast.parse(''), text='error') | ||
visitor.error_template = '{0} {1}' | ||
visitor.code = 1 | ||
assert visitor.node_items() == (0, 0, 'Z001 error') | ||
|
||
|
||
def test_checker_default_location(): | ||
"""Ensures that `BaseStyleViolation` returns correct location.""" | ||
assert BaseStyleViolation(None)._location() == (0, 0) | ||
|
||
|
||
def test_all_unique_error_codes(all_errors): | ||
"""Ensures that all errors have unique error codes.""" | ||
codes = [] | ||
for error in all_errors: | ||
codes.append(error.code) | ||
codes.append(int(error.code)) | ||
|
||
assert len(set(codes)) == len(all_errors) | ||
|
||
|
||
def test_all_errors_have_description_with_code(all_errors): | ||
"""Ensures that all errors have description with error code.""" | ||
for error in all_errors: | ||
assert error.code in error.__doc__ | ||
assert str(error.code) in error.__doc__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import ast | ||
from textwrap import dedent | ||
|
||
import pytest | ||
|
||
|
||
def _maybe_set_parent(tree: ast.AST) -> ast.AST: | ||
""" | ||
Sets parents for all nodes that do not have this prop. | ||
This step is required due to how `flake8` works. | ||
It does not set the same properties as `ast` module. | ||
This function was the cause of `issue-112`. | ||
.. versionchanged:: 0.0.11 | ||
""" | ||
for statement in ast.walk(tree): | ||
for child in ast.iter_child_nodes(statement): | ||
if not hasattr(child, 'parent'): # noqa: Z112 | ||
setattr(child, 'parent', statement) | ||
|
||
return tree | ||
|
||
|
||
@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 |
53 changes: 53 additions & 0 deletions
53
tests/test_visitors/test_ast/test_complexity/test_counts/test_imports_counts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.visitors.ast.complexity.counts import ( | ||
ImportMembersVisitor, | ||
TooManyImportsViolation, | ||
) | ||
|
||
module_import = '' | ||
module_with_regular_imports = """ | ||
import sys | ||
import os | ||
""" | ||
|
||
module_with_from_imports = """ | ||
from os import path | ||
from sys import version | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
module_import, | ||
module_with_regular_imports, | ||
module_with_from_imports, | ||
]) | ||
def test_module_import_counts_normal( | ||
assert_errors, parse_ast_tree, code, default_options, | ||
): | ||
"""Testing that imports in a module work well.""" | ||
tree = parse_ast_tree(code) | ||
|
||
visitor = ImportMembersVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, []) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
module_with_regular_imports, | ||
module_with_from_imports, | ||
]) | ||
def test_module_import_counts_violation( | ||
assert_errors, parse_ast_tree, code, options, | ||
): | ||
"""Testing that violations are raised when reaching max value.""" | ||
tree = parse_ast_tree(code) | ||
|
||
option_values = options(max_imports=1) | ||
visitor = ImportMembersVisitor(option_values, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [TooManyImportsViolation]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.