(
self, async_engine, filter_, yield_per, yield_per_type
)
| 1321 | @testing.combinations("method", "opt", argnames="yield_per_type") |
| 1322 | @async_test |
| 1323 | async def test_partitions( |
| 1324 | self, async_engine, filter_, yield_per, yield_per_type |
| 1325 | ): |
| 1326 | users = self.tables.users |
| 1327 | async with async_engine.connect() as conn: |
| 1328 | stmt = select(users) |
| 1329 | if yield_per and yield_per_type == "opt": |
| 1330 | stmt = stmt.execution_options(yield_per=yield_per) |
| 1331 | result = await conn.stream(stmt) |
| 1332 | |
| 1333 | if filter_ == "mappings": |
| 1334 | result = result.mappings() |
| 1335 | elif filter_ == "scalars": |
| 1336 | result = result.scalars(1) |
| 1337 | |
| 1338 | if yield_per and yield_per_type == "method": |
| 1339 | result = result.yield_per(yield_per) |
| 1340 | |
| 1341 | check_result = [] |
| 1342 | |
| 1343 | # stream() sets stream_results unconditionally |
| 1344 | assert isinstance( |
| 1345 | result._real_result.cursor_strategy, |
| 1346 | _cursor.BufferedRowCursorFetchStrategy, |
| 1347 | ) |
| 1348 | |
| 1349 | if yield_per: |
| 1350 | partition_size = yield_per |
| 1351 | |
| 1352 | eq_(result._real_result.cursor_strategy._bufsize, yield_per) |
| 1353 | |
| 1354 | async for partition in result.partitions(): |
| 1355 | check_result.append(partition) |
| 1356 | else: |
| 1357 | eq_(result._real_result.cursor_strategy._bufsize, 5) |
| 1358 | |
| 1359 | partition_size = 5 |
| 1360 | async for partition in result.partitions(partition_size): |
| 1361 | check_result.append(partition) |
| 1362 | |
| 1363 | ranges = [ |
| 1364 | (i, min(20, i + partition_size)) |
| 1365 | for i in range(1, 21, partition_size) |
| 1366 | ] |
| 1367 | |
| 1368 | if filter_ == "mappings": |
| 1369 | eq_( |
| 1370 | check_result, |
| 1371 | [ |
| 1372 | [ |
| 1373 | {"user_id": i, "user_name": "name%d" % i} |
| 1374 | for i in range(a, b) |
| 1375 | ] |
| 1376 | for (a, b) in ranges |
| 1377 | ], |
| 1378 | ) |
| 1379 | elif filter_ == "scalars": |
| 1380 | eq_( |
nothing calls this directly
no test coverage detected