Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff drop in replacement #52

Merged
merged 5 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install tox
- uses: psf/black@stable
with:
options: "--check --verbose --diff --color"
- uses: isort/isort-action@master
with:
configuration: "--check-only --diff"
- name: Analysing formatting
run: |
tox -e format-check
- name: Analysing the code style
run: |
tox -e codestyle
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,10 @@ log_cli = false

[tool.mypy]
ignore_missing_imports = true

[tool.ruff.lint]
ignore = ["C901", "E203"]
pydocstyle.convention = "google"

[tool.ruff.format]
quote-style = "double"
5 changes: 4 additions & 1 deletion src/pytest_fluent/content_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,23 @@ def patch(
self,
content: dict,
stage_name: typing.Optional[str] = None,
ignore_entries: typing.List[str] = [],
ignore_entries: typing.Optional[typing.List[str]] = None,
) -> dict:
"""Patch the content with the provided settings for each stage.

Args:
content (dict): Structured data for transmission.
stage_name (typing.Optional[str], optional): Calling stage name.
Defaults to None.
ignore_entries (typing.List[str], optional): List of keys to ignore.

Returns:
dict: Patched dictionary with the user provided stage settings.
""" # noqa
if stage_name is None:
stage_name = inspect.stack()[1][3]
if ignore_entries is None:
ignore_entries = []

stage_info = self._user_settings.get(stage_name, {})
stage_info = {k: v for k, v in stage_info.items() if k not in ignore_entries}
Expand Down
1 change: 1 addition & 0 deletions src/pytest_fluent/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __call__(self, tag: str, label: str, data: dict, **kwargs):
tag (str): Fluent tag.
label (str): Fluent label.
data (dict): Data to transmit as dictionary.
**kwargs: Additional arguments
"""
assert isinstance(data, dict), "data must be a dict"
# Return if tag is empty string
Expand Down
4 changes: 2 additions & 2 deletions src/pytest_fluent/importlib_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def extract_function_from_module_string(
class_name (str): The name of the record formatter class.
module (typing.Optional[str], optional): Module name string or more descriptive
dictionary. Defaults to None.
module (typing.Optional[str], optional): Module name string or more descriptive
dictionary. Defaults to None.
file_path (typing.Optional[str], optional): File path to the module.
Defaults to None.

Returns:
typing.Type[logging.Formatter]: The extract record formatter class.
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_fluent/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def get_formatter(patcher: typing.Optional[ContentPatcher] = None) -> logging.Fo


def load_record_formatter_class(
record_formatter_settings: typing.Dict[str, str]
record_formatter_settings: typing.Dict[str, str],
) -> logging.Formatter:
"""Load a custom record formatter.

Expand Down
6 changes: 5 additions & 1 deletion src/pytest_fluent/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@


class LogReport(object):
"""Log test results."""

def __init__(self, config):
"""Initialize log report."""
self.config = config
super(LogReport, self).__init__()

Expand Down Expand Up @@ -84,6 +87,7 @@ def create_report_with_verdict(
if_val: str,
else_val: str,
) -> dict:
"""Create test report dataset with verdict."""
if predicate(report):
return self.create_report(report, if_val)
else:
Expand All @@ -108,7 +112,7 @@ def create_report(
return test_data

def get_worker_id(self):
"""Extract the worker id"""
"""Extract the worker id."""
worker_id = "default"
if hasattr(self.config, "workerinput"):
worker_id = self.config.workerinput["workerid"]
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from unittest.mock import MagicMock, patch

import pytest
from fluent import handler

import pytest_fluent.event
from fluent import handler

plugin_name = "pytest_fluent"
SESSION_UUID = uuid.uuid4()
Expand Down
2 changes: 0 additions & 2 deletions tests/test_additional_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from unittest.mock import patch

import pytest

import pytest_fluent.additional_information
from pytest_fluent import (
additional_information_callback,
Expand All @@ -13,7 +12,6 @@


def test_allowed_input():

def add_1() -> dict:
return {}

Expand Down
1 change: 0 additions & 1 deletion tests/test_content_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import uuid

import pytest

from pytest_fluent.content_patcher import ContentPatcher, _ContentType
from pytest_fluent.plugin import FluentLoggerRuntime

Expand Down
1 change: 0 additions & 1 deletion tests/test_importlib_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import types

import pytest

from pytest_fluent.importlib_utils import (
extract_function_from_module_string,
load_module_from_path,
Expand Down
3 changes: 1 addition & 2 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from io import StringIO

import pytest
from ruamel.yaml import YAML

from pytest_fluent.setting_file_loader_action import SettingFileLoaderAction
from ruamel.yaml import YAML

parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down
29 changes: 14 additions & 15 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ description = Autoformat code.
skip_install = true
envdir = {toxworkdir}/lint
deps =
black
isort >= 5.0
ruff
commands =
isort {posargs:src/ tests/}
black {posargs:src/ tests/}
ruff check --select I --fix {posargs:src/ tests/}
ruff format {posargs:src/ tests/}

[testenv:format-check]
description = Check code style using black.
skip_install = true
envdir = {toxworkdir}/lint
deps =
black
ruff
commands =
black --check {posargs:src/ tests/}
ruff format --check {posargs:src/ tests/}
ruff check --select I --diff {posargs:src/ tests/}

[testenv:lint]
description = Check code for stylistic and logical errors.
Expand All @@ -48,27 +48,26 @@ description = Check code and tests for PEP 8 compliance and code complexity.
skip_install = true
envdir = {toxworkdir}/lint
deps =
flake8
isort >= 5.0
ruff
commands =
flake8 --select E,W,C --show-source {posargs:src/ tests/}
isort --check --diff {posargs:src/ tests/}
ruff check {posargs:src/ tests/} --select E,W,C --ignore C901
ruff check {posargs:src/ tests/} --select I --diff

[testenv:docstyle]
description = Check docstrings for PEP 257 compliance (Google style).
skip_install = true
envdir = {toxworkdir}/lint
deps =
pydocstyle
commands = pydocstyle {posargs:src/}
ruff
commands = ruff check {posargs:src/} --select D

[testenv:flake]
description = Find errors with static code analysis.
description = Find errors with Flake.
envdir = {toxworkdir}/lint
deps =
flake8
ruff
commands =
flake8 --select F {posargs:src/ tests/}
ruff check {posargs:src/ tests/} --select F

[testenv:pylint]
description = Find errors with static code analysis.
Expand Down
Loading