summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatherine Devlin <catherine.devlin@gmail.com>2009-04-03 12:47:13 -0400
committerCatherine Devlin <catherine.devlin@gmail.com>2009-04-03 12:47:13 -0400
commit8ff906d6eb94661a633b25a1bb83afcebedbb2d0 (patch)
tree6107744a293a1e58359b0410d6eda6c2ae3c7a15
parentf9485262a26971bb2d0f69174c5f143e11b872b7 (diff)
downloadcmd2-hg-8ff906d6eb94661a633b25a1bb83afcebedbb2d0.tar.gz
line end-stripping working in transcript testing
-rwxr-xr-xcmd2.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/cmd2.py b/cmd2.py
index 146080b..e633fd2 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1107,7 +1107,7 @@ class OutputTrap(Borg):
def tearDown(self):
sys.stdout = self.old_stdout
-
+
class Cmd2TestCase(unittest.TestCase):
'''Subclass this, setting CmdApp, to make a unittest.TestCase class
that will execute the commands in a transcript file and expect the results shown.
@@ -1141,6 +1141,12 @@ class Cmd2TestCase(unittest.TestCase):
its = sorted(self.transcripts.items())
for (fname, transcript) in its:
self._test_transcript(fname, transcript)
+ regexPattern = pyparsing.QuotedString(quoteChar=r'/', escChar='\\', multiline=True, unquoteResults=True)
+ regexPattern.ignore(pyparsing.cStyleComment)
+ notRegexPattern = pyparsing.Word(pyparsing.printables)
+ notRegexPattern.setParseAction(lambda t: re.escape(t[0]))
+ expectationParser = regexPattern | notRegexPattern
+ endStrippingRegex = re.compile(r'[ \t]*\n')
def _test_transcript(self, fname, transcript):
lineNum = 0
try:
@@ -1167,12 +1173,10 @@ class Cmd2TestCase(unittest.TestCase):
line = transcript.next()
expected = ''.join(expected).strip()
message = '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n'%\
- (fname, lineNum, command, expected, result)
- if False and ((expected[0] == '/' == expected[-1]) and not expected.startswith('/*')):
- self.assert_(re.match(expected[1:-1], result, re.MULTILINE | re.DOTALL),
- message)
- else:
- self.assertEqualEnough(expected, result, message)
+ (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)
# this needs to account for a line-by-line strip()ping
except StopIteration:
pass