diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-03-19 20:27:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-19 20:27:12 -0400 |
commit | 9f5906a5cc1128652f1b43545ae4c948e9a0fe2b (patch) | |
tree | 8e5e706742ae361443fc8a02d1037d8a9943c7ee /tests/test_transcript.py | |
parent | e89bd4f5e70300251314117d3664ad92c9123ade (diff) | |
parent | 74d2d60fa8685df82d3348dd56b6f8413deac6c2 (diff) | |
download | cmd2-git-9f5906a5cc1128652f1b43545ae4c948e9a0fe2b.tar.gz |
Merge pull request #652 from python-cmd2/load_generate_transcript
Added load -t flag for recording a transcript based on a script file
Diffstat (limited to 'tests/test_transcript.py')
-rw-r--r-- | tests/test_transcript.py | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 4a03ebe0..acdbe703 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -17,7 +17,7 @@ from unittest import mock import pytest import cmd2 -from .conftest import run_cmd +from .conftest import run_cmd, BASE_HELP_VERBOSE from cmd2 import transcript from cmd2.utils import StdSim @@ -136,7 +136,7 @@ def test_transcript(request, capsys, filename, feedback_to_output): assert err.startswith(expected_start) assert err.endswith(expected_end) -def test_history_transcript(request, capsys): +def test_history_transcript(): app = CmdLineApp() app.stdout = StdSim(app.stdout) run_cmd(app, 'orate this is\na /multiline/\ncommand;\n') @@ -163,7 +163,7 @@ this is a \/multiline\/ command assert xscript == expected -def test_history_transcript_bad_filename(request, capsys): +def test_history_transcript_bad_filename(): app = CmdLineApp() app.stdout = StdSim(app.stdout) run_cmd(app, 'orate this is\na /multiline/\ncommand;\n') @@ -189,6 +189,35 @@ this is a \/multiline\/ command transcript = f.read() assert transcript == expected + +def test_load_record_transcript(base_app, request): + test_dir = os.path.dirname(request.module.__file__) + filename = os.path.join(test_dir, 'scripts', 'help.txt') + + assert base_app.cmdqueue == [] + assert base_app._script_dir == [] + assert base_app._current_script_dir is None + + # make a tmp file to use as a transcript + fd, transcript_fname = tempfile.mkstemp(prefix='', suffix='.trn') + os.close(fd) + + # Run the load command with the -r option to generate a transcript + run_cmd(base_app, 'load {} -t {}'.format(filename, transcript_fname)) + + assert base_app.cmdqueue == [] + assert base_app._script_dir == [] + assert base_app._current_script_dir is None + + # read in the transcript created by the history command + with open(transcript_fname) as f: + xscript = f.read() + + expected = '(Cmd) help -v\n' + BASE_HELP_VERBOSE + '\n' + + assert xscript == expected + + @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. |