def test_stack_safety(self): with recursion_limit(100): effect.sequence_async([effect.success(v) for v in range(500)]).run(None) e = effect.error('') for _ in range(500): e = e.recover(lambda _: effect.error('')) e = e.recover(lambda _: effect.success('')) with recursion_limit(100): e.run(None) e = effect.success('') for _ in range(500): e = e.either() with recursion_limit(100): e.run(None)
def test_error_repr(self): assert repr(effect.error('reason')) == 'error(\'reason\')'
def test_error(self): with pytest.raises(Exception): # todo effect.error('error').run(None)
def test_recover(self): success = effect.success(1) error = effect.error('error') assert success.recover(lambda e: effect.success(2)).run(None) == 1 assert error.recover(lambda e: effect.success(2)).run(None) == 2
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_recover_io_bound(self, e): effect.error('').recover(effect.io_bound(lambda _: e) ).run(None) == e.run(None)
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')))