Skip to content

Commit

Permalink
Chore: Format code using Ruff. Phase out Black and isort.
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jan 7, 2025
1 parent ff9e8d1 commit f22f4ab
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 58 deletions.
108 changes: 57 additions & 51 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ name = "pytest-mqtt"
version = "0.4.2"
description = "pytest-mqtt supports testing systems based on MQTT"
readme = "README.rst"
requires-python = ">=3.7"
license = {text = "MIT"}
keywords = ["mqtt", "pytest", "testing", "mosquitto", "paho"]
keywords = [ "mosquitto", "mqtt", "paho", "pytest", "testing" ]
license = { text = "MIT" }
authors = [
{name = "Andreas Motl", email = "andreas.motl@panodata.org"},
{name = "Richard Pobering", email = "richard.pobering@panodata.org"},
{ name = "Andreas Motl", email = "andreas.motl@panodata.org" },
{ name = "Richard Pobering", email = "richard.pobering@panodata.org" },
]
requires-python = ">=3.7"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
Expand All @@ -33,6 +33,7 @@ classifiers = [
"Operating System :: POSIX :: Linux",
"Operating System :: Unix",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
Expand Down Expand Up @@ -61,79 +62,79 @@ dependencies = [
"pytest-docker-fixtures<2",
]

[project.entry-points.pytest11]
capmqtt = "pytest_mqtt.capmqtt"
mosquitto = "pytest_mqtt.mosquitto"

[project.optional-dependencies]
test = [
"coverage<8",
"pytest<9",
"pytest-fixture-order<1",
"pytest-ordering<1",
]
develop = [
"isort<6",
"black<25",
optional-dependencies.develop = [
"mypy<1.12",
"poethepoet<1",
"pyproject-fmt<3",
"ruff<0.9",
"validate-pyproject<0.19",
]
release = [
optional-dependencies.release = [
"build<2",
"twine<7",
]
optional-dependencies.test = [
"coverage<8",
"pytest<9",
"pytest-fixture-order<1",
"pytest-ordering<1",
]
urls.changelog = "https://github.com/mqtt-tools/pytest-mqtt/blob/main/CHANGES.rst"
urls.documentation = "https://github.com/mqtt-tools/pytest-mqtt"
urls.homepage = "https://github.com/mqtt-tools/pytest-mqtt"
urls.repository = "https://github.com/mqtt-tools/pytest-mqtt"
entry-points.pytest11.capmqtt = "pytest_mqtt.capmqtt"
entry-points.pytest11.mosquitto = "pytest_mqtt.mosquitto"

[tool.setuptools]
# https://setuptools.pypa.io/en/latest/userguide/package_discovery.html
packages = ["pytest_mqtt"]

[project.urls]
homepage = "https://github.com/mqtt-tools/pytest-mqtt"
documentation = "https://github.com/mqtt-tools/pytest-mqtt"
repository = "https://github.com/mqtt-tools/pytest-mqtt"
changelog = "https://github.com/mqtt-tools/pytest-mqtt/blob/main/CHANGES.rst"

packages = [ "pytest_mqtt" ]

# ==================
# Tool configuration
# ==================
# Configuration snippets for pytest, coverage, and ruff.

# Configuration snippets for Black, isort, pytest, coverage, and ruff.

[tool.black]
[tool.ruff]
line-length = 120

[tool.isort]
profile = "black"
skip_glob = "**/site-packages/**"
skip_gitignore = false
# src_paths = ["pytest_mqtt", "testing"]

[tool.pytest.ini_options]
minversion = "2.0"
addopts = """
-rfEX -p pytester --strict-markers --verbosity=3
"""
log_level = "DEBUG"
log_cli_level = "DEBUG"
testpaths = ["testing"]
testpaths = [ "testing" ]
xfail_strict = true
markers = [
"capmqtt_decode_utf8: Capture MQTT messages as `str`, not `bytes`",
]

[tool.coverage.run]
branch = false
source = ["pytest_mqtt"]
source = [ "pytest_mqtt" ]

[tool.coverage.report]
fail_under = 0
show_missing = true
omit = [
]

[tool.ruff]
line-length = 120
[tool.mypy]
packages = [ "pytest_mqtt" ]
exclude = [
]
ignore_missing_imports = true
check_untyped_defs = false
implicit_optional = true
install_types = true
no_implicit_optional = true
non_interactive = true
show_error_codes = true
strict_equality = true
warn_unused_ignores = true
warn_redundant_casts = true


# ===================
Expand All @@ -148,25 +149,30 @@ check = [
]

format = [
{cmd="black ."},
{cmd="isort pytest_mqtt testing"},
{ cmd = "ruff format ." },
# Configure Ruff not to auto-fix (remove!):
# unused imports (F401), unused variables (F841), `print` statements (T201), and commented-out code (ERA001).
{ cmd = "ruff check --fix --ignore=ERA --ignore=F401 --ignore=F841 --ignore=T20 --ignore=ERA001 ." },
{ cmd = "pyproject-fmt --keep-full-version pyproject.toml" },
]

lint = [
{cmd="ruff check ."},
{cmd="black --check ."},
{cmd="isort --check pytest_mqtt testing"},
{ cmd = "ruff format --check ." },
{ cmd = "ruff check ." },
{ cmd = "validate-pyproject pyproject.toml" },
{ cmd = "mypy" },
]

# When testing a pytest plugin, `coverage` needs to be
# started before `pytest`. `pytest-cov` will not work.
# https://stackoverflow.com/a/62224494
test = [
{cmd="coverage run -m pytest"},
{cmd="coverage report"},
{cmd="coverage xml"},
{ cmd = "coverage run -m pytest" },
{ cmd = "coverage report" },
{ cmd = "coverage xml" },
]

release = [
{cmd="python -m build"},
{cmd="twine upload --skip-existing dist/*.tar.gz dist/*.whl"},
{ cmd = "python -m build" },
{ cmd = "twine upload --skip-existing dist/*.tar.gz dist/*.whl" },
]
6 changes: 3 additions & 3 deletions pytest_mqtt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
try:
from importlib.metadata import PackageNotFoundError, version # noqa
except ImportError: # pragma:nocover
from importlib_metadata import PackageNotFoundError, version # noqa
except ImportError: # pragma: no cover
from importlib_metadata import PackageNotFoundError, version # type: ignore[no-redef] # noqa

from .model import MqttMessage # noqa:F401
from .model import MqttMessage # noqa: F401

try:
__version__ = version("pytest-mqtt")
Expand Down
5 changes: 3 additions & 2 deletions pytest_mqtt/capmqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
.. _Paho MQTT Python Client: https://github.com/eclipse/paho.mqtt.python
"""

import logging
import threading
import typing as t
Expand Down Expand Up @@ -94,7 +95,7 @@ class MqttCaptureFixture:
def __init__(self, decode_utf8: t.Optional[bool], host: str = "localhost", port: int = 1883) -> None:
"""Creates a new funcarg."""
self._buffer: t.List[MqttMessage] = []
self._decode_utf8: bool = decode_utf8
self._decode_utf8: bool = decode_utf8 or False

self.mqtt_client = MqttClientAdapter(on_message_callback=self.on_message, host=host, port=port)
self.mqtt_client.start()
Expand Down Expand Up @@ -124,7 +125,7 @@ def messages(self) -> t.List[MqttMessage]:
return self._buffer

@property
def records(self) -> t.List[t.Tuple[str, t.Union[str, bytes], t.Dict]]:
def records(self) -> t.List[t.Tuple[str, t.Union[str, bytes], t.Union[t.Dict, None]]]:
return [(item.topic, item.payload, item.userdata) for item in self._buffer]

def publish(self, topic: str, payload: str, **kwargs) -> mqtt.MQTTMessageInfo:
Expand Down
3 changes: 1 addition & 2 deletions pytest_mqtt/mosquitto.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
.. _Mosquitto: https://github.com/eclipse/mosquitto
"""

import os

import docker
Expand All @@ -36,7 +37,6 @@


class Mosquitto(BaseImage):

name = "mosquitto"

def __init__(self, host: str = "localhost", port: int = 1883) -> None:
Expand Down Expand Up @@ -96,7 +96,6 @@ def mqtt_settings(pytestconfig) -> MqttSettings:

@pytest.fixture(scope="session")
def mosquitto(mqtt_settings: MqttSettings):

host, port = mqtt_settings.host, mqtt_settings.port

# Gracefully skip spinning up the Docker container if Mosquitto is already running.
Expand Down

0 comments on commit f22f4ab

Please sign in to comment.