diff options
author | Catherine Devlin <catherine.devlin@gmail.com> | 2010-11-08 08:49:32 -0500 |
---|---|---|
committer | Catherine Devlin <catherine.devlin@gmail.com> | 2010-11-08 08:49:32 -0500 |
commit | 1de83fe582ea574e66387b90d95b7ddd3db0c93f (patch) | |
tree | 7a54ebb272a6d51a9f13c8c97106bd5daaaa45e5 | |
parent | a2a5c3912b3959b8bd0198aab7c0f5eaf40c13ec (diff) | |
download | cmd2-hg-1de83fe582ea574e66387b90d95b7ddd3db0c93f.tar.gz |
broke down StopIteration catches
-rwxr-xr-x | cmd2.py | 92 |
1 files changed, 52 insertions, 40 deletions
@@ -1480,49 +1480,61 @@ class Cmd2TestCase(unittest.TestCase): anyWhitespace = re.compile(r'\s', re.DOTALL | re.MULTILINE) def _test_transcript(self, fname, transcript): lineNum = 0 - try: - line = transcript.next() - lineNum += 1 - while True: - # Scroll forward to where actual commands begin - while not line.startswith(self.cmdapp.prompt): + finished = False + line = transcript.next() + lineNum += 1 + tests_run = 0 + while not finished: + # Scroll forward to where actual commands begin + while not line.startswith(self.cmdapp.prompt): + try: line = transcript.next() - lineNum += 1 - command = [line[len(self.cmdapp.prompt):]] - line = transcript.next() - # Read the entirety of a multi-line command - while line.startswith(self.cmdapp.continuation_prompt): - command.append(line[len(self.cmdapp.continuation_prompt):]) + except StopIteration: + finished = True + break + lineNum += 1 + command = [line[len(self.cmdapp.prompt):]] + line = transcript.next() + # Read the entirety of a multi-line command + while line.startswith(self.cmdapp.continuation_prompt): + command.append(line[len(self.cmdapp.continuation_prompt):]) + try: line = transcript.next() - lineNum += 1 - command = ''.join(command) - # Send the command into the application and capture the resulting output - stop = self.cmdapp.onecmd_plus_hooks(command) - #TODO: should act on ``stop`` - result = self.outputTrap.read() - # Read the expected result from transcript - if line.startswith(self.cmdapp.prompt): - message = '\nFile %s, line %d\nCommand was:\n%s\nExpected: (nothing)\nGot:\n%s\n'%\ - (fname, lineNum, command, result) - self.assert_(not(result.strip()), message) - continue - expected = [] - while not line.startswith(self.cmdapp.prompt): - expected.append(line) + except StopIteration: + raise (StopIteration, + 'Transcript broke off while reading command beginning at line %d with\n%s' + % (command[0])) + lineNum += 1 + command = ''.join(command) + # Send the command into the application and capture the resulting output + stop = self.cmdapp.onecmd_plus_hooks(command) + #TODO: should act on ``stop`` + result = self.outputTrap.read() + # Read the expected result from transcript + if line.startswith(self.cmdapp.prompt): + message = '\nFile %s, line %d\nCommand was:\n%s\nExpected: (nothing)\nGot:\n%s\n'%\ + (fname, lineNum, command, result) + self.assert_(not(result.strip()), message) + continue + expected = [] + while not line.startswith(self.cmdapp.prompt): + expected.append(line) + try: line = transcript.next() - lineNum += 1 - expected = ''.join(expected) - # Compare actual result to expected - message = '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n'%\ - (fname, lineNum, command, expected, result) - expected = self.expectationParser.transformString(expected) - # checking whitespace is a pain - let's skip it - expected = self.anyWhitespace.sub('', expected) - result = self.anyWhitespace.sub('', result) - self.assert_(re.match(expected, result, re.MULTILINE | re.DOTALL), message) - except StopIteration: - message = 'Final portion of test not returned, beginning at line %d' % (lineNum) - self.assert_(len(expected) < 3, message) + except StopIteration: + finished = True + break + lineNum += 1 + expected = ''.join(expected) + # Compare actual result to expected + message = '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n'%\ + (fname, lineNum, command, expected, result) + expected = self.expectationParser.transformString(expected) + # checking whitespace is a pain - let's skip it + expected = self.anyWhitespace.sub('', expected) + result = self.anyWhitespace.sub('', result) + self.assert_(re.match(expected, result, re.MULTILINE | re.DOTALL), message) + def tearDown(self): if self.CmdApp: self.outputTrap.tearDown() |