diff --git a/.flake8 b/.flake8 index 504766c8..3654ff4f 100644 --- a/.flake8 +++ b/.flake8 @@ -1,6 +1,6 @@ [flake8] statistics = True max-line-length = 80 -ignore = E501, B008, B011, W503, B905 select = C,E,F,W,B,B9 +ignore = E203, E501, E704, B008, B011, B905, W503 exclude = docs,.svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg diff --git a/cobald_tests/controller/test_stepwise.py b/cobald_tests/controller/test_stepwise.py index d525dc2a..4b5e3710 100644 --- a/cobald_tests/controller/test_stepwise.py +++ b/cobald_tests/controller/test_stepwise.py @@ -9,13 +9,13 @@ class TestStepwise: def test_add(self): @stepwise def control(pool, interval): - ... + pass assert isinstance(control, UnboundStepwise) @control.add(supply=20) def rule(pool, interval): - ... + pass assert isinstance(control, UnboundStepwise) assert isinstance(rule, FunctionType) @@ -23,7 +23,7 @@ def rule(pool, interval): def test_instantiate(self): @stepwise def control(pool, interval): - ... + pass assert isinstance(control(FullMockPool()), Stepwise) assert isinstance(control.s() >> FullMockPool(), Stepwise) @@ -32,7 +32,7 @@ def control(pool, interval): @control.add(supply=20) def rule(pool, interval): - ... + pass assert isinstance(control(FullMockPool()), Stepwise) assert isinstance(control.s() >> FullMockPool(), Stepwise) diff --git a/cobald_tests/decorator/test_logger.py b/cobald_tests/decorator/test_logger.py index 035a7639..d35f9f24 100644 --- a/cobald_tests/decorator/test_logger.py +++ b/cobald_tests/decorator/test_logger.py @@ -1,6 +1,7 @@ import threading import logging import io +import warnings import pytest @@ -56,10 +57,11 @@ def test_name(self): def test_verification(self): pool = FullMockPool() - # no warnings by default - with pytest.warns(None) as recorded_warnings: + # ensure no warnings by default + # see https://docs.pytest.org/en/8.0.x/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests # noqa + with warnings.catch_warnings(): + warnings.simplefilter("error") Logger(target=pool, name="test logger") - assert not recorded_warnings pool = FullMockPool() with pytest.warns(FutureWarning): diff --git a/cobald_tests/interfaces/test_partial.py b/cobald_tests/interfaces/test_partial.py index 0ef8a305..c43dea32 100644 --- a/cobald_tests/interfaces/test_partial.py +++ b/cobald_tests/interfaces/test_partial.py @@ -7,11 +7,11 @@ class MockController(Controller): def regulate(self, interval: float): - ... + pass class MockDecorator(PoolDecorator): - ... + pass class TestPartial(object): diff --git a/setup.py b/setup.py index 396c4c57..a520083f 100644 --- a/setup.py +++ b/setup.py @@ -57,7 +57,7 @@ python_requires=">=3.8", install_requires=[ "pyyaml", - "trio>=0.4.0", + "trio", "entrypoints", "toposort", ], @@ -68,6 +68,7 @@ "flake8", "flake8-bugbear", "black; implementation_name=='cpython'", + "pytest>=8.0", "pytest-cov", ] + TESTS_REQUIRE, diff --git a/src/cobald/__about__.py b/src/cobald/__about__.py index 9544ea41..040846c4 100644 --- a/src/cobald/__about__.py +++ b/src/cobald/__about__.py @@ -10,6 +10,7 @@ This is a **draft** for a feedback based balancing system for providing opportunistic resources. """ + __title__ = "cobald" __summary__ = "COBalD - the Opportunistic Balancing Daemon" __url__ = "https://github.com/MatterMiners/cobald" diff --git a/src/cobald/controller/stepwise.py b/src/cobald/controller/stepwise.py index ccc0a83a..4982ebe7 100644 --- a/src/cobald/controller/stepwise.py +++ b/src/cobald/controller/stepwise.py @@ -134,12 +134,12 @@ def __init__(self, base: ControlRule): self._thresholds: Set[float] = set() @overload # noqa: F811 - def add(self, rule: ControlRule, *, supply: float) -> ControlRule: - ... + def add(self, rule: ControlRule, *, supply: float) -> ControlRule: ... @overload # noqa: F811 - def add(self, rule: None, *, supply: float) -> Callable[[ControlRule], ControlRule]: - ... + def add( + self, rule: None, *, supply: float + ) -> Callable[[ControlRule], ControlRule]: ... def add(self, rule: ControlRule = None, *, supply: float): # noqa: F811 """ diff --git a/src/cobald/daemon/core/logger.py b/src/cobald/daemon/core/logger.py index c7100529..89b8c974 100644 --- a/src/cobald/daemon/core/logger.py +++ b/src/cobald/daemon/core/logger.py @@ -25,9 +25,11 @@ def initialise_logging(level: str, target: str, short_format: bool): handler = create_handler(target=target) logging.basicConfig( level=log_level, - format="%(asctime)-15s (%(process)d) %(message)s" - if not short_format - else "%(message)s", + format=( + "%(asctime)-15s (%(process)d) %(message)s" + if not short_format + else "%(message)s" + ), datefmt="%Y-%m-%d %H:%M:%S", handlers=[handler], ) diff --git a/src/cobald/daemon/core/main.py b/src/cobald/daemon/core/main.py index ba38355f..1e9fa5ad 100644 --- a/src/cobald/daemon/core/main.py +++ b/src/cobald/daemon/core/main.py @@ -1,6 +1,7 @@ """ Daemon core specific to cobald """ + import asyncio import sys import logging diff --git a/src/cobald/daemon/debug.py b/src/cobald/daemon/debug.py index 7eb0254f..558eba8f 100644 --- a/src/cobald/daemon/debug.py +++ b/src/cobald/daemon/debug.py @@ -20,9 +20,11 @@ def pretty_partial(obj: partial) -> str: return "partial(%s%s%s)" % ( pretty_ref(obj.func), "" if not obj.args else ", ".join(repr(arg) for arg in obj.args), - "" - if not obj.keywords - else ", ".join("%r = %r" % (k, v) for k, v in obj.keywords.items()), + ( + "" + if not obj.keywords + else ", ".join("%r = %r" % (k, v) for k, v in obj.keywords.items()) + ), ) diff --git a/src/cobald/daemon/plugins.py b/src/cobald/daemon/plugins.py index 653ee9e0..8adceacb 100644 --- a/src/cobald/daemon/plugins.py +++ b/src/cobald/daemon/plugins.py @@ -1,6 +1,7 @@ """ Tools and helpers to declare plugins """ + from typing import Iterable, FrozenSet, TypeVar, NamedTuple diff --git a/src/cobald/interfaces/__init__.py b/src/cobald/interfaces/__init__.py index 3b1818f9..09c4d942 100644 --- a/src/cobald/interfaces/__init__.py +++ b/src/cobald/interfaces/__init__.py @@ -23,6 +23,7 @@ } """ + from ._composite import CompositePool from ._controller import Controller from ._pool import Pool diff --git a/src/cobald/interfaces/_partial.py b/src/cobald/interfaces/_partial.py index 47c27349..4d83f225 100644 --- a/src/cobald/interfaces/_partial.py +++ b/src/cobald/interfaces/_partial.py @@ -39,6 +39,7 @@ class Partial(Generic[C_co]): creates a temporary :py:class:`~.PartialBind`. Only binding to a :py:class:`~.Pool` as the last element creates a concrete binding. """ + __slots__ = ("ctor", "args", "kwargs", "leaf") def __init__(self, ctor: Type[C_co], *args, __leaf__, **kwargs): @@ -74,12 +75,12 @@ def __construct__(self, *args, **kwargs): return self.ctor(*args, *self.args, **kwargs, **self.kwargs) @overload # noqa: F811 - def __rshift__(self, other: "Union[Owner, Pool, PartialBind[Pool]]") -> "C_co": - ... + def __rshift__(self, other: "Union[Owner, Pool, PartialBind[Pool]]") -> "C_co": ... @overload # noqa: F811 - def __rshift__(self, other: "Union[Partial, PartialBind]") -> "PartialBind[C_co]": - ... + def __rshift__( + self, other: "Union[Partial, PartialBind]" + ) -> "PartialBind[C_co]": ... def __rshift__(self, other): # noqa: F811 if isinstance(other, PartialBind): @@ -107,6 +108,7 @@ class PartialBind(Generic[C_co]): This helper is used to invert the operator precedence of ``>>``, allowing the last pair to be bound first. """ + __slots__ = ("parent", "targets") def __init__( @@ -118,12 +120,10 @@ def __init__( self.targets = targets @overload # noqa: F811 - def __rshift__(self, other: Partial[Owner]) -> "PartialBind[C_co]": - ... + def __rshift__(self, other: Partial[Owner]) -> "PartialBind[C_co]": ... @overload # noqa: F811 - def __rshift__(self, other: "Pool") -> "C_co": - ... + def __rshift__(self, other: "Pool") -> "C_co": ... def __rshift__(self, other: "Union[Pool, Partial[Owner]]"): # noqa: F811 if isinstance(other, _pool.Pool):