Skip to content

Commit

Permalink
Merge 4f85fed into 36ba28f
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Mar 23, 2020
2 parents 36ba28f + 4f85fed commit 6985679
Show file tree
Hide file tree
Showing 24 changed files with 664 additions and 89 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -203,3 +203,6 @@ fabric.properties
# Used for testing:
ex.py
setup.py

# Usually you don't need to gitignore this file, but we use it for testing:
/.flake8-baseline.json
2 changes: 2 additions & 0 deletions .importlinter
Expand Up @@ -13,6 +13,7 @@ containers =
layers =
checker
formatter
patches
transformations
presets
visitors
Expand Down Expand Up @@ -74,6 +75,7 @@ ignore_imports =
# These modules must import from flake8 to provide required API:
wemake_python_styleguide.checker -> flake8
wemake_python_styleguide.formatter -> flake8
wemake_python_styleguide.patches.baseline -> flake8
wemake_python_styleguide.options.config -> flake8
# We disallow direct imports of our dependencies from anywhere, except:
wemake_python_styleguide.formatter -> pygments
Expand Down
46 changes: 23 additions & 23 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions setup.cfg
Expand Up @@ -106,15 +106,16 @@ addopts =
[coverage:run]
# Coverage configuration: https://coverage.readthedocs.io/

# We don't need to cover some files. They are fully checked with mypy.
# And don't contain any logic.
omit =
wemake_python_styleguide/types.py

# Here we specify plugins for coverage to be used:
plugins =
coverage_conditional_plugin

[coverage:report]
# We exclude two lines from default coverage:
exclude_lines =
\# pragma: no cover\b
^ +\.\.\.$

[coverage:coverage_conditional_plugin]
# Here we specify our pragma rules:
rules =
Expand Down
11 changes: 1 addition & 10 deletions tests/conftest.py
@@ -1,27 +1,18 @@
import os
from collections import namedtuple

import pytest

from wemake_python_styleguide.options.config import Configuration

pytest_plugins = [
'plugins.files',
'plugins.violations',
'plugins.ast_tree',
'plugins.tokenize_parser',
'plugins.async_sync',
]


@pytest.fixture(scope='session')
def absolute_path():
"""Fixture to create full path relative to `contest.py` inside tests."""
def factory(*files: str):
dirname = os.path.dirname(__file__)
return os.path.join(dirname, *files)
return factory


@pytest.fixture(scope='session')
def options():
"""Returns the options builder."""
Expand Down
46 changes: 46 additions & 0 deletions tests/plugins/files.py
@@ -0,0 +1,46 @@
import os

import pytest

_TEMP_FOLDER = 'tmp'
_MODE_EXECUTABLE = 0o755
_MODE_NON_EXECUTABLE = 0o644


@pytest.fixture()
def make_file(tmp_path):
"""Fixture to make a temporary executable or non executable file."""
def factory(
filename: str,
file_content: str,
*,
is_executable: bool = False,
) -> str:
temp_folder = tmp_path / _TEMP_FOLDER
temp_folder.mkdir(exist_ok=True)
test_file = temp_folder / filename
file_mode = _MODE_EXECUTABLE if is_executable else _MODE_NON_EXECUTABLE

test_file.write_text(file_content)
os.chmod(test_file.as_posix(), file_mode)

return test_file.as_posix()
return factory


@pytest.fixture(scope='session')
def read_file(absolute_path):
"""Fixture to get the file contents."""
def factory(filename: str) -> str:
with open(filename) as file_obj:
return file_obj.read()
return factory


@pytest.fixture(scope='session')
def absolute_path():
"""Fixture to create full path relative to `contest.py` inside tests."""
def factory(*files: str):
dirname = os.path.dirname(os.path.dirname(__file__))
return os.path.join(dirname, *files)
return factory
3 changes: 1 addition & 2 deletions tests/plugins/tokenize_parser.py
Expand Up @@ -19,6 +19,5 @@ def parse_file_tokens(parse_tokens):
"""Parses tokens from a file."""
def factory(filename: str):
with open(filename, 'r', encoding='utf-8') as test_file:
file_content = test_file.read()
return parse_tokens(file_content)
return parse_tokens(test_file.read())
return factory

0 comments on commit 6985679

Please sign in to comment.