Skip to content

Commit

Permalink
Merge pull request #545 from amoffat/544-ok-code-exception
Browse files Browse the repository at this point in the history
Properly raise ErrorReturnCode_0 on exit code 0
  • Loading branch information
amoffat authored Oct 24, 2020
2 parents 4b90c93 + eb9d051 commit 07170fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def get_rc_exc(rc):
except KeyError:
pass

if rc > 0:
if rc >= 0:
name = "ErrorReturnCode_%d" % rc
base = ErrorReturnCode
else:
Expand Down
5 changes: 5 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ def test_ok_code_none(self):
py = create_tmp_test("exit(0)")
python(py.name, _ok_code=None)

def test_ok_code_exception(self):
from sh import ErrorReturnCode_0
py = create_tmp_test("exit(0)")
self.assertRaises(ErrorReturnCode_0, python, py.name, _ok_code=2)

def test_none_arg(self):
py = create_tmp_test("""
import sys
Expand Down

0 comments on commit 07170fe

Please sign in to comment.