diff options
author | Catherine Devlin <catherine.devlin@gmail.com> | 2009-04-03 12:47:13 -0400 |
---|---|---|
committer | Catherine Devlin <catherine.devlin@gmail.com> | 2009-04-03 12:47:13 -0400 |
commit | 8ff906d6eb94661a633b25a1bb83afcebedbb2d0 (patch) | |
tree | 6107744a293a1e58359b0410d6eda6c2ae3c7a15 | |
parent | f9485262a26971bb2d0f69174c5f143e11b872b7 (diff) | |
download | cmd2-hg-8ff906d6eb94661a633b25a1bb83afcebedbb2d0.tar.gz |
line end-stripping working in transcript testing
-rwxr-xr-x | cmd2.py | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -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 |