def test_absolve(self): right = either.Right(1) left = either.Left('error') right_effect = effect.success(right) left_effect = effect.success(left) assert effect.absolve(right_effect).run(None) == 1 with pytest.raises(Exception): # todo effect.absolve(left_effect).run(None)
def test_try_modify(self): int_ref = ref.Ref(0) int_ref.try_modify(lambda _: either.Left('')).either().run(None) assert int_ref.value == 0 int_ref.try_modify(lambda _: either.Right(1)).run(None) assert int_ref.value == 1
def test_either(self): success = effect.success(1) error = effect.error('error') assert success.either().run(None) == either.Right(1) error.either().run(None) == either.Left('error')
def test_retry(self): s = schedule.recurs(2, schedule.spaced(timedelta(seconds=1))) assert (effect.error('whoops').retry(s).either().run(MockModules()) == either.Left(('whoops', 'whoops')))