def test_creating_controller_with_eager_consumer_results_in_error(
        eager_consumer):

    with pytest.raises(InvertedIterationError) as excinfo:
        InvertedIterationController(eager_consumer)

    assert ('Consumer attempted to access a second value without yielding.'
            in str(excinfo.value))
def test_creating_controller_creates_consumer_from_bind_func():
    bind_consumer = MagicMock()
    bind_consumer.return_value = object()

    controller = InvertedIterationController(bind_consumer)

    assert bind_consumer.call_count == 1
    args, _ = bind_consumer.call_args
    assert isinstance(args[0], Iterable)
    assert controller.consumer is bind_consumer.return_value
def controller_with_non_consuming_consumer(non_consuming_consumer):
    return InvertedIterationController(non_consuming_consumer)
def controller(consumer):
    return InvertedIterationController(consumer)
def controller_with_failing_consumer(failing_consumer):
    return InvertedIterationController(failing_consumer)
def controller_with_lazy_consumer(lazy_consumer):
    return InvertedIterationController(lazy_consumer)
def controller_with_greedy_consumer(greedy_consumer):
    return InvertedIterationController(greedy_consumer)