@@ -8,13 +8,12 @@ part, your app can play back these transcripts as a unit test. Transcripts can
88contain regular expressions, which provide the flexibility to match responses
99from commands that produce dynamic or variable output.
1010
11+ .. highlight :: none
1112
1213Creating a transcript
1314=====================
1415
15- Here's a transcript created from ``python examples/example.py ``:
16-
17- .. code-block :: none
16+ Here's a transcript created from ``python examples/example.py ``::
1817
1918 (Cmd) say -r 3 Goodnight, Gracie
2019 Goodnight, Gracie
@@ -26,20 +25,15 @@ Here's a transcript created from ``python examples/example.py``:
2625 well maybe we could like go to er lunch right?
2726
2827This transcript has three commands: they are on the lines that begin with the
29- prompt. The first command looks like this:
30-
31- .. code-block :: none
28+ prompt. The first command looks like this::
3229
3330 (Cmd) say -r 3 Goodnight, Gracie
3431
35-
3632Following each command is the output generated by that command.
3733
3834The transcript ignores all lines in the file until it reaches the first line
3935that begins with the prompt. You can take advantage of this by using the first
40- lines of the transcript as comments.
41-
42- .. code-block :: none
36+ lines of the transcript as comments::
4337
4438 # Lines at the beginning of the transcript that do not
4539 ; start with the prompt i.e. '(Cmd) ' are ignored.
@@ -57,24 +51,22 @@ lines of the transcript as comments.
5751 maybe we could like go to er lunch right?
5852
5953In this example I've used several different commenting styles, and even bare
60- text. It doesn't matter what you put on those beginning lines. Everything before
61-
62- .. code-block :: none
54+ text. It doesn't matter what you put on those beginning lines. Everything before::
6355
6456 (Cmd) say -r 3 Goodnight, Gracie
6557
6658will be ignored.
6759
68- If we used this transcript as-is, it would likely fail. As you can see, the
69- ``mumble `` command doesn't always return the same thing. The ``mumble `` command
70- inserts random words into the input.
7160
61+ Regular Expressions
62+ ===================
7263
64+ If we used the above transcript as-is, it would likely fail. As you can see,
65+ the ``mumble `` command doesn't always return the same thing: it inserts random
66+ words into the input.
7367
7468Regular expressions can be included in the response portion of a transcript,
75- and are surrounded by slashes.
76-
77- .. code-block :: none
69+ and are surrounded by slashes::
7870
7971 (Cmd) mumble maybe we could go to lunch
8072 /.*\bmaybe\b.*\bcould\b.*\blunch\b.*/
@@ -94,33 +86,36 @@ so you may want to double check the `Python regular expression documentation
9486using ``\Z ``, it matches after the newline at the end of the string.
9587
9688If your output has slashes in it, you will need to escape those slashes so the
97- stuff between them is not interpred as a regular expression. In this transcript:
98-
99- .. code-block :: none
89+ stuff between them is not interpred as a regular expression. In this transcript::
10090
10191 (Cmd) say cd /usr/local/lib/python3.6/site-packages
10292 /usr/local/lib/python3.6/site-packages
10393
10494the output contains slashes. The text between the first slash and the second
105- slash, will be interpreted as a regular expression, and those two
106- slashes will not be included in the comparison. When replayed, this transcript
107- would therefore fail. To fix it, we could either write a regular expression to
108- match the path instead of specifying it verbatim, or we can escape the slashes:
109-
110- .. code-block :: none
95+ slash, will be interpreted as a regular expression, and those two slashes will
96+ not be included in the comparison. When replayed, this transcript would
97+ therefore fail. To fix it, we could either write a regular expression to match
98+ the path instead of specifying it verbatim, or we can escape the slashes::
11199
112100 (Cmd) say cd /usr/local/lib/python3.6/site-packages
113101 \/usr\/local\/lib\/python3.6\/site-packages
114102
115103.. warning ::
116104
117105 Be aware of trailing spaces and newlines. Your commands might output
118- trailing spaces which are impossible to see.
106+ trailing spaces which are impossible to see. Instead of leaving them
107+ invisible, you can add a regular expression to match them, so that you can
108+ see where they are when you look at the transcript::
109+
110+ (Cmd) set prompt
111+ prompt: (Cmd)/ /
119112
120113 Some terminal emulators strip trailing space when you copy text from them.
121114 This could make the actual data generated by your app different than the
122115 text you pasted into the transcript, and it might not be readily obvious why
123- the transcript is not passing.
116+ the transcript is not passing. Consider using :ref: `output_redirection ` to
117+ the clipboard or to a file to ensure you accurately capture the output of
118+ your command.
124119
125120 If you aren't using regular expressions, make sure the newlines at the end
126121 of your transcript exactly match the output of your commands. A common cause
@@ -134,9 +129,7 @@ Running a transcript
134129====================
135130
136131Once you have created a transcript, it's easy to have your application play it
137- back and check the output. From within the ``examples/ `` directory:
138-
139- .. code-block :: none
132+ back and check the output. From within the ``examples/ `` directory::
140133
141134 $ python example.py --test transcript_regex.txt
142135 .
0 commit comments