예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
 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)
예제 #5
0
    async def test_accumulate_empty(self):
        values = []
        async for value in ait.accumulate([]):
            values.append(value)

        self.assertEqual(values, [])
예제 #6
0
 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)
예제 #7
0
 def accumulate_array(genarr, markets):
     genacc = aioitertools.accumulate(genarr, BookShapper.build)
     return genacc