diff mbox series

Strip prompt by default in send_expect

Message ID 20210415140303.22620-1-dliu@iol.unh.edu (mailing list archive)
State Superseded
Headers show
Series Strip prompt by default in send_expect | expand

Commit Message

dliu April 15, 2021, 2:03 p.m. UTC
From: Owen Hilyard <ohilyard@iol.unh.edu>

During investigation of timeout exceptions during performance testing, the
community lab found that trailing whitespace in run commands was the cause
of some of the timeouts. This patch makes the Crb version of send_expect
strip whitespace from the expected string by default. It is possible to
disable this behavior should it be needed, but we expect that the majority
of use-cases are matching non-whitespace characters.

Signed-off-by: Owen Hilyard <ohilyard@iol.unh.edu>
 framework/crb.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff mbox series


diff --git a/framework/crb.py b/framework/crb.py
index e7c1cc1c..3964e213 100644
--- a/framework/crb.py
+++ b/framework/crb.py
@@ -79,12 +79,19 @@  class Crb(object):
             self.alt_session = None
     def send_expect(self, cmds, expected, timeout=TIMEOUT,
-                    alt_session=False, verify=False):
+                    alt_session=False, verify=False, trim_whitespace=True):
         Send commands to crb and return string before expected string. If
         there's no expected string found before timeout, TimeoutException will
         be raised.
+        By default, it will trim the whitespace from the expected string. This
+        behavior can be turned off via the trim_whitespace argument.
+        if trim_whitespace:
+            expected = expected.strip()
         # sometimes there will be no alt_session like VM dut
         if alt_session and self.alt_session:
             return self.alt_session.session.send_expect(cmds, expected,