|
1 | 1 | # |
2 | 2 | # -*- coding: utf-8 -*- |
| 3 | +"""Machinery for running and validating transcripts. |
| 4 | +
|
| 5 | +If the user wants to run a transcript (see docs/transcript.rst), |
| 6 | +we need a mechanism to run each command in the transcript as |
| 7 | +a unit test, comparing the expected output to the actual output. |
| 8 | +
|
| 9 | +This file contains the classess necessary to make that work. These |
| 10 | +classes are used in cmd2.py::run_transcript_tests() |
| 11 | +""" |
3 | 12 | import re |
4 | 13 | import glob |
5 | 14 | import unittest |
6 | 15 |
|
7 | 16 | from . import utils |
8 | 17 |
|
9 | 18 | class Cmd2TestCase(unittest.TestCase): |
10 | | - """Subclass this, setting CmdApp, to make a unittest.TestCase class |
11 | | - that will execute the commands in a transcript file and expect the results shown. |
12 | | - See example.py""" |
| 19 | + """A unittest class used for transcript testing. |
| 20 | +
|
| 21 | + Subclass this, setting CmdApp, to make a unittest.TestCase class |
| 22 | + that will execute the commands in a transcript file and expect the |
| 23 | + results shown. |
| 24 | +
|
| 25 | + See example.py |
| 26 | + """ |
13 | 27 | cmdapp = None |
14 | 28 |
|
15 | 29 | def fetchTranscripts(self): |
@@ -90,7 +104,7 @@ def _test_transcript(self, fname, transcript): |
90 | 104 | self.assertTrue(re.match(expected, result, re.MULTILINE | re.DOTALL), message) |
91 | 105 |
|
92 | 106 | def _transform_transcript_expected(self, s): |
93 | | - """parse the string with slashed regexes into a valid regex |
| 107 | + """Parse the string with slashed regexes into a valid regex. |
94 | 108 |
|
95 | 109 | Given a string like: |
96 | 110 |
|
@@ -138,8 +152,7 @@ def _transform_transcript_expected(self, s): |
138 | 152 |
|
139 | 153 | @staticmethod |
140 | 154 | def _escaped_find(regex, s, start, in_regex): |
141 | | - """ |
142 | | - Find the next slash in {s} after {start} that is not preceded by a backslash. |
| 155 | + """Find the next slash in {s} after {start} that is not preceded by a backslash. |
143 | 156 |
|
144 | 157 | If we find an escaped slash, add everything up to and including it to regex, |
145 | 158 | updating {start}. {start} therefore serves two purposes, tells us where to start |
@@ -191,7 +204,9 @@ def tearDown(self): |
191 | 204 | self.cmdapp.stdout = self._orig_stdout |
192 | 205 |
|
193 | 206 | class OutputTrap(object): |
194 | | - """Instantiate an OutputTrap to divert/capture ALL stdout output. For use in transcript testing.""" |
| 207 | + """Instantiate an OutputTrap to divert/capture ALL stdout output. |
| 208 | + For use in transcript testing. |
| 209 | + """ |
195 | 210 |
|
196 | 211 | def __init__(self): |
197 | 212 | self.contents = '' |
|
0 commit comments