async def test_groupby_empty(self): async def gen(): for _ in range(0): yield # Force generator with no actual iteration async for _ in ait.groupby(gen()): self.fail("No iteration should have happened")
async def test_groupby_list_key(self): data = "aAabBA" it = ait.groupby(data, key=str.lower) for k in [("a", ["a", "A", "a"]), ("b", ["b", "B"]), ("a", ["A"])]: self.assertEqual(await ait.next(it), k) with self.assertRaises(StopAsyncIteration): await ait.next(it)
async def test_groupby_list(self): data = "aaabba" it = ait.groupby(data) for k in [("a", ["a", "a", "a"]), ("b", ["b", "b"]), ("a", ["a"])]: self.assertEqual(await ait.next(it), k) with self.assertRaises(StopAsyncIteration): await ait.next(it)
async def test_groupby_gen_key(self): async def gen(): for c in "aAabBA": yield c it = ait.groupby(gen(), key=str.lower) for k in [("a", ["a", "A", "a"]), ("b", ["b", "B"]), ("a", ["A"])]: self.assertEqual(await ait.next(it), k) with self.assertRaises(StopAsyncIteration): await ait.next(it)
async def test_groupby_gen(self): async def gen(): for c in "aaabba": yield c it = ait.groupby(gen()) for k in [("a", ["a", "a", "a"]), ("b", ["b", "b"]), ("a", ["a"])]: self.assertEqual(await ait.next(it), k) with self.assertRaises(StopAsyncIteration): await ait.next(it)