diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-06-07 16:51:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-07 16:51:16 -0700 |
commit | d0e71c85190b81bb269cc18bf9380a142e18d707 (patch) | |
tree | 7b1a8d83d35417cf886cd6586b78fd727b4b8859 /tests/test_transcript.py | |
parent | 794414745f7c28c4c96300117ce9a57c38d4d5b5 (diff) | |
parent | c09e99341d5ba8aa0775cd312b359da084013a29 (diff) | |
download | cmd2-git-d0e71c85190b81bb269cc18bf9380a142e18d707.tar.gz |
Merge pull request #432 from python-cmd2/file_crashes
Fixed a couple potential crashes on opening files
Diffstat (limited to 'tests/test_transcript.py')
-rw-r--r-- | tests/test_transcript.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 302d80c8..3caf6a37 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -154,6 +154,32 @@ this is a \/multiline\/ command assert transcript == expected +def test_history_transcript_bad_filename(request, capsys): + app = CmdLineApp() + app.stdout = 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 + history_fname = '~/fakedir/this_does_not_exist.txt' + + # tell the history command to create a transcript + run_cmd(app, 'history -t "{}"'.format(history_fname)) + + # 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 + @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. |