コード例 #1
0
def test_maybe_transform(integer):
    MonadTransformTester(monad=Maybe.just,
                         value=integer).test(run_to_maybe_test=False)

    assert Maybe.nothing().to_box() == Box(None)
    assert Maybe.nothing().to_either() == Left(None)
    assert Maybe.nothing().to_lazy().get() is None
    assert Maybe.nothing().to_try() == Try(None, is_success=False)
    assert Maybe.nothing().to_validation() == Validation.success(None)
コード例 #2
0
    def to_maybe(self):
        """
        Transform Either to Maybe.

        :returns: Empty Maybe
        :rtype: Maybe[None]
        """
        from pymonet.maybe import Maybe

        return Maybe.nothing()
コード例 #3
0
 def to_maybe_test(self):
     if self.is_fail:
         assert self.monad(self.value).to_maybe() == Maybe.nothing()
     else:
         assert self.monad(self.value).to_maybe() == Maybe.just(self.value)
コード例 #4
0
def test_validation_transform(integer):
    MonadTransformTester(monad=Validation.success, value=integer).test(run_to_validation_test=False)

    Validation.fail([integer]).to_maybe() == Maybe.nothing()
    Validation.fail([integer]).to_either() == Left([integers])
コード例 #5
0
def test_maybe_if_filter_returns_false_method_should_return_empty_maybe():
    assert Maybe.just(41).filter(
        lambda value: value % 2 == 0) == Maybe.nothing()
コード例 #6
0
def test_maybe_is_nothing_should_return_proper_boolean(integer):
    assert Maybe.just(integer).is_nothing is False
    assert Maybe.nothing().is_nothing is True
コード例 #7
0
def test_maybe_get_or_else_method_should_return_argument_when_monad_is_empty(
        integer):
    assert Maybe.nothing().get_or_else(integer) is integer
コード例 #8
0
def test_maybe_bind_should_not_call_mapper_when_monad_has_nothing(maybe_spy):
    Maybe.nothing().bind(maybe_spy.binder)

    assert maybe_spy.binder.call_count == 0
コード例 #9
0
def test_maybe_map_operator_should_be_applied_only_on_just_value(integer):
    assert Maybe.just(42).map(increase) == Maybe.just(43)
    assert Maybe.nothing().map(increase) == Maybe.nothing()
コード例 #10
0
def test_maybe_eq_operator_should_compare_values(integer):

    assert Maybe.just(integer) == Maybe.just(integer)
    assert Maybe.just(None) == Maybe.just(None)

    assert Maybe.just(integer) != Maybe.nothing()
コード例 #11
0
def test_maybe_ap_on_empty_maybe_should_not_be_applied():
    def lambda_fn():
        raise TypeError

    assert Maybe.nothing().ap(Maybe.just(lambda_fn)) == Maybe.nothing()
    assert Maybe.just(42).ap(Maybe.nothing()) == Maybe.nothing()