Skip to content

Commit

Permalink
Add test for BoundResult.exit and fix bug on it
Browse files Browse the repository at this point in the history
  • Loading branch information
ilotoki0804 committed Oct 5, 2024
1 parent 4e989cc commit c0e6b30
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/fieldenum/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def as_option(self) -> Option[R]:
unreachable(other)

def exit(self, error_code: str | int | None = 1) -> NoReturn:
sys.exit(error_code if self else 0)
sys.exit(0 if self else error_code)

def rebound[NewBound: BaseException](self, bound: type[NewBound], /) -> BoundResult[R, NewBound]:
match self:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ def test_bound_result():
) == BoundResult.Failed(error, Exception)


with pytest.raises(SystemExit) as exc:
BoundResult.Success("success", Exception).exit()
assert exc.value.code == 0

with pytest.raises(SystemExit) as exc:
BoundResult.Failed(error, Exception).exit()
assert exc.value.code == 1

with pytest.raises(SystemExit) as exc:
BoundResult.Failed(error, Exception).exit("failed miserably...")
assert exc.value.code == "failed miserably..."

with pytest.raises(SystemExit) as exc:
BoundResult.Failed(error, Exception).exit(None)
assert exc.value.code == None


@pytest.mark.parametrize(
"second_param",
[True, False],
Expand Down

0 comments on commit c0e6b30

Please sign in to comment.