diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_history.py | 10 | ||||
-rw-r--r-- | tests/test_transcript.py | 27 |
2 files changed, 15 insertions, 22 deletions
diff --git a/tests/test_history.py b/tests/test_history.py index 41ae2a9e..d1285705 100755 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -616,7 +616,7 @@ def test_history_verbose_with_other_options(base_app): for opt in options_to_test: out, err = run_cmd(base_app, 'history -v ' + opt) assert len(out) == 4 - assert out[0] == '-v can not be used with any other options' + assert out[0] == '-v cannot be used with any other options' assert out[1].startswith('Usage:') @@ -635,7 +635,7 @@ def test_history_script_with_invalid_options(base_app): for opt in options_to_test: out, err = run_cmd(base_app, 'history -s ' + opt) assert len(out) == 4 - assert out[0] == '-s and -x can not be used with -c, -r, -e, -o, or -t' + assert out[0] == '-s and -x cannot be used with -c, -r, -e, -o, or -t' assert out[1].startswith('Usage:') @@ -653,7 +653,7 @@ def test_history_expanded_with_invalid_options(base_app): for opt in options_to_test: out, err = run_cmd(base_app, 'history -x ' + opt) assert len(out) == 4 - assert out[0] == '-s and -x can not be used with -c, -r, -e, -o, or -t' + assert out[0] == '-s and -x cannot be used with -c, -r, -e, -o, or -t' assert out[1].startswith('Usage:') @@ -761,7 +761,7 @@ def test_history_file_permission_error(mocker, capsys): cmd2.Cmd(persistent_history_file='/tmp/doesntmatter') out, err = capsys.readouterr() assert not out - assert 'Can not read' in err + assert 'Cannot read' in err def test_history_file_conversion_no_truncate_on_init(hist_file, capsys): @@ -843,4 +843,4 @@ def test_persist_history_permission_error(hist_file, mocker, capsys): app._persist_history() out, err = capsys.readouterr() assert not out - assert 'Can not write' in err + assert 'Cannot write' in err 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): |