Skip to content

Commit 160bb74

Browse files
authored
Merge pull request #261 from python-cmd2/automated_transcripts
Fixed issue with automated transcript generation via "history -t"
2 parents ddfd3d9 + beadd89 commit 160bb74

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 0.8.0 (TBD, 2018)
1+
## 0.8.0 (February TBD, 2018)
22
* Bug Fixes
33
* Fixed unit tests on Python 3.7 due to changes in how re.escape() behaves in Python 3.7
44
* Fixed a bug where unknown commands were getting saved in the history
@@ -21,7 +21,7 @@
2121
* The **set** command now has an additional **-a/--all** option to also display read-only settings
2222
* The **history** command can now run, edit, and save prior commands, in addition to displaying prior commands.
2323
* The **history** command can now automatically generate a transcript file for regression testing
24-
* This feature works imperfectly at the moment, but it is still quite useful
24+
* This makes creating regression tests for your ``cmd2`` application trivial
2525
* Commands Removed
2626
* The **cmdenvironment** has been removed and its functionality incorporated into the **-a/--all** argument to **set**
2727
* The **show** command has been removed. Its functionality has always existing within **set** and continues to do so

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ Main Features
3636
- Windows, macOS, and Linux support
3737
- Trivial to provide built-in help for all commands
3838
- Built-in regression testing framework for your applications (transcript-based testing)
39+
- Transcripts for use with built-in regression can be automatically generated from `history -t`
3940

41+
Plan for dropping Python 2.7 support
42+
------------------------------------
43+
Support for Python 2.7 will be discontinued on Aug 31, 2018. After that date, new releases of `cmd2` will only support
44+
Python 3. Older releases of `cmd2` will of course continue to support Python 2.7.
45+
46+
Supporting Python 2 is an increasing burden on our limited resources. Switching to support only Python 3 will allow
47+
us to clean up the codebase, remove some cruft, and focus on developing new features.
4048

4149
Installation
4250
------------

cmd2.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,13 @@ def do_history(self, args):
19131913
# Set echo back to its original state
19141914
self.echo = saved_echo
19151915

1916+
# Post-process the file to escape un-escaped "/" regex escapes
1917+
with open(args.transcript, 'r') as fin:
1918+
data = fin.read()
1919+
post_processed_data = data.replace('/', '\/')
1920+
with open(args.transcript, 'w') as fout:
1921+
fout.write(post_processed_data)
1922+
19161923
plural = 's' if len(history) > 1 else ''
19171924
self.pfeedback('{} command{} and outputs saved to transcript file {!r}'.format(len(history), plural,
19181925
args.transcript))

docs/transcript.rst

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ from commands that produce dynamic or variable output.
1313
Creating a transcript
1414
=====================
1515

16+
Automatically
17+
-------------
18+
A transcript can automatically generated based upon commands previously executed in the *history*::
19+
20+
(Cmd) help
21+
...
22+
(Cmd) help history
23+
...
24+
(Cmd) history 1:2 -t transcript.txt
25+
2 commands and outputs saved to transcript file 'transcript.txt'
26+
27+
This is by far the easiest way to generate a transcript.
28+
29+
Manually
30+
--------
1631
Here's a transcript created from ``python examples/example.py``::
1732

1833
(Cmd) say -r 3 Goodnight, Gracie
@@ -38,9 +53,9 @@ lines of the transcript as comments::
3853
# Lines at the beginning of the transcript that do not
3954
; start with the prompt i.e. '(Cmd) ' are ignored.
4055
/* You can use them for comments. */
41-
56+
4257
All six of these lines before the first prompt are treated as comments.
43-
58+
4459
(Cmd) say -r 3 Goodnight, Gracie
4560
Goodnight, Gracie
4661
Goodnight, Gracie
@@ -105,21 +120,21 @@ the path instead of specifying it verbatim, or we can escape the slashes::
105120
trailing spaces which are impossible to see. Instead of leaving them
106121
invisible, you can add a regular expression to match them, so that you can
107122
see where they are when you look at the transcript::
108-
123+
109124
(Cmd) set prompt
110125
prompt: (Cmd)/ /
111-
126+
112127
Some terminal emulators strip trailing space when you copy text from them.
113128
This could make the actual data generated by your app different than the
114129
text you pasted into the transcript, and it might not be readily obvious why
115130
the transcript is not passing. Consider using :ref:`output_redirection` to
116131
the clipboard or to a file to ensure you accurately capture the output of
117132
your command.
118-
133+
119134
If you aren't using regular expressions, make sure the newlines at the end
120135
of your transcript exactly match the output of your commands. A common cause
121136
of a failing transcript is an extra or missing newline.
122-
137+
123138
If you are using regular expressions, be aware that depending on how you
124139
write your regex, the newlines after the regex may or may not matter.
125140
``\Z`` matches *after* the newline at the end of the string, whereas

0 commit comments

Comments
 (0)