Skip to content

Commit 5a77702

Browse files
committed
Fixed transcript testing bug where last command in transcript has no expected output
Also: - Added unit test for this specific case
1 parent bc49e71 commit 5a77702

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def test_commands_at_invocation():
103103
('multiline_no_regex.txt', False),
104104
('multiline_regex.txt', False),
105105
('no_output.txt', False),
106+
('no_output_last.txt', False),
106107
('regex_set.txt', False),
107108
('singleslash.txt', False),
108109
('slashes_escaped.txt', False),

tests/transcripts/no_output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ensure the transcript can play a command with no output
1+
# ensure the transcript can play a command with no output from a command somewhere in the middle
22

33
(Cmd) say something
44
something
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)