changeset 404:e4bc5174aad1

don't let falling-off-the-edge equal test success
author catherine@dellzilla
date Thu, 25 Mar 2010 18:40:03 -0400
parents c4a821f40050
children
files cmd2.py
diffstat 1 files changed, 16 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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()