|
17 | 17 | import pytest |
18 | 18 |
|
19 | 19 | import cmd2 |
20 | | -from .conftest import run_cmd |
| 20 | +from .conftest import run_cmd, BASE_HELP_VERBOSE |
21 | 21 | from cmd2 import transcript |
22 | 22 | from cmd2.utils import StdSim |
23 | 23 |
|
@@ -190,6 +190,35 @@ def test_history_transcript_bad_filename(request, capsys): |
190 | 190 | transcript = f.read() |
191 | 191 | assert transcript == expected |
192 | 192 |
|
| 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 | + |
193 | 222 | @pytest.mark.parametrize('expected, transformed', [ |
194 | 223 | # strings with zero or one slash or with escaped slashes means no regular |
195 | 224 | # expression present, so the result should just be what re.escape returns. |
|
0 commit comments