(self)
| 1655 | self.assertEqual(sys.getrefcount(aiter), refs_before) |
| 1656 | |
| 1657 | def test_for_6(self): |
| 1658 | I = 0 |
| 1659 | |
| 1660 | class Manager: |
| 1661 | async def __aenter__(self): |
| 1662 | nonlocal I |
| 1663 | I += 10000 |
| 1664 | |
| 1665 | async def __aexit__(self, *args): |
| 1666 | nonlocal I |
| 1667 | I += 100000 |
| 1668 | |
| 1669 | class Iterable: |
| 1670 | def __init__(self): |
| 1671 | self.i = 0 |
| 1672 | |
| 1673 | def __aiter__(self): |
| 1674 | return self |
| 1675 | |
| 1676 | async def __anext__(self): |
| 1677 | if self.i > 10: |
| 1678 | raise StopAsyncIteration |
| 1679 | self.i += 1 |
| 1680 | return self.i |
| 1681 | |
| 1682 | ############## |
| 1683 | |
| 1684 | manager = Manager() |
| 1685 | iterable = Iterable() |
| 1686 | mrefs_before = sys.getrefcount(manager) |
| 1687 | irefs_before = sys.getrefcount(iterable) |
| 1688 | |
| 1689 | async def main(): |
| 1690 | nonlocal I |
| 1691 | |
| 1692 | async with manager: |
| 1693 | async for i in iterable: |
| 1694 | I += 1 |
| 1695 | I += 1000 |
| 1696 | |
| 1697 | with warnings.catch_warnings(): |
| 1698 | warnings.simplefilter("error") |
| 1699 | # Test that __aiter__ that returns an asynchronous iterator |
| 1700 | # directly does not throw any warnings. |
| 1701 | run_async(main()) |
| 1702 | self.assertEqual(I, 111011) |
| 1703 | |
| 1704 | self.assertEqual(sys.getrefcount(manager), mrefs_before) |
| 1705 | self.assertEqual(sys.getrefcount(iterable), irefs_before) |
| 1706 | |
| 1707 | ############## |
| 1708 | |
| 1709 | async def main(): |
| 1710 | nonlocal I |
| 1711 | |
| 1712 | async with Manager(): |
| 1713 | async for i in Iterable(): |
| 1714 | I += 1 |
nothing calls this directly
no test coverage detected