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

Switch to ruff in tests and precommit #786

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 15 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
hooks:
- id: ruff
name: Check ruff for zwave_js_server
files: ^(zwave_js_server)/.+\.py$
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
hooks:
- id: ruff
name: Check ruff for scripts and test
files: ^(scripts|test)/.+\.py$
args: [--fix, --exit-non-zero-on-fix, --select, I001, D210, D400, D403, D415]
raman325 marked this conversation as resolved.
Show resolved Hide resolved
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
Expand All @@ -17,11 +31,6 @@ repos:
hooks:
- id: pydocstyle
files: ^(zwave_js_server|test)/.+\.py$
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
files: ^((zwave_js_server|test)/.+)?[^/]+\.py$
- repo: local
hooks:
- id: mypy
Expand All @@ -33,7 +42,7 @@ repos:
files: ^(zwave_js_server)/.+\.py$
- id: pylint
name: pylint
entry: scripts/run-in-env.sh pylint -j 0 --ignore-missing-annotations=y
entry: scripts/run-in-env.sh pylint -j 0
language: script
types: [python]
files: ^zwave_js_server/.+\.py$
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[tool.ruff]
select = [
"D",
"E",
"F",
"G",
"I",
"PLC",
"PLE",
"PLR",
"PLW",
"UP",
"W",
]
ignore = [
"D202",
"D212",
"D203",
"D213",
"E501",
"PLR0911", # Too many return statements ({returns} > {max_returns})
"PLR0912", # Too many branches ({branches} > {max_branches})
"PLR0913", # Too many arguments to function call ({c_args} > {max_args})
"PLR0915", # Too many statements ({statements} > {max_statements})
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
"PLW2901", # Outer {outer_kind} variable {name} overwritten by inner {inner_kind} target
"UP006", # keep type annotation style as is
"UP007", # keep type annotation style as is
]
exclude = [
".venv",
".git",
".tox",
"docs",
"venv",
"bin",
"lib",
"deps",
"build",
]
line-length = 88

[tool.ruff.isort]
force-sort-within-sections = true
known-first-party = [
"zwave_js_server",
]
combine-as-imports = true
split-on-trailing-comma = false
case-sensitive = true
3 changes: 1 addition & 2 deletions requirements_lint.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
black==23.9.1
flake8==6.1.0
mypy==1.5.1
pydocstyle==6.3.0
pylint==3.0.1
pylint-strict-informational==0.1
pre-commit==3.5.0
ruff==0.0.292
4 changes: 2 additions & 2 deletions scripts/generate_multilevel_sensor_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"""Script to generate Multilevel Sensor CC constants."""
from __future__ import annotations

from collections import defaultdict
from collections.abc import Callable, Mapping
import json
import pathlib
import re
import subprocess
from collections import defaultdict
from collections.abc import Callable, Mapping

import requests
from slugify import slugify
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_notification_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"""Script to generate Notification CC constants."""
from __future__ import annotations

from collections.abc import Callable, Mapping
import json
import pathlib
import re
import subprocess
from collections.abc import Callable, Mapping

import requests
from slugify import slugify
Expand Down
4 changes: 2 additions & 2 deletions scripts/run_mock_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import argparse
import asyncio
import json
import logging
from collections import defaultdict
from collections.abc import Hashable
import json
import logging
from typing import Any

from aiohttp import WSMsgType, web, web_request
Expand Down
28 changes: 1 addition & 27 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
[flake8]
exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build
# To work with Black
max-line-length = 88
# E501: line too long
# W503: Line break occurred before a binary operator
# E203: Whitespace before ':'
# D202 No blank lines allowed after function docstring
# W504 line break after binary operator
ignore =
E501,
W503,
E203,
D202,
W504

[isort]
multi_line_output = 3
include_trailing_comma = True
force_grid_wrap = 0
use_parentheses = True
line_length = 88

[mypy]
plugins = pydantic.mypy
follow_imports = skip
Expand All @@ -29,7 +6,7 @@ check_untyped_defs = true
disallow_incomplete_defs = true
disallow_untyped_calls = true
disallow_untyped_defs = true
warn_return_any = true
warn_return_any = false
warn_unreachable = true
warn_unused_ignores = true
warn_incomplete_stub = true
Expand All @@ -39,8 +16,5 @@ warn_unused_configs = true
[mypy-test.*,]
ignore_errors = true

[pydocstyle]
add-ignore = D202

[tool:pytest]
asyncio_mode = auto
4 changes: 2 additions & 2 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Provide common pytest fixtures."""
import asyncio
import json
from collections import deque
from copy import deepcopy
import json
from unittest.mock import AsyncMock, Mock, patch

import pytest
from aiohttp import ClientSession, ClientWebSocketResponse
from aiohttp.http_websocket import WSMessage, WSMsgType
import pytest

from zwave_js_server.client import Client
from zwave_js_server.model.controller import Controller
Expand Down
16 changes: 10 additions & 6 deletions test/model/test_controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test the controller model."""
import json
from copy import deepcopy
import json
from unittest.mock import patch

import pytest
Expand All @@ -21,8 +21,10 @@
)
from zwave_js_server.event import Event
from zwave_js_server.exceptions import RepeaterRssiErrorReceived, RssiErrorReceived
from zwave_js_server.model import association as association_pkg
from zwave_js_server.model import controller as controller_pkg
from zwave_js_server.model import (
association as association_pkg,
controller as controller_pkg,
)
from zwave_js_server.model.controller.firmware import ControllerFirmwareUpdateStatus
from zwave_js_server.model.controller.rebuild_routes import (
RebuildRoutesOptions,
Expand Down Expand Up @@ -183,7 +185,7 @@ def test_controller_mods():


def test_controller_status():
""" "Test controller status functionality."""
"""Test controller status functionality."""
state = json.loads(load_fixture("basic_dump.txt").split("\n")[0])["result"]["state"]
state["controller"]["status"] = 0

Expand Down Expand Up @@ -425,7 +427,8 @@ async def test_begin_inclusion_errors(controller, uuid4, mock_command):
InclusionStrategy.SECURITY_S0, dsk="test"
)

# Test that Security S2 Inclusion Strategy doesn't support providing `force_security`
# Test that Security S2 Inclusion Strategy doesn't support providing
# `force_security`
with pytest.raises(ValueError):
await controller.async_begin_inclusion(
InclusionStrategy.SECURITY_S2, force_security=True
Expand Down Expand Up @@ -1845,7 +1848,8 @@ async def test_get_available_firmware_updates(multisensor_6, uuid4, mock_command
{"command": "controller.get_available_firmware_updates"},
{"updates": [FIRMWARE_UPDATE_INFO]},
)
updates = await multisensor_6.client.driver.controller.async_get_available_firmware_updates(
controller = multisensor_6.client.driver.controller
updates = await controller.async_get_available_firmware_updates(
multisensor_6, "test"
)
assert len(updates) == 1
Expand Down
8 changes: 5 additions & 3 deletions test/model/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

from zwave_js_server.const import LogLevel
from zwave_js_server.event import Event
from zwave_js_server.model import driver as driver_pkg
from zwave_js_server.model import log_config as log_config_pkg
from zwave_js_server.model import log_message as log_message_pkg
from zwave_js_server.model import (
driver as driver_pkg,
log_config as log_config_pkg,
log_message as log_message_pkg,
)

from .. import load_fixture

Expand Down
10 changes: 5 additions & 5 deletions test/model/test_node.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Test the node model."""
import asyncio
import json
from copy import deepcopy
from datetime import datetime, timezone
import json
from typing import Any
from unittest.mock import AsyncMock, patch

Expand Down Expand Up @@ -34,8 +34,7 @@
RssiErrorReceived,
UnwriteableValue,
)
from zwave_js_server.model import endpoint as endpoint_pkg
from zwave_js_server.model import node as node_pkg
from zwave_js_server.model import endpoint as endpoint_pkg, node as node_pkg
from zwave_js_server.model.node.firmware import (
NodeFirmwareUpdateInfo,
NodeFirmwareUpdateStatus,
Expand Down Expand Up @@ -183,7 +182,7 @@ def test_from_state(client):


async def test_highest_security_value(lock_schlage_be469, ring_keypad):
"""Test the highest_security_class property"""
"""Test the highest_security_class property."""
assert lock_schlage_be469.highest_security_class == SecurityClass.S0_LEGACY
assert ring_keypad.highest_security_class is None

Expand Down Expand Up @@ -238,7 +237,8 @@ async def test_device_config(
"controller being inoperable or otherwise unavailable.)"
)
assert device_config.metadata.manual == (
"https://products.z-wavealliance.org/ProductManual/File?folder=&filename=MarketCertificationFiles/2479/ZP3111-5_R2_20170316.pdf"
"https://products.z-wavealliance.org/ProductManual/File?folder=&filename="
"MarketCertificationFiles/2479/ZP3111-5_R2_20170316.pdf"
)
assert device_config.metadata.wakeup is None
assert device_config.metadata.comments == [{"level": "info", "text": "test"}]
Expand Down
4 changes: 2 additions & 2 deletions test/test_client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Test the client."""
import asyncio
import logging
from datetime import datetime
import logging
from unittest.mock import Mock, patch

import pytest
from aiohttp.client_exceptions import ClientError, WSServerHandshakeError
from aiohttp.client_reqrep import ClientResponse, RequestInfo
from aiohttp.http_websocket import WSMsgType
import pytest

from zwave_js_server.client import LOGGER, Client
from zwave_js_server.const import MAX_SERVER_SCHEMA_VERSION, LogLevel, __version__
Expand Down
2 changes: 1 addition & 1 deletion test/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def test_get_server_version(client_session, ws_client, url, version_data):
async def test_missing_server_schema_version(
client_session, ws_client, url, version_data
):
"""test missing schema version processed as schema version 0."""
"""Test missing schema version processed as schema version 0."""
del version_data["minSchemaVersion"]
del version_data["maxSchemaVersion"]
ws_client.receive_json.return_value = version_data
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ basepython = python3
ignore_errors = True
commands =
black --check ./
flake8 zwave_js_server test
ruff check zwave_js_server
ruff check scripts test --select I001,D210,D400,D403,D415
pylint zwave_js_server
pydocstyle zwave_js_server test
deps =
-rrequirements.txt
-rrequirements_lint.txt
Expand Down
Loading