def test_should_consume_no_items_when_underlying_queue_empty(self, underlying_nowait_get):
        queue = ConsumingQueue()

        def empty_queue_get_nowait():
            raise Empty()

        underlying_nowait_get.side_effect = empty_queue_get_nowait

        queue.consume_available_items()

        self.assertEqual(queue.items, [])
    def test_should_consume_no_items_when_underlying_queue_empty(self, underlying_nowait_get):
        queue = ConsumingQueue()

        def empty_queue_get_nowait():
            raise Empty()

        underlying_nowait_get.side_effect = empty_queue_get_nowait

        queue.consume_available_items()

        self.assertEqual(queue.items, [])
    def test_should_give_item_size_of_zero_when_underlying_queue_is_empty(self, underlying_nowait_get):
        queue = ConsumingQueue()

        def empty_queue_get_nowait():
            raise Empty()

        # not a generator, beware!!!!
        underlying_nowait_get.side_effect = empty_queue_get_nowait

        queue.consume_available_items()

        self.assertEqual(queue.size, 0)
    def test_should_give_item_size_of_zero_when_underlying_queue_is_empty(self, underlying_nowait_get):
        queue = ConsumingQueue()

        def empty_queue_get_nowait():
            raise Empty()

        # not a generator, beware!!!!
        underlying_nowait_get.side_effect = empty_queue_get_nowait

        queue.consume_available_items()

        self.assertEqual(queue.size, 0)
    def test_should_consume_one_item_when_underlying_queue_has_one(self, underlying_nowait_get):
        queue = ConsumingQueue()

        def empty_queue_get_nowait():
            yield "any-item"
            raise Empty()

        # generator, needs initialization!
        underlying_nowait_get.side_effect = empty_queue_get_nowait()

        queue.consume_available_items()

        self.assertEqual(queue.items, ['any-item'])
    def test_should_consume_one_item_when_underlying_queue_has_one(self, underlying_nowait_get):
        queue = ConsumingQueue()

        def empty_queue_get_nowait():
            yield "any-item"
            raise Empty()

        # generator, needs initialization!
        underlying_nowait_get.side_effect = empty_queue_get_nowait()

        queue.consume_available_items()

        self.assertEqual(queue.items, ['any-item'])
    def test_should_give_item_size_of_n_when_underlying_queue_has_n_elements(self, underlying_nowait_get):
        queue = ConsumingQueue()

        def empty_queue_get_nowait():
            yield 'first'
            yield 'second'
            yield 'third'
            raise Empty()

        # generator, needs initialization!
        underlying_nowait_get.side_effect = empty_queue_get_nowait()

        queue.consume_available_items()

        self.assertEqual(queue.size, 3)
    def test_should_give_item_size_of_n_when_underlying_queue_has_n_elements(self, underlying_nowait_get):
        queue = ConsumingQueue()

        def empty_queue_get_nowait():
            yield 'first'
            yield 'second'
            yield 'third'
            raise Empty()

        # generator, needs initialization!
        underlying_nowait_get.side_effect = empty_queue_get_nowait()

        queue.consume_available_items()

        self.assertEqual(queue.size, 3)
Exemplo n.º 9
0
    def test_should_consume_many_items_when_underlying_queue_has_them(
            self, underlying_nowait_get):
        ctx = Mock()
        ctx.Empty = Empty
        queue = ConsumingQueue(ctx)

        def empty_queue_get_nowait():
            yield "any-item"
            yield "any-other-item"
            yield "some stuff"
            raise Empty()

        # generator, needs initialization!
        underlying_nowait_get.side_effect = empty_queue_get_nowait()

        queue.consume_available_items()

        self.assertEqual(queue.items,
                         ['any-item', 'any-other-item', 'some stuff'])