summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2020-04-15 19:18:30 -0400
committerGitHub <noreply@github.com>2020-04-15 19:18:30 -0400
commit85bb29b7edfc6485556f398ddb192c16d1509856 (patch)
treebc4beaf99dcb0c49c9d836135ae2954ebd48dd15 /tests
parentc4fbd8fa618b5c48cc38ac5c262d3c1ec53ce9af (diff)
parentb29a2bde32b5f59c29df52809d306df06aadfa9e (diff)
downloadcmd2-git-85bb29b7edfc6485556f398ddb192c16d1509856.tar.gz
Merge pull request #919 from python-cmd2/exception_handling
Exception handling
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_cmd2.py34
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):