Example #1
0
    def test_should_consume_no_items_when_underlying_queue_empty(
            self, underlying_nowait_get):
        ctx = Mock()
        ctx.Empty = Empty
        queue = ConsumingQueue(ctx)

        def empty_queue_get_nowait():
            raise Empty()

        underlying_nowait_get.side_effect = empty_queue_get_nowait

        queue.consume_available_items()

        self.assertEqual(queue.items, [])
Example #2
0
    def test_should_give_item_size_of_zero_when_underlying_queue_is_empty(
            self, underlying_nowait_get):
        ctx = Mock()
        ctx.Empty = Empty
        queue = ConsumingQueue(ctx)

        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)
Example #3
0
    def test_should_consume_one_item_when_underlying_queue_has_one(
            self, underlying_nowait_get):
        ctx = Mock()
        ctx.Empty = Empty
        queue = ConsumingQueue(ctx)

        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'])
Example #4
0
    def test_should_give_item_size_of_n_when_underlying_queue_has_n_elements(
            self, underlying_nowait_get):
        ctx = Mock()
        ctx.Empty = Empty
        queue = ConsumingQueue(ctx)

        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)