diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-03-16 22:36:51 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-03-16 22:36:51 -0400 |
commit | a5632e06cba42a26bb7d628631071d5cf0236e6f (patch) | |
tree | 09eb09272c30fa90995af675ca2383788dc669e1 /cmd2.py | |
parent | 2d4b43a4901122d7918af4030c440a3c93892a4f (diff) | |
download | cmd2-git-a5632e06cba42a26bb7d628631071d5cf0236e6f.tar.gz |
Added example of using a regular expression in a transcript test.
Also added a unit test for this feature.
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -2001,6 +2001,12 @@ class Cmd2TestCase(unittest.TestCase): that will execute the commands in a transcript file and expect the results shown. See example.py""" CmdApp = None + 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 + anyWhitespace = re.compile(r'\s', re.DOTALL | re.MULTILINE) def fetchTranscripts(self): self.transcripts = {} @@ -2024,13 +2030,6 @@ class Cmd2TestCase(unittest.TestCase): 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 - anyWhitespace = re.compile(r'\s', re.DOTALL | re.MULTILINE) - def _test_transcript(self, fname, transcript): line_num = 0 finished = False |