File: test_maybe_conversions.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 (23 lines) | stat: -rw-r--r-- 653 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from returns.maybe import Nothing, Some


def test_some_is_true() -> None:
    """Ensures that ``Something(...)`` is ``True`` when treated as a boolean."""
    assert bool(Some(123))
    assert bool(Some('abc'))


def test_nothing_is_false() -> None:
    """Ensures that ``Nothing`` is ``False`` when treated as a boolean."""
    assert not bool(Nothing)


def test_some_none_is_true() -> None:
    """
    Ensures that ``Something(None)`` is ``True`` when treated as a boolean.

    See <https://github.com/dry-python/returns/issues/2177> for the discussion
    of this design choice.
    """
    assert bool(Some(None))
    assert bool(Some(Nothing))