(
self, async_engine, filter_, yield_per, yield_per_type
)
| 1250 | @testing.combinations("method", "opt", argnames="yield_per_type") |
| 1251 | @async_test |
| 1252 | async def test_partitions( |
| 1253 | self, async_engine, filter_, yield_per, yield_per_type |
| 1254 | ): |
| 1255 | users = self.tables.users |
| 1256 | async with async_engine.connect() as conn: |
| 1257 | stmt = select(users) |
| 1258 | if yield_per and yield_per_type == "opt": |
| 1259 | stmt = stmt.execution_options(yield_per=yield_per) |
| 1260 | result = await conn.stream(stmt) |
| 1261 | |
| 1262 | if filter_ == "mappings": |
| 1263 | result = result.mappings() |
| 1264 | elif filter_ == "scalars": |
| 1265 | result = result.scalars(1) |
| 1266 | |
| 1267 | if yield_per and yield_per_type == "method": |
| 1268 | result = result.yield_per(yield_per) |
| 1269 | |
| 1270 | check_result = [] |
| 1271 | |
| 1272 | # stream() sets stream_results unconditionally |
| 1273 | assert isinstance( |
| 1274 | result._real_result.cursor_strategy, |
| 1275 | _cursor.BufferedRowCursorFetchStrategy, |
| 1276 | ) |
| 1277 | |
| 1278 | if yield_per: |
| 1279 | partition_size = yield_per |
| 1280 | |
| 1281 | eq_(result._real_result.cursor_strategy._bufsize, yield_per) |
| 1282 | |
| 1283 | async for partition in result.partitions(): |
| 1284 | check_result.append(partition) |
| 1285 | else: |
| 1286 | eq_(result._real_result.cursor_strategy._bufsize, 5) |
| 1287 | |
| 1288 | partition_size = 5 |
| 1289 | async for partition in result.partitions(partition_size): |
| 1290 | check_result.append(partition) |
| 1291 | |
| 1292 | ranges = [ |
| 1293 | (i, min(20, i + partition_size)) |
| 1294 | for i in range(1, 21, partition_size) |
| 1295 | ] |
| 1296 | |
| 1297 | if filter_ == "mappings": |
| 1298 | eq_( |
| 1299 | check_result, |
| 1300 | [ |
| 1301 | [ |
| 1302 | {"user_id": i, "user_name": "name%d" % i} |
| 1303 | for i in range(a, b) |
| 1304 | ] |
| 1305 | for (a, b) in ranges |
| 1306 | ], |
| 1307 | ) |
| 1308 | elif filter_ == "scalars": |
| 1309 | eq_( |
nothing calls this directly
no test coverage detected