(self)
| 1241 | self.assertRaises(RuntimeError, IgnoreGeneratorExit().close) |
| 1242 | |
| 1243 | def test_AsyncGenerator(self): |
| 1244 | class NonAGen1: |
| 1245 | def __aiter__(self): return self |
| 1246 | def __anext__(self): return None |
| 1247 | def aclose(self): pass |
| 1248 | def athrow(self, typ, val=None, tb=None): pass |
| 1249 | |
| 1250 | class NonAGen2: |
| 1251 | def __aiter__(self): return self |
| 1252 | def __anext__(self): return None |
| 1253 | def aclose(self): pass |
| 1254 | def asend(self, value): return value |
| 1255 | |
| 1256 | class NonAGen3: |
| 1257 | def aclose(self): pass |
| 1258 | def asend(self, value): return value |
| 1259 | def athrow(self, typ, val=None, tb=None): pass |
| 1260 | |
| 1261 | non_samples = [ |
| 1262 | None, 42, 3.14, 1j, b"", "", (), [], {}, set(), |
| 1263 | iter(()), iter([]), NonAGen1(), NonAGen2(), NonAGen3()] |
| 1264 | for x in non_samples: |
| 1265 | self.assertNotIsInstance(x, AsyncGenerator) |
| 1266 | self.assertNotIsSubclass(type(x), AsyncGenerator) |
| 1267 | |
| 1268 | class Gen: |
| 1269 | def __aiter__(self): return self |
| 1270 | async def __anext__(self): return None |
| 1271 | async def aclose(self): pass |
| 1272 | async def asend(self, value): return value |
| 1273 | async def athrow(self, typ, val=None, tb=None): pass |
| 1274 | |
| 1275 | class MinimalAGen(AsyncGenerator): |
| 1276 | async def asend(self, value): |
| 1277 | return value |
| 1278 | async def athrow(self, typ, val=None, tb=None): |
| 1279 | await super().athrow(typ, val, tb) |
| 1280 | |
| 1281 | async def gen(): |
| 1282 | yield 1 |
| 1283 | |
| 1284 | samples = [gen(), Gen(), MinimalAGen()] |
| 1285 | for x in samples: |
| 1286 | self.assertIsInstance(x, AsyncIterator) |
| 1287 | self.assertIsInstance(x, AsyncGenerator) |
| 1288 | self.assertIsSubclass(type(x), AsyncGenerator) |
| 1289 | self.validate_abstract_methods(AsyncGenerator, 'asend', 'athrow') |
| 1290 | |
| 1291 | def run_async(coro): |
| 1292 | result = None |
| 1293 | while True: |
| 1294 | try: |
| 1295 | coro.send(None) |
| 1296 | except StopIteration as ex: |
| 1297 | result = ex.args[0] if ex.args else None |
| 1298 | break |
| 1299 | return result |
| 1300 |
nothing calls this directly
no test coverage detected