# HG changeset patch # User catherine@dellzilla # Date 1269556803 14400 # Node ID e4bc5174aad1ea57f9e616d02e4fe89caf8b3e82 # Parent c4a821f400506d0c9fd147b2ab21e1d057cc8a4b don't let falling-off-the-edge equal test success diff -r c4a821f40050 -r e4bc5174aad1 cmd2.py --- a/cmd2.py Tue Mar 16 12:37:35 2010 -0400 +++ b/cmd2.py Thu Mar 25 18:40:03 2010 -0400 @@ -1472,6 +1472,13 @@ expectationParser = regexPattern | notRegexPattern endStrippingRegex = re.compile(r'[ \t]*\n') def _test_transcript(self, fname, transcript): + def assert_matching(): + _expected = ''.join(expected) + _expected = self.expectationParser.transformString(_expected) + _expected = self.endStrippingRegex.sub('\s*', _expected) # was \s*\n + _message = '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n'%\ + (fname, lineNum, command, _expected, result) + self.assert_(re.match(_expected, result.strip(), re.MULTILINE | re.DOTALL), _message) lineNum = 0 try: line = transcript.next() @@ -1483,27 +1490,20 @@ while line.startswith(self.cmdapp.continuation_prompt): command.append(line[len(self.cmdapp.continuation_prompt):]) line = transcript.next() - command = ''.join(command) + command = ''.join(command) stop = self.cmdapp.onecmd_plus_hooks(command) #TODO: should act on ``stop`` result = self.outputTrap.read() + expected = [] 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) - line = transcript.next() - expected = ''.join(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) - expected = self.endStrippingRegex.sub('\s*\n', expected) - self.assert_(re.match(expected, result, re.MULTILINE | re.DOTALL), message) + assert_matching() + else: + while not line.startswith(self.cmdapp.prompt): + expected.append(line) + line = transcript.next() + assert_matching() except StopIteration: - pass + assert_matching() def tearDown(self): if self.CmdApp: self.outputTrap.tearDown()