summaryrefslogtreecommitdiff
path: root/cmd2/transcript.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-06-06 22:25:48 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2019-06-06 22:25:48 -0400
commitabeb8e7cabec6b18c269debb74659f91df4f6058 (patch)
tree66f7f44b6ad5606fd320ffbc4417f4b75bb29385 /cmd2/transcript.py
parent5157a6ee2c13d553854f2a78362e957f3d018870 (diff)
downloadcmd2-git-abeb8e7cabec6b18c269debb74659f91df4f6058.tar.gz
Transcript testing now properly handles commands which signal the application to quit
Implemented an antediluvian TODO
Diffstat (limited to 'cmd2/transcript.py')
-rw-r--r--cmd2/transcript.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/cmd2/transcript.py b/cmd2/transcript.py
index a635c1d3..b5cb5397 100644
--- a/cmd2/transcript.py
+++ b/cmd2/transcript.py
@@ -84,14 +84,16 @@ class Cmd2TestCase(unittest.TestCase):
line_num += 1
command = ''.join(command)
# Send the command into the application and capture the resulting output
- # TODO: Should we get the return value and act if stop == True?
- self.cmdapp.onecmd_plus_hooks(command)
+ stop = self.cmdapp.onecmd_plus_hooks(command)
result = self.cmdapp.stdout.read()
+ stop_msg = 'Command indicated application should quit, but more commands in transcript'
# Read the expected result from transcript
if utils.strip_ansi(line).startswith(self.cmdapp.visible_prompt):
message = '\nFile {}, line {}\nCommand was:\n{}\nExpected: (nothing)\nGot:\n{}\n'.format(
fname, line_num, command, result)
self.assertTrue(not (result.strip()), message)
+ # If the command signaled the application to quit there should be no more commands
+ self.assertFalse(stop, stop_msg)
continue
expected = []
while not utils.strip_ansi(line).startswith(self.cmdapp.visible_prompt):
@@ -102,9 +104,13 @@ class Cmd2TestCase(unittest.TestCase):
finished = True
break
line_num += 1
- expected = ''.join(expected)
+
+ if stop:
+ # This should only be hit if cmd2.Cmd.do_quit is overridden to have output text
+ self.assertTrue(finished, stop_msg)
# transform the expected text into a valid regular expression
+ expected = ''.join(expected)
expected = self._transform_transcript_expected(expected)
message = '\nFile {}, line {}\nCommand was:\n{}\nExpected:\n{}\nGot:\n{}\n'.format(
fname, line_num, command, expected, result)