summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--cmd2/transcript.py5
-rw-r--r--tests/test_transcript.py8
-rw-r--r--tests/transcripts/from_cmdloop.txt4
-rw-r--r--tests/transcripts/no_output.txt7
-rw-r--r--tests/transcripts/no_output_last.txt7
6 files changed, 28 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0e3d704d..e09d25b2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
* Fixed bug where ``get_all_commands`` could return non-callable attributes
* Fixed bug where **alias** command was dropping quotes around arguments
* Fixed bug where running help on argparse commands didn't work if they didn't support -h
+ * Fixed transcript testing bug where last command in transcript has no expected output
* Enhancements
* Added ``exit_code`` attribute of ``cmd2.Cmd`` class
* Enables applications to return a non-zero exit code when exiting from ``cmdloop``
diff --git a/cmd2/transcript.py b/cmd2/transcript.py
index 2d94f4e4..baaa6caf 100644
--- a/cmd2/transcript.py
+++ b/cmd2/transcript.py
@@ -67,7 +67,10 @@ class Cmd2TestCase(unittest.TestCase):
break
line_num += 1
command = [line[len(self.cmdapp.visible_prompt):]]
- line = next(transcript)
+ try:
+ line = next(transcript)
+ except StopIteration:
+ line = ''
# Read the entirety of a multi-line command
while line.startswith(self.cmdapp.continuation_prompt):
command.append(line[len(self.cmdapp.continuation_prompt):])
diff --git a/tests/test_transcript.py b/tests/test_transcript.py
index f854241b..58ae16b4 100644
--- a/tests/test_transcript.py
+++ b/tests/test_transcript.py
@@ -79,6 +79,10 @@ class CmdLineApp(cmd2.Cmd):
output.append(random.choice(self.MUMBLE_LAST))
self.poutput(' '.join(output))
+ def do_nothing(self, statement):
+ """Do nothing and output nothing"""
+ pass
+
def test_commands_at_invocation():
testargs = ["prog", "say hello", "say Gracie", "quit"]
@@ -98,6 +102,8 @@ def test_commands_at_invocation():
('from_cmdloop.txt', True),
('multiline_no_regex.txt', False),
('multiline_regex.txt', False),
+ ('no_output.txt', False),
+ ('no_output_last.txt', False),
('regex_set.txt', False),
('singleslash.txt', False),
('slashes_escaped.txt', False),
@@ -125,7 +131,7 @@ def test_transcript(request, capsys, filename, feedback_to_output):
# Check for the unittest "OK" condition for the 1 test which ran
expected_start = ".\n----------------------------------------------------------------------\nRan 1 test in"
expected_end = "s\n\nOK\n"
- out, err = capsys.readouterr()
+ _, err = capsys.readouterr()
assert err.startswith(expected_start)
assert err.endswith(expected_end)
diff --git a/tests/transcripts/from_cmdloop.txt b/tests/transcripts/from_cmdloop.txt
index 56bbdc0c..8c0dd007 100644
--- a/tests/transcripts/from_cmdloop.txt
+++ b/tests/transcripts/from_cmdloop.txt
@@ -5,8 +5,8 @@
Documented commands (type help <topic>):
========================================
-alias help load mumble py quit set shortcuts/ */
-edit history macro orate pyscript say shell speak/ */
+alias help load mumble orate pyscript say shell speak/ */
+edit history macro nothing py quit set shortcuts/ */
(Cmd) help say
usage: speak [-h] [-p] [-s] [-r REPEAT]/ */
diff --git a/tests/transcripts/no_output.txt b/tests/transcripts/no_output.txt
new file mode 100644
index 00000000..6b84e8e7
--- /dev/null
+++ b/tests/transcripts/no_output.txt
@@ -0,0 +1,7 @@
+# ensure the transcript can play a command with no output from a command somewhere in the middle
+
+(Cmd) say something
+something
+(Cmd) nothing
+(Cmd) say something else
+something else
diff --git a/tests/transcripts/no_output_last.txt b/tests/transcripts/no_output_last.txt
new file mode 100644
index 00000000..c75d7e7f
--- /dev/null
+++ b/tests/transcripts/no_output_last.txt
@@ -0,0 +1,7 @@
+# ensure the transcript can play a command with no output from the last command
+
+(Cmd) say something
+something
+(Cmd) say something else
+something else
+(Cmd) nothing