Great work! I think it'd be fine to just keep if you ask me, I could see this being used in the future. I'm also looking at it from the perspective of 'what if i would have to write this myself,' if it turns out that we need it again for something later. It's easier to remove later if it turns out we aren't using it, but it'd likely be more time-consuming to remove it now and implement it again later, considering that time has already been spent testing and building it.
On Thu, Aug 8, 2024 at 5:49 PM Jeremy Spewock <jspew...@iol.unh.edu> wrote: > > On Thu, Aug 8, 2024 at 4:36 PM <jspew...@iol.unh.edu> wrote: > > > > From: Jeremy Spewock <jspew...@iol.unh.edu> > > > > Multiple test suites from the old DTS framework rely on being able to > > consume and interpret the verbose output of testpmd. The new framework > > doesn't have an elegant way for handling the verbose output, but test > > suites are starting to be written that rely on it. This patch creates a > > TextParser class that can be used to extract the verbose information > > from any testpmd output and also adjusts the `stop` method of the shell > > to return all output that it collected. > > > > Signed-off-by: Jeremy Spewock <jspew...@iol.unh.edu> > > --- > > dts/framework/parser.py | 30 ++ > > dts/framework/remote_session/testpmd_shell.py | 405 +++++++++++++++++- > > dts/framework/utils.py | 1 + > > 3 files changed, 434 insertions(+), 2 deletions(-) > > > > diff --git a/dts/framework/parser.py b/dts/framework/parser.py > > index 741dfff821..0b39025a48 100644 > > --- a/dts/framework/parser.py > > +++ b/dts/framework/parser.py > > @@ -160,6 +160,36 @@ def _find(text: str) -> Any: > > > > return ParserFn(TextParser_fn=_find) > > > > + @staticmethod > > + def find_all( > > I just realized that I forgot to take this method out since it is no > longer used in this patch now that I removed the idea of a block of > output that contains a burst of packets. The method could still be > useful in the future, but it isn't used anywhere now, so I can remove > it in the next version if no one sees a use for it. I'm also open to > leaving it there for the "just in case" it is needed in the future. > What do you all think? > > > + pattern: str | re.Pattern[str], > > + flags: re.RegexFlag = re.RegexFlag(0), > > + ) -> ParserFn: > > + """Makes a parser function that finds all of the regular > > expression matches in the text. > > + > > + If there are no matches found in the text than None will be > > returned, otherwise a list > > + containing all matches will be returned. Patterns that contain > > multiple groups will pack > > + the matches for each group into a tuple. > > + > > + Args: > > + pattern: The regular expression pattern. > > + flags: The regular expression flags. Ignored if the given > > pattern is already compiled. > > + > > + Returns: > > + A :class:`ParserFn` that can be used as metadata for a > > dataclass field. > > + """ > > + if isinstance(pattern, str): > > + pattern = re.compile(pattern, flags) > > + > > + def _find_all(text: str) -> list[str] | None: > > + m = pattern.findall(text) > > + if len(m) == 0: > > + return None > > + > > + return m > > + > > + return ParserFn(TextParser_fn=_find_all) > > + > <snip> > > 2.45.2 > >