File: test_result_unwrap.py

package info (click to toggle)
python-returns 0.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,652 kB
  • sloc: python: 11,000; makefile: 18
file content (26 lines) | stat: -rw-r--r-- 752 bytes parent folder | download | duplicates (2)
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
    )