diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-10 11:33:07 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-10 11:33:07 -0400 |
commit | 18f001c603135010582256984e92f6835898171e (patch) | |
tree | 8727216799119cbf842e962d7a567d79f9dbc4f5 /tests/test_transcript.py | |
parent | 6fa5c56a0d457fa69ac43b1d0b6f733a71a697da (diff) | |
download | cmd2-git-18f001c603135010582256984e92f6835898171e.tar.gz |
Added unit test for stopping during transcript generation
Diffstat (limited to 'tests/test_transcript.py')
-rw-r--r-- | tests/test_transcript.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 9d804a88..4af547b1 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -216,6 +216,29 @@ def test_load_record_transcript(base_app, request): assert xscript == expected +def test_generate_transcript_stop(capsys): + # Verify transcript generation stops when a command returns True for stop + app = CmdLineApp() + + # Make a tmp file to use as a transcript + fd, transcript_fname = tempfile.mkstemp(prefix='', suffix='.trn') + os.close(fd) + + # This should run all commands return False for stop + commands = ['help', 'alias'] + stop = app._generate_transcript(commands, transcript_fname) + _, err = capsys.readouterr() + assert not stop + assert err.startswith("2 commands") + + # Since quit returns True for stop, only the first 2 commands will run and stop should be True + commands = ['help', 'quit', 'alias'] + stop = app._generate_transcript(commands, transcript_fname) + _, err = capsys.readouterr() + assert stop + assert err.startswith("2 commands") + + @pytest.mark.parametrize('expected, transformed', [ # strings with zero or one slash or with escaped slashes means no regular # expression present, so the result should just be what re.escape returns. |