(self, ait_class, anext)
| 638 | self._check_async_iterator_anext(ait_class, anext) |
| 639 | |
| 640 | def _check_async_iterator_anext(self, ait_class, anext): |
| 641 | g = ait_class() |
| 642 | async def consume(): |
| 643 | results = [] |
| 644 | results.append(await anext(g)) |
| 645 | results.append(await anext(g)) |
| 646 | results.append(await anext(g, 'buckle my shoe')) |
| 647 | return results |
| 648 | res = self.loop.run_until_complete(consume()) |
| 649 | self.assertEqual(res, [1, 2, 'buckle my shoe']) |
| 650 | with self.assertRaises(StopAsyncIteration): |
| 651 | self.loop.run_until_complete(consume()) |
| 652 | |
| 653 | async def test_2(): |
| 654 | g1 = ait_class() |
| 655 | self.assertEqual(await anext(g1), 1) |
| 656 | self.assertEqual(await anext(g1), 2) |
| 657 | with self.assertRaises(StopAsyncIteration): |
| 658 | await anext(g1) |
| 659 | with self.assertRaises(StopAsyncIteration): |
| 660 | await anext(g1) |
| 661 | |
| 662 | g2 = ait_class() |
| 663 | self.assertEqual(await anext(g2, "default"), 1) |
| 664 | self.assertEqual(await anext(g2, "default"), 2) |
| 665 | self.assertEqual(await anext(g2, "default"), "default") |
| 666 | self.assertEqual(await anext(g2, "default"), "default") |
| 667 | |
| 668 | return "completed" |
| 669 | |
| 670 | result = self.loop.run_until_complete(test_2()) |
| 671 | self.assertEqual(result, "completed") |
| 672 | |
| 673 | def test_send(): |
| 674 | p = ait_class() |
| 675 | obj = anext(p, "completed") |
| 676 | with self.assertRaises(StopIteration): |
| 677 | with contextlib.closing(obj.__await__()) as g: |
| 678 | g.send(None) |
| 679 | |
| 680 | test_send() |
| 681 | |
| 682 | async def test_throw(): |
| 683 | p = ait_class() |
| 684 | obj = anext(p, "completed") |
| 685 | self.assertRaises(SyntaxError, obj.throw, SyntaxError) |
| 686 | return "completed" |
| 687 | |
| 688 | result = self.loop.run_until_complete(test_throw()) |
| 689 | self.assertEqual(result, "completed") |
| 690 | |
| 691 | def test_async_generator_anext(self): |
| 692 | async def agen(): |
no test coverage detected