summaryrefslogtreecommitdiff
path: root/tests/test_cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-03-02 10:26:45 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-03-02 10:26:45 -0500
commit7024aa0e705e522e8e0cc9b4555bb17a5a35ed45 (patch)
treef27278d32dbc5d9ee19dbb2f5dd929b943df4789 /tests/test_cmd2.py
parent6b14aa6579d9c5bdd32bf8c3d67f11db8b575bb0 (diff)
downloadcmd2-git-exception_passthrough.tar.gz
Added cmd2.exceptions.PassThroughExceptionexception_passthrough
Diffstat (limited to 'tests/test_cmd2.py')
-rwxr-xr-xtests/test_cmd2.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 0c3333c1..b4b13945 100755
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -534,7 +534,7 @@ def test_in_script(request):
def test_system_exit_in_command(base_app, capsys):
- """Test raising SystemExit from a command"""
+ """Test raising SystemExit in a command"""
import types
def do_system_exit(self, _):
@@ -546,6 +546,21 @@ def test_system_exit_in_command(base_app, capsys):
assert stop
+def test_passthrough_exception_in_command(base_app):
+ """Test raising a PassThroughException in a command"""
+ import types
+
+ def do_passthrough(self, _):
+ wrapped_ex = OSError("Pass me up")
+ raise exceptions.PassThroughException(wrapped_ex=wrapped_ex)
+
+ setattr(base_app, 'do_passthrough', types.MethodType(do_passthrough, base_app))
+
+ with pytest.raises(OSError) as excinfo:
+ base_app.onecmd_plus_hooks('passthrough')
+ assert 'Pass me up' in str(excinfo.value)
+
+
def test_output_redirection(base_app):
fd, filename = tempfile.mkstemp(prefix='cmd2_test', suffix='.txt')
os.close(fd)