From 1d73a71cc353d4378edd36be07c71f62a7a027cc Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 17 Sep 2024 12:55:08 +0200 Subject: [PATCH] topotato: add vtysh output compare filters Allow the test to do some text mangling beyond what the template supports. Signed-off-by: David Lamparter --- topotato/assertions.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/topotato/assertions.py b/topotato/assertions.py index 6d5eda4..65a5f5e 100644 --- a/topotato/assertions.py +++ b/topotato/assertions.py @@ -19,6 +19,7 @@ from typing import ( cast, Any, + Callable, ClassVar, List, Optional, @@ -235,8 +236,12 @@ class AssertVtysh(TimedMixin, TopotatoAssertion): _daemon: str _command: str _compare: Optional[str] + _filters: List[Callable[[str], str]] default_delay = 0.1 + default_filters = [ + lambda t: deindent(t, trim=True), + ] posargs = ["rtr", "daemon", "command", "compare"] @@ -249,6 +254,7 @@ def __init__( daemon, command, compare=None, + filters=None, **kwargs, ): command_cleaned = command @@ -270,6 +276,7 @@ def __init__( self._daemon = daemon self._command = self._cmdprefix + command self._compare = compare + self._filters = filters or self.default_filters def __call__(self): router = cast("FRRRouterNS", self.instance.routers[self._rtr.name]) @@ -289,7 +296,8 @@ def __call__(self): if isinstance(self._compare, type(None)): pass elif isinstance(self._compare, str): - text = deindent(text, trim=True) + for filterfn in self._filters: + text = filterfn(text) result = text_rich_cmp( router._configs, text,