Skip to content

Commit

Permalink
topotato: remove consume_args hack
Browse files Browse the repository at this point in the history
This can just be in `__init__` and be much less hacky.  cf. next commit.

Signed-off-by: David Lamparter <[email protected]>
  • Loading branch information
eqvinox committed Sep 16, 2024
1 parent 4caff60 commit 18853ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 32 deletions.
30 changes: 14 additions & 16 deletions topotato/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -133,25 +133,23 @@ 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)
assert fn is not None
return fn.started_ts


class AssertKernelRoutes(TopotatoAssertion, TimedMixin):
class AssertKernelRoutes(TimedMixin, TopotatoAssertion):
"""
Common code for v4/v6 kernel routing table check.
"""
Expand Down Expand Up @@ -220,7 +218,7 @@ class AssertKernelRoutesV6(AssertKernelRoutes):
af = 6


class AssertVtysh(TopotatoAssertion, TimedMixin):
class AssertVtysh(TimedMixin, TopotatoAssertion):
_nodename = "vtysh"
_cmdprefix = ""

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 1 addition & 16 deletions topotato/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 18853ca

Please sign in to comment.