changeset 396:e60e2c15f026

ignore whitespace during comparisons
author Catherine Devlin <catherine.devlin@gmail.com>
date Thu, 16 Sep 2010 07:38:26 -0400
parents 9f9c69fbb78f
children 50acba85cf9e 3bef4253cf1b
files cmd2.py docs/freefeatures.rst
diffstat 2 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Tue Sep 07 07:25:49 2010 -0400
+++ b/cmd2.py	Thu Sep 16 07:38:26 2010 -0400
@@ -1469,7 +1469,7 @@
     notRegexPattern = pyparsing.Word(pyparsing.printables)
     notRegexPattern.setParseAction(lambda t: re.escape(t[0]))
     expectationParser = regexPattern | notRegexPattern
-    endStrippingRegex = re.compile(r'[ \t]*\n')
+    anyWhitespace = re.compile(r'\s', re.DOTALL | re.MULTILINE)
     def _test_transcript(self, fname, transcript):
         lineNum = 0
         try:
@@ -1499,7 +1499,9 @@
                 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)
+                # 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:
             pass
--- a/docs/freefeatures.rst	Tue Sep 07 07:25:49 2010 -0400
+++ b/docs/freefeatures.rst	Thu Sep 16 07:38:26 2010 -0400
@@ -181,6 +181,11 @@
 
   python app.py --test transcript.txt
   
-Any deviations between the output prescribed in ``transcript.txt`` and
+Any non-whitespace deviations between the output prescribed in ``transcript.txt`` and
 the actual output from a fresh run of the application will be reported
-as a unit test failure.
+as a unit test failure.  (Whitespace is ignored during the comparison.)
+
+Regular expressions can be embedded in the transcript inside paired ``/`` 
+slashes.  These regular expressions should not include any whitespace
+expressions.
+