From 106accd07c8c54304fe67e98b88e50ddb26d3f95 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Wed, 7 Apr 2021 12:34:14 -0400 Subject: Increased unit test coverage for pexcept() --- tests/test_cmd2.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index aeddfc78..7595327f 100755 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -2131,6 +2131,34 @@ def test_pwarning_no_style(base_app, capsys): assert err == msg + end +def test_pexcept_style(base_app, capsys): + msg = Exception('testing...') + ansi.allow_style = ansi.STYLE_ALWAYS + + base_app.pexcept(msg) + out, err = capsys.readouterr() + assert err.startswith(ansi.style_error("EXCEPTION of type 'Exception' occurred with message: testing...")) + + +def test_pexcept_no_style(base_app, capsys): + msg = Exception('testing...') + ansi.allow_style = ansi.STYLE_ALWAYS + + base_app.pexcept(msg, apply_style=False) + out, err = capsys.readouterr() + assert err.startswith("EXCEPTION of type 'Exception' occurred with message: testing...") + + +def test_pexcept_not_exception(base_app, capsys): + # Pass in a msg that is not an Exception object + msg = False + ansi.allow_style = ansi.STYLE_ALWAYS + + base_app.pexcept(msg) + out, err = capsys.readouterr() + assert err.startswith(ansi.style_error(msg)) + + def test_ppaged(outsim_app): msg = 'testing...' end = '\n' -- cgit v1.2.1