def test_generator_execute_success(successful_action): @reversible.gen def action(): result = yield successful_action() raise reversible.Return(result) value = yield reversible.execute(action()) assert 42 == value
def test_generator_lift(make_future, successful_action): @reversible.gen def action(): yield successful_action() value = yield reversible.lift(make_future(42)) raise reversible.Return(value) value = yield reversible.execute(action()) assert 42 == value
def test_generator_execute_failure_catch(failing_action): @reversible.gen def action(): try: yield failing_action() except MyException: raise tornado.gen.Return(100) result = yield reversible.execute(action()) assert 100 == result
def test_generator_execute_failure(failing_action): @reversible.gen def action(): yield failing_action() pytest.fail('Should not reach here') with pytest.raises(MyException) as exc_info: yield reversible.execute(action()) assert 'great sadness' in str(exc_info)
def test_generator_lift_with_rollback(make_future, failing_action): @reversible.gen def action(): value = yield reversible.lift(make_future(42)) assert value == 42 yield failing_action() with pytest.raises(MyException) as exc_info: yield reversible.execute(action()) assert 'great sadness' in str(exc_info)
def test_generator_lift_with_failing_future(make_future, successful_action): @reversible.gen def action(): yield successful_action() yield reversible.lift( make_future(exc=MyException('future failed')) ) with pytest.raises(MyException) as exc_info: yield reversible.execute(action()) assert 'future failed' in str(exc_info)
def test_generator_rollback_fail( successful_with_rollback_fail_action, failing_action ): @reversible.gen def action(): yield successful_with_rollback_fail_action() yield failing_action() pytest.fail('Should not reach here') with pytest.raises(RollbackFailException) as exc_info: yield reversible.execute(action()) assert 'rollback failed' in str(exc_info)
def test_rollback_fail(rollback_failed_action): with pytest.raises(RollbackFailException) as exc_info: yield reversible.execute(rollback_failed_action()) assert 'rollback failed' in str(exc_info)
def test_failing_action(failing_action): with pytest.raises(MyException) as exc_info: yield reversible.execute(failing_action()) assert 'great sadness' in str(exc_info)
def test_execute_success(successful_action): result = yield reversible.execute(successful_action()) assert 42 == result