async def test__items_aiter(self): # Items to be returned. item1 = 17 item2 = 100 item3 = 211 # Make pages from mock responses parent = mock.sentinel.parent page1 = page_iterator_async.Page( parent, (item1, item2), page_iterator_async._item_to_value_identity) page2 = page_iterator_async.Page( parent, (item3, ), page_iterator_async._item_to_value_identity) iterator = PageAsyncIteratorImpl(None, None) iterator._next_page = mock.AsyncMock(side_effect=[page1, page2, None]) items_aiter = iterator._items_aiter() assert inspect.isasyncgen(items_aiter) # Consume items and check the state of the iterator. assert iterator.num_results == 0 assert await items_aiter.__anext__() == item1 assert iterator.num_results == 1 assert await items_aiter.__anext__() == item2 assert iterator.num_results == 2 assert await items_aiter.__anext__() == item3 assert iterator.num_results == 3 with pytest.raises(StopAsyncIteration): await items_aiter.__anext__()
async def test_anext(self): parent = mock.sentinel.parent page_1 = page_iterator_async.Page( parent, ("item 1.1", "item 1.2"), page_iterator_async._item_to_value_identity) page_2 = page_iterator_async.Page( parent, ("item 2.1", ), page_iterator_async._item_to_value_identity) async_iterator = PageAsyncIteratorImpl(None, None) async_iterator._next_page = mock.AsyncMock( side_effect=[page_1, page_2, None]) # Consume items and check the state of the async_iterator. assert async_iterator.num_results == 0 assert await async_iterator.__anext__() == "item 1.1" assert async_iterator.num_results == 1 assert await async_iterator.__anext__() == "item 1.2" assert async_iterator.num_results == 2 assert await async_iterator.__anext__() == "item 2.1" assert async_iterator.num_results == 3 with pytest.raises(StopAsyncIteration): await async_iterator.__anext__()
async def test__page_aiter_increment(self): iterator = PageAsyncIteratorImpl(None, None) page = page_iterator_async.Page( iterator, ("item", ), page_iterator_async._item_to_value_identity) iterator._next_page = mock.AsyncMock(side_effect=[page, None]) assert iterator.num_results == 0 page_aiter = iterator._page_aiter(increment=True) await page_aiter.__anext__() assert iterator.num_results == 1