(self, type_)
| 324 | ("values_returning", testing.requires.insert_returning), |
| 325 | ) |
| 326 | def test_bulk_insert(self, type_): |
| 327 | Edge, Point = (self.classes.Edge, self.classes.Point) |
| 328 | Graph = self.classes.Graph |
| 329 | |
| 330 | sess = self._fixture() |
| 331 | |
| 332 | graph = Graph(id=2) |
| 333 | sess.add(graph) |
| 334 | sess.flush() |
| 335 | graph_id = 2 |
| 336 | |
| 337 | data = [ |
| 338 | { |
| 339 | "start": Point(random.randint(1, 50), random.randint(1, 50)), |
| 340 | "end": Point(random.randint(1, 50), random.randint(1, 50)), |
| 341 | "graph_id": graph_id, |
| 342 | } |
| 343 | for i in range(25) |
| 344 | ] |
| 345 | returning = False |
| 346 | if type_ == "statement": |
| 347 | sess.execute(insert(Edge), data) |
| 348 | elif type_ == "stmt_returning": |
| 349 | result = sess.scalars(insert(Edge).returning(Edge), data) |
| 350 | returning = True |
| 351 | elif type_ == "values": |
| 352 | sess.execute(insert(Edge).values(data)) |
| 353 | elif type_ == "values_returning": |
| 354 | result = sess.scalars(insert(Edge).values(data).returning(Edge)) |
| 355 | returning = True |
| 356 | elif type_ == "legacy": |
| 357 | sess.bulk_insert_mappings(Edge, data) |
| 358 | else: |
| 359 | assert False |
| 360 | |
| 361 | if returning: |
| 362 | eq_(result.all(), [Edge(rec["start"], rec["end"]) for rec in data]) |
| 363 | |
| 364 | edges = self.tables.edges |
| 365 | eq_( |
| 366 | sess.execute( |
| 367 | select(edges.c["x1", "y1", "x2", "y2"]) |
| 368 | .where(edges.c.graph_id == graph_id) |
| 369 | .order_by(edges.c.id) |
| 370 | ).all(), |
| 371 | [ |
| 372 | (e["start"].x, e["start"].y, e["end"].x, e["end"].y) |
| 373 | for e in data |
| 374 | ], |
| 375 | ) |
| 376 | |
| 377 | @testing.combinations("legacy", "statement") |
| 378 | def test_bulk_insert_heterogeneous(self, type_): |
nothing calls this directly
no test coverage detected