summaryrefslogtreecommitdiff
path: root/tests/test_transcript.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-03-18 21:25:03 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2019-03-18 21:25:03 -0400
commit96d176cc3d8198913693a42c7dd983cf69a165bd (patch)
treed80ac0d451933b20c5c2575275f298d273214780 /tests/test_transcript.py
parent3928910d6e14699515601ecee23e201d4b7309d1 (diff)
downloadcmd2-git-96d176cc3d8198913693a42c7dd983cf69a165bd.tar.gz
Added a unit test for "load -r"
Diffstat (limited to 'tests/test_transcript.py')
-rw-r--r--tests/test_transcript.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/tests/test_transcript.py b/tests/test_transcript.py
index f93642b8..df7a7cf9 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
@@ -190,6 +190,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 {} -r {}'.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.