Mercurial > python-cmd2
diff cmd2.py @ 261:57070e181cf7
line end-stripping working in transcript testing
author | Catherine Devlin <catherine.devlin@gmail.com> |
---|---|
date | Fri, 03 Apr 2009 12:47:13 -0400 |
parents | 2b69c4d72cd8 |
children | e81378f82c7c |
line wrap: on
line diff
--- a/cmd2.py Fri Apr 03 08:01:22 2009 -0400 +++ b/cmd2.py Fri Apr 03 12:47:13 2009 -0400 @@ -1107,7 +1107,7 @@ 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 @@ 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 @@ 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