Rework increment param in pexpect.expect_prompt

This switches the 'increment' param from "after" to "before." Instead
of expect_prompt saying if the next prompt will be incremented, each
call site says if it should have been incremented sinec the last prompt.
This commit is contained in:
ridiculousfish
2020-10-06 14:22:35 -07:00
parent d8af0d2eec
commit 9e1800cb96
2 changed files with 11 additions and 9 deletions

View File

@@ -145,7 +145,7 @@ class SpawnedProc(object):
self.start_time = None
self.spawn = pexpect.spawn(exe_path, env=env, encoding="utf-8", timeout=timeout)
self.spawn.delaybeforesend = None
self.prompt_counter = 1
self.prompt_counter = 0
def time_since_first_message(self):
""" Return a delta in seconds since the first message, or 0 if this is the first. """
@@ -203,7 +203,9 @@ class SpawnedProc(object):
def expect_prompt(self, increment=True, *args, **kwargs):
""" Convenience function which matches some text and then a prompt.
Match the given positional arguments as expect_re, and then look
for a prompt, bumping the prompt counter if increment is true.
for a prompt.
If increment is set, then this should be a new prompt and the prompt counter
should be bumped; otherwise this is not a new prompt.
Returns None on success, and exits on failure.
Example:
sp.sendline("echo hello world")
@@ -211,12 +213,12 @@ class SpawnedProc(object):
"""
if args:
self.expect_re(*args, **kwargs)
if increment:
self.prompt_counter += 1
self.expect_re(
get_prompt_re(self.prompt_counter),
pat_desc="prompt %d" % self.prompt_counter,
)
if increment:
self.prompt_counter += 1
def report_exception_and_exit(self, pat, unmatched, err):
""" Things have gone badly.