From 96d176cc3d8198913693a42c7dd983cf69a165bd Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Mon, 18 Mar 2019 21:25:03 -0400 Subject: Added a unit test for "load -r" --- tests/test_transcript.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'tests/test_transcript.py') 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. -- cgit v1.2.1 From e0a307c03345674bd78ff991b16816f5301d2653 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Tue, 19 Mar 2019 00:17:58 -0400 Subject: Updated CHANGELOG Also: - Removed guard clauses which kmvanbrunt promises will be unecessary with his upcoming change - Moved transcript path validation inside _generate_transcript() --- tests/test_transcript.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_transcript.py') diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 709648fc..6c9b8a20 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -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') -- cgit v1.2.1 From 0cdc9119de361e76d665c9cab71085fe40677331 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Tue, 19 Mar 2019 19:39:03 -0400 Subject: Now consistently use -t flag for transcript generation for both history and load commands --- tests/test_transcript.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_transcript.py') diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 6c9b8a20..acdbe703 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -203,7 +203,7 @@ def test_load_record_transcript(base_app, request): 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)) + run_cmd(base_app, 'load {} -t {}'.format(filename, transcript_fname)) assert base_app.cmdqueue == [] assert base_app._script_dir == [] -- cgit v1.2.1