diff options
Diffstat (limited to 'cmd2/transcript.py')
-rw-r--r-- | cmd2/transcript.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/cmd2/transcript.py b/cmd2/transcript.py index a635c1d3..5a115496 100644 --- a/cmd2/transcript.py +++ b/cmd2/transcript.py @@ -10,7 +10,6 @@ This file contains the classess necessary to make that work. These classes are used in cmd2.py::run_transcript_tests() """ import re -import glob import unittest from typing import Tuple @@ -30,13 +29,10 @@ class Cmd2TestCase(unittest.TestCase): def fetchTranscripts(self): self.transcripts = {} - for fileset in self.cmdapp.testfiles: - for fname in glob.glob(fileset): - tfile = open(fname) - self.transcripts[fname] = iter(tfile.readlines()) - tfile.close() - if not len(self.transcripts): - raise Exception("No test files found - nothing to test.") + for fname in self.cmdapp.testfiles: + tfile = open(fname) + self.transcripts[fname] = iter(tfile.readlines()) + tfile.close() def setUp(self): if self.cmdapp: @@ -84,14 +80,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 +100,13 @@ class Cmd2TestCase(unittest.TestCase): finished = True break line_num += 1 - expected = ''.join(expected) + + if stop: + # This should only be hit if the command that set stop to True had 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) |