async def test_accumulate_range_coroutine(self): async def mul(a, b): return a * b it = ait.accumulate(srange, func=mul) for k in [1, 2, 6]: self.assertEqual(await ait.next(it), k) with self.assertRaises(StopAsyncIteration): await ait.next(it)
async def test_accumulate_gen_function(self): async def gen(): yield 1 yield 2 yield 4 it = ait.accumulate(gen(), func=operator.mul) for k in [1, 2, 8]: self.assertEqual(await ait.next(it), k) with self.assertRaises(StopAsyncIteration): await ait.next(it)
async def test_accumulate_gen_coroutine(self): async def mul(a, b): return a * b async def gen(): yield 1 yield 2 yield 4 it = ait.accumulate(gen(), func=mul) for k in [1, 2, 8]: self.assertEqual(await ait.next(it), k) with self.assertRaises(StopAsyncIteration): await ait.next(it)
async def test_accumulate_range_default(self): it = ait.accumulate(srange) for k in [1, 3, 6]: self.assertEqual(await ait.next(it), k) with self.assertRaises(StopAsyncIteration): await ait.next(it)
async def test_accumulate_empty(self): values = [] async for value in ait.accumulate([]): values.append(value) self.assertEqual(values, [])
async def test_accumulate_range_function(self): it = ait.accumulate(srange, func=operator.mul) for k in [1, 2, 6]: self.assertEqual(await ait.next(it), k) with self.assertRaises(StopAsyncIteration): await ait.next(it)
def accumulate_array(genarr, markets): genacc = aioitertools.accumulate(genarr, BookShapper.build) return genacc