diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-03-31 14:53:50 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-03-31 15:34:37 -0400 |
commit | 06f05261945d706b668c8021a7ae6f8dcd15b9ea (patch) | |
tree | 26839ea0e5e4527a795336e6bdbec3a3fa4730b7 /tests/test_transcript.py | |
parent | 5165edec890575682f345fc42f5a53e10ed575b9 (diff) | |
download | cmd2-git-error_cleanup.tar.gz |
Replaced some pexcept() calls with perror().error_cleanup
Converted some strings to f-strings.
Fixed some grammar in error messages and docs.
Increased code coverage.
Diffstat (limited to 'tests/test_transcript.py')
-rw-r--r-- | tests/test_transcript.py | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/tests/test_transcript.py b/tests/test_transcript.py index ccb28740..22e04239 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -184,31 +184,24 @@ this is a \/multiline\/ command assert xscript == expected -def test_history_transcript_bad_filename(): +def test_history_transcript_bad_path(mocker): app = CmdLineApp() app.stdout = StdSim(app.stdout) run_cmd(app, 'orate this is\na /multiline/\ncommand;\n') run_cmd(app, 'speak /tmp/file.txt is not a regex') - expected = r"""(Cmd) orate this is -> a /multiline/ -> command; -this is a \/multiline\/ command -(Cmd) speak /tmp/file.txt is not a regex -\/tmp\/file.txt is not a regex -""" - - # make a tmp file + # Bad directory history_fname = '~/fakedir/this_does_not_exist.txt' + out, err = run_cmd(app, 'history -t "{}"'.format(history_fname)) + assert "is not a directory" in err[0] - # tell the history command to create a transcript - run_cmd(app, 'history -t "{}"'.format(history_fname)) + # Cause os.open to fail and make sure error gets printed + mock_remove = mocker.patch('builtins.open') + mock_remove.side_effect = OSError - # read in the transcript created by the history command - with pytest.raises(FileNotFoundError): - with open(history_fname) as f: - transcript = f.read() - assert transcript == expected + history_fname = 'outfile.txt' + out, err = run_cmd(app, 'history -t "{}"'.format(history_fname)) + assert "Error saving transcript file" in err[0] def test_run_script_record_transcript(base_app, request): |