Skip to content

Commit 33a451d

Browse files
kmvanbruntanselor
authored andcommitted
Increased unit test coverage for pexcept()
1 parent 83a5ec0 commit 33a451d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/test_cmd2.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,6 +2131,34 @@ def test_pwarning_no_style(base_app, capsys):
21312131
assert err == msg + end
21322132

21332133

2134+
def test_pexcept_style(base_app, capsys):
2135+
msg = Exception('testing...')
2136+
ansi.allow_style = ansi.STYLE_ALWAYS
2137+
2138+
base_app.pexcept(msg)
2139+
out, err = capsys.readouterr()
2140+
assert err.startswith(ansi.style_error("EXCEPTION of type 'Exception' occurred with message: testing..."))
2141+
2142+
2143+
def test_pexcept_no_style(base_app, capsys):
2144+
msg = Exception('testing...')
2145+
ansi.allow_style = ansi.STYLE_ALWAYS
2146+
2147+
base_app.pexcept(msg, apply_style=False)
2148+
out, err = capsys.readouterr()
2149+
assert err.startswith("EXCEPTION of type 'Exception' occurred with message: testing...")
2150+
2151+
2152+
def test_pexcept_not_exception(base_app, capsys):
2153+
# Pass in a msg that is not an Exception object
2154+
msg = False
2155+
ansi.allow_style = ansi.STYLE_ALWAYS
2156+
2157+
base_app.pexcept(msg)
2158+
out, err = capsys.readouterr()
2159+
assert err.startswith(ansi.style_error(msg))
2160+
2161+
21342162
def test_ppaged(outsim_app):
21352163
msg = 'testing...'
21362164
end = '\n'

0 commit comments

Comments
 (0)