-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
We define public API here. | ||
So, later our code can be used like so: | ||
.. code:: python | ||
import returns | ||
result: returns.Result[int, str] | ||
See: https://github.com/dry-python/returns/issues/73 | ||
""" | ||
|
||
from returns.functions import compose, safe, pipeline | ||
from returns.result import Failure, Result, Success | ||
from returns.primitives.exceptions import UnwrapFailedError | ||
|
||
__all__ = ( # noqa: Z410 | ||
'compose', | ||
'safe', | ||
'pipeline', | ||
'Failure', | ||
'Result', | ||
'Success', | ||
'UnwrapFailedError', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from typing import Type | ||
|
||
import pytest | ||
|
||
from returns.functions import raise_exception | ||
from returns.result import Failure, Success | ||
|
||
|
||
class _CustomException(Exception): | ||
"""Just for the test.""" | ||
|
||
|
||
@pytest.mark.parametrize('exception_type', [ | ||
TypeError, | ||
ValueError, | ||
_CustomException, | ||
]) | ||
def test_raise_regular_exception(exception_type: Type[Exception]): | ||
"""Ensures that regular exception can be thrown.""" | ||
with pytest.raises(exception_type): | ||
raise_exception(exception_type()) | ||
|
||
|
||
def test_failure_can_be_fixed(): | ||
"""Ensures that exceptions can work with Failures.""" | ||
failure = Failure(ValueError('Message')) | ||
with pytest.raises(ValueError): | ||
failure.fix(raise_exception) | ||
|
||
|
||
def test_success_is_not_touched(): | ||
"""Ensures that exceptions can work with Success.""" | ||
assert Success(1).fix(raise_exception) == Success(1) |