From 18f001c603135010582256984e92f6835898171e Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Mon, 10 Jun 2019 11:33:07 -0400 Subject: Added unit test for stopping during transcript generation --- tests/test_transcript.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/test_transcript.py') 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. -- cgit v1.2.1