From 18853caaf217c70d146af0eb3ee767f475dcb913 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 13 Sep 2024 15:02:22 +0200 Subject: [PATCH] topotato: remove `consume_args` hack This can just be in `__init__` and be much less hacky. cf. next commit. Signed-off-by: David Lamparter --- topotato/assertions.py | 30 ++++++++++++++---------------- topotato/base.py | 17 +---------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/topotato/assertions.py b/topotato/assertions.py index acbbb8b..5df06b2 100644 --- a/topotato/assertions.py +++ b/topotato/assertions.py @@ -122,8 +122,8 @@ class TimedMixin: Maximum time to wait on this assertions. """ - @classmethod - def consume_kwargs(cls, kwargs): + def __init__(self, **kwargs): + cls = self.__class__ if cls.default_delay is None: if "delay" in kwargs: raise TopotatoUnhandledArgs( @@ -133,17 +133,15 @@ def consume_kwargs(cls, kwargs): delay = kwargs.pop("delay", cls.default_delay) maxwait = kwargs.pop("maxwait", cls.default_maxwait) - timing = TimingParams(delay, maxwait) - - def finalize(self): - # pylint: disable=protected-access - self._timing = timing.anchor(self.relative_start) + super().__init__(**kwargs) - fn = self.getparent(TopotatoFunction) - if fn.include_startup: - self._timing.full_history = True + self._timing = TimingParams(delay, maxwait) + self._timing.anchor(self.relative_start) - return [finalize] + fn = cast(TopotatoItem, self).getparent(TopotatoFunction) + assert fn is not None + if fn.include_startup: + self._timing.full_history = True def relative_start(self): fn = cast(TopotatoItem, self).getparent(TopotatoFunction) @@ -151,7 +149,7 @@ def relative_start(self): return fn.started_ts -class AssertKernelRoutes(TopotatoAssertion, TimedMixin): +class AssertKernelRoutes(TimedMixin, TopotatoAssertion): """ Common code for v4/v6 kernel routing table check. """ @@ -220,7 +218,7 @@ class AssertKernelRoutesV6(AssertKernelRoutes): af = 6 -class AssertVtysh(TopotatoAssertion, TimedMixin): +class AssertVtysh(TimedMixin, TopotatoAssertion): _nodename = "vtysh" _cmdprefix = "" @@ -318,7 +316,7 @@ class ReconfigureFRR(AssertVtysh): _cmdprefix = "enable\nconfigure\n" -class AssertPacket(TopotatoAssertion, TimedMixin): +class AssertPacket(TimedMixin, TopotatoAssertion): # pylint does not understand that from_parent is our __init__ _link: str _pkt: Any @@ -392,7 +390,7 @@ def __call__(self): ) -class AssertLog(TopotatoAssertion, TimedMixin): +class AssertLog(TimedMixin, TopotatoAssertion): # pylint does not understand that from_parent is our __init__ _rtr: str _daemon: str @@ -439,7 +437,7 @@ def __call__(self): raise TopotatoLogFail(detail) -class Delay(TopotatoAssertion, TimedMixin): +class Delay(TimedMixin, TopotatoAssertion): # pylint: disable=arguments-differ,protected-access,too-many-arguments @classmethod def from_parent(cls, parent, name, **kwargs) -> "Delay": # type: ignore diff --git a/topotato/base.py b/topotato/base.py index 4cedd6c..58b5543 100644 --- a/topotato/base.py +++ b/topotato/base.py @@ -208,30 +208,15 @@ def from_parent( """ name = kw.pop("name") - finalize = [] - - for base in cls.__mro__: - consumer = base.__dict__.get("consume_kwargs") - if not consumer: - continue - # pylint: disable=unnecessary-dunder-call - consumer = consumer.__get__(None, cls) - finalize.extend(consumer(kw)) - - if args or kw: - raise TopotatoUnhandledArgs("leftover arguments: %r, %r" % (args, kw)) nodeid = None child_sep = getattr(parent, "nodeid_children_sep", None) if child_sep: nodeid = parent.nodeid + child_sep + name self: TopotatoItem = cast( - "TopotatoItem", super().from_parent(parent, name=name, nodeid=nodeid) + "TopotatoItem", super().from_parent(parent, name=name, nodeid=nodeid, **kw) ) - for fin in finalize: - fin(self) - tparent = self.getparent(TopotatoClass) assert tparent is not None