diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-04-11 14:42:37 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-04-11 14:42:37 -0400 |
commit | 5b4bec9d56b2907a168d0688b0a3cde64043d048 (patch) | |
tree | d2eb512710c724012a6533250d2173b6a8f0991f /tests | |
parent | f223e96cfb0be13881ebf304d0720f0633b7fe46 (diff) | |
download | cmd2-git-5b4bec9d56b2907a168d0688b0a3cde64043d048.tar.gz |
Simplfied _redirect_output() by raising exception instead of returning bool
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_cmd2.py | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index b86ddfa6..2afcf701 100755 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -482,20 +482,11 @@ def test_output_redirection(base_app): def test_output_redirection_to_nonexistent_directory(base_app): filename = '~/fakedir/this_does_not_exist.txt' - # Verify that writing to a file in a non-existent directory doesn't work - run_cmd(base_app, 'help > {}'.format(filename)) - with pytest.raises(FileNotFoundError): - with open(filename) as f: - content = f.read() - verify_help_text(base_app, content) + out, err = run_cmd(base_app, 'help > {}'.format(filename)) + assert 'Failed to redirect' in err[0] - # Verify that appending to a file also works - run_cmd(base_app, 'help history >> {}'.format(filename)) - with pytest.raises(FileNotFoundError): - with open(filename) as f: - appended_content = f.read() - verify_help_text(base_app, appended_content) - assert len(appended_content) > len(content) + out, err = run_cmd(base_app, 'help >> {}'.format(filename)) + assert 'Failed to redirect' in err[0] def test_output_redirection_to_too_long_filename(base_app): filename = '~/sdkfhksdjfhkjdshfkjsdhfkjsdhfkjdshfkjdshfkjshdfkhdsfkjhewfuihewiufhweiufhiweufhiuewhiuewhfiuwehfia' \ @@ -504,20 +495,11 @@ def test_output_redirection_to_too_long_filename(base_app): 'fheiufhieuwhfewiuhfeiufhiuewfhiuewheiwuhfiuewhfiuewhfeiuwfhewiufhiuewhiuewhfeiuwhfiuwehfuiwehfiuehie' \ 'whfieuwfhieufhiuewhfeiuwfhiuefhueiwhfw' - # Verify that writing to a file in a non-existent directory doesn't work - run_cmd(base_app, 'help > {}'.format(filename)) - with pytest.raises(OSError): - with open(filename) as f: - content = f.read() - verify_help_text(base_app, content) + out, err = run_cmd(base_app, 'help > {}'.format(filename)) + assert 'Failed to redirect' in err[0] - # Verify that appending to a file also works - run_cmd(base_app, 'help history >> {}'.format(filename)) - with pytest.raises(OSError): - with open(filename) as f: - appended_content = f.read() - verify_help_text(base_app, content) - assert len(appended_content) > len(content) + out, err = run_cmd(base_app, 'help >> {}'.format(filename)) + assert 'Failed to redirect' in err[0] def test_feedback_to_output_true(base_app): |