Skip to content

Commit 96d176c

Browse files
committed
Added a unit test for "load -r"
1 parent 3928910 commit 96d176c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

tests/scripts/help.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
help -v

tests/test_transcript.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import pytest
1818

1919
import cmd2
20-
from .conftest import run_cmd
20+
from .conftest import run_cmd, BASE_HELP_VERBOSE
2121
from cmd2 import transcript
2222
from cmd2.utils import StdSim
2323

@@ -190,6 +190,35 @@ def test_history_transcript_bad_filename(request, capsys):
190190
transcript = f.read()
191191
assert transcript == expected
192192

193+
194+
def test_load_record_transcript(base_app, request):
195+
test_dir = os.path.dirname(request.module.__file__)
196+
filename = os.path.join(test_dir, 'scripts', 'help.txt')
197+
198+
assert base_app.cmdqueue == []
199+
assert base_app._script_dir == []
200+
assert base_app._current_script_dir is None
201+
202+
# make a tmp file to use as a transcript
203+
fd, transcript_fname = tempfile.mkstemp(prefix='', suffix='.trn')
204+
os.close(fd)
205+
206+
# Run the load command with the -r option to generate a transcript
207+
run_cmd(base_app, 'load {} -r {}'.format(filename, transcript_fname))
208+
209+
assert base_app.cmdqueue == []
210+
assert base_app._script_dir == []
211+
assert base_app._current_script_dir is None
212+
213+
# read in the transcript created by the history command
214+
with open(transcript_fname) as f:
215+
xscript = f.read()
216+
217+
expected = '(Cmd) help -v\n' + BASE_HELP_VERBOSE + '\n'
218+
219+
assert xscript == expected
220+
221+
193222
@pytest.mark.parametrize('expected, transformed', [
194223
# strings with zero or one slash or with escaped slashes means no regular
195224
# expression present, so the result should just be what re.escape returns.

0 commit comments

Comments
 (0)