Skip to content

Commit aae1c61

Browse files
authored
Merge pull request #555 from python-cmd2/transcript_fixes
Transcript fixes
2 parents 6ec2af3 + 5a77702 commit aae1c61

File tree

6 files changed

+28
-4
lines changed

6 files changed

+28
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Fixed bug where ``get_all_commands`` could return non-callable attributes
44
* Fixed bug where **alias** command was dropping quotes around arguments
55
* Fixed bug where running help on argparse commands didn't work if they didn't support -h
6+
* Fixed transcript testing bug where last command in transcript has no expected output
67
* Enhancements
78
* Added ``exit_code`` attribute of ``cmd2.Cmd`` class
89
* Enables applications to return a non-zero exit code when exiting from ``cmdloop``

cmd2/transcript.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ def _test_transcript(self, fname: str, transcript):
6767
break
6868
line_num += 1
6969
command = [line[len(self.cmdapp.visible_prompt):]]
70-
line = next(transcript)
70+
try:
71+
line = next(transcript)
72+
except StopIteration:
73+
line = ''
7174
# Read the entirety of a multi-line command
7275
while line.startswith(self.cmdapp.continuation_prompt):
7376
command.append(line[len(self.cmdapp.continuation_prompt):])

tests/test_transcript.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def do_mumble(self, opts, arg):
7979
output.append(random.choice(self.MUMBLE_LAST))
8080
self.poutput(' '.join(output))
8181

82+
def do_nothing(self, statement):
83+
"""Do nothing and output nothing"""
84+
pass
85+
8286

8387
def test_commands_at_invocation():
8488
testargs = ["prog", "say hello", "say Gracie", "quit"]
@@ -98,6 +102,8 @@ def test_commands_at_invocation():
98102
('from_cmdloop.txt', True),
99103
('multiline_no_regex.txt', False),
100104
('multiline_regex.txt', False),
105+
('no_output.txt', False),
106+
('no_output_last.txt', False),
101107
('regex_set.txt', False),
102108
('singleslash.txt', False),
103109
('slashes_escaped.txt', False),
@@ -125,7 +131,7 @@ def test_transcript(request, capsys, filename, feedback_to_output):
125131
# Check for the unittest "OK" condition for the 1 test which ran
126132
expected_start = ".\n----------------------------------------------------------------------\nRan 1 test in"
127133
expected_end = "s\n\nOK\n"
128-
out, err = capsys.readouterr()
134+
_, err = capsys.readouterr()
129135
assert err.startswith(expected_start)
130136
assert err.endswith(expected_end)
131137

tests/transcripts/from_cmdloop.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
Documented commands (type help <topic>):
77
========================================
8-
alias help load mumble py quit set shortcuts/ */
9-
edit history macro orate pyscript say shell speak/ */
8+
alias help load mumble orate pyscript say shell speak/ */
9+
edit history macro nothing py quit set shortcuts/ */
1010

1111
(Cmd) help say
1212
usage: speak [-h] [-p] [-s] [-r REPEAT]/ */

tests/transcripts/no_output.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ensure the transcript can play a command with no output from a command somewhere in the middle
2+
3+
(Cmd) say something
4+
something
5+
(Cmd) nothing
6+
(Cmd) say something else
7+
something else
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ensure the transcript can play a command with no output from the last command
2+
3+
(Cmd) say something
4+
something
5+
(Cmd) say something else
6+
something else
7+
(Cmd) nothing

0 commit comments

Comments
 (0)