From 71078cb089cbdc1e3fae43c1a9de935b4ccf2c4f Mon Sep 17 00:00:00 2001 From: Marcin Usielski Date: Wed, 7 Aug 2024 09:39:58 +0000 Subject: [PATCH] matched --- moler/device/textualdevice.py | 3 ++- moler/events/unix/wait4prompts.py | 1 + test/events/unix/test_event_wait4prompts.py | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/moler/device/textualdevice.py b/moler/device/textualdevice.py index 06d30ad6f..54376ba94 100644 --- a/moler/device/textualdevice.py +++ b/moler/device/textualdevice.py @@ -1031,7 +1031,8 @@ def _prompts_observer_callback(self, event): occurrence = event.get_last_occurrence() state = occurrence["state"] line = occurrence["line"] - msg = f"Callback for state {state} for line >>{line}<<" + matched = occurrence["matched"] + msg = f"Callback for state {state} for line >>{line}<<, matched: '{matched}'." if self.current_state != state: self._log(level=logging.INFO, msg=msg) self._set_state(state) diff --git a/moler/events/unix/wait4prompts.py b/moler/events/unix/wait4prompts.py index a86c2e123..642a95206 100644 --- a/moler/events/unix/wait4prompts.py +++ b/moler/events/unix/wait4prompts.py @@ -63,6 +63,7 @@ def _parse_prompts(self, line): current_ret = { "line": line, "prompt_regex": prompt_regex.pattern, + "matched": self._regex_helper.group(0), "state": self.compiled_prompts_regex[prompt_regex], "time": datetime.datetime.now(), } diff --git a/test/events/unix/test_event_wait4prompts.py b/test/events/unix/test_event_wait4prompts.py index 150c8bc8f..b1617643f 100644 --- a/test/events/unix/test_event_wait4prompts.py +++ b/test/events/unix/test_event_wait4prompts.py @@ -30,11 +30,13 @@ def _prompts_observer_callback(event): occurrence = event.get_last_occurrence() state = occurrence["state"] line = occurrence["line"] + matched = occurrence["matched"] nonlocal was_callback_called was_callback_called = True try: assert state == "UNIX_LOCAL" assert line == "moler_bash#" + assert matched == "moler_bash#" except AssertionError as err: nonlocal error error = err @@ -67,11 +69,13 @@ def _prompts_observer_callback(event): occurrence = event.get_last_occurrence() state = occurrence["state"] line = occurrence["line"] + matched = occurrence["matched"] nonlocal was_callback_called was_callback_called =True try: assert state == "UNIX_LOCAL" assert line == "moler_bash#" + assert matched == "moler_bash#" except AssertionError as err: nonlocal error error = err