diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-20 17:58:54 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-20 17:58:54 -0400 |
commit | 7e850f828a899d5fcc5deb468857eaf9f3f2bbc5 (patch) | |
tree | d6231be46229b574bdbbf9a119dc46947f25073e /tests | |
parent | 7d95fa11dce408535bd67c93c2066d190ac6293a (diff) | |
download | cmd2-git-7e850f828a899d5fcc5deb468857eaf9f3f2bbc5.tar.gz |
Printing an error instead of raising and exception if setting a variable that does not exist
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cmd2.py | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index e94f1c06..6d2daa89 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -163,8 +163,7 @@ def test_set_not_supported(base_app, capsys): run_cmd(base_app, 'set qqq True') out, err = capsys.readouterr() expected = normalize(""" -EXCEPTION of type 'LookupError' occurred with message: 'Parameter 'qqq' not supported (type 'set' for list of parameters).' -To enable full traceback, run the following command: 'set debug true' +Parameter 'qqq' not supported (type 'set' for list of parameters). """) assert normalize(str(err)) == expected @@ -620,26 +619,6 @@ now: True assert err.startswith('Elapsed: 0:00:00.0') -def test_base_debug(base_app, capsys): - # Try to set a non-existent parameter with debug set to False by default - run_cmd(base_app, 'set does_not_exist 5') - out, err = capsys.readouterr() - assert err.startswith('EXCEPTION') - - # Set debug true - out = run_cmd(base_app, 'set debug True') - expected = normalize(""" -debug - was: False -now: True -""") - assert out == expected - - # Verify that we now see the exception traceback - run_cmd(base_app, 'set does_not_exist 5') - out, err = capsys.readouterr() - assert str(err).startswith('Traceback (most recent call last):') - - def _expected_no_editor_error(): expected_exception = 'OSError' # If PyPy, expect a different exception than with Python 3 @@ -653,7 +632,7 @@ To enable full traceback, run the following command: 'set debug true' return expected_text -def test_edit_no_editor(base_app, capsys): +def test_base_debug(base_app, capsys): # Purposely set the editor to None base_app.editor = None @@ -664,6 +643,19 @@ def test_edit_no_editor(base_app, capsys): expected = _expected_no_editor_error() assert normalize(str(err)) == expected + # Set debug true + out = run_cmd(base_app, 'set debug True') + expected = normalize(""" +debug - was: False +now: True +""") + assert out == expected + + # Verify that we now see the exception traceback + run_cmd(base_app, 'edit') + out, err = capsys.readouterr() + assert str(err).startswith('Traceback (most recent call last):') + def test_edit_file(base_app, request, monkeypatch): # Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock base_app.editor = 'fooedit' |