1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
import pytest
from returns.primitives.exceptions import UnwrapFailedError
from returns.result import Failure, Success
def test_unwrap_success():
"""Ensures that unwrap works for Success container."""
assert Success(5).unwrap() == 5
def test_unwrap_failure():
"""Ensures that unwrap works for Failure container."""
with pytest.raises(UnwrapFailedError):
assert Failure(5).unwrap()
def test_unwrap_failure_with_exception():
"""Ensures that unwrap raises from the original exception."""
expected_exception = ValueError('error')
with pytest.raises(UnwrapFailedError) as excinfo:
Failure(expected_exception).unwrap()
assert 'ValueError: error' in str(
excinfo.getrepr(), # noqa: WPS441
)
|