summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-03-16 22:36:51 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-03-16 22:36:51 -0400
commita5632e06cba42a26bb7d628631071d5cf0236e6f (patch)
tree09eb09272c30fa90995af675ca2383788dc669e1 /cmd2.py
parent2d4b43a4901122d7918af4030c440a3c93892a4f (diff)
downloadcmd2-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-xcmd2.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/cmd2.py b/cmd2.py
index 34bd8134..4dcd9ba7 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -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