MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_bulk_insert

Method test_bulk_insert

test/orm/test_composites.py:326–375  ·  view source on GitHub ↗
(self, type_)

Source from the content-addressed store, hash-verified

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_):

Callers

nothing calls this directly

Calls 15

_fixtureMethod · 0.95
insertFunction · 0.90
eq_Function · 0.90
selectFunction · 0.90
GraphClass · 0.70
PointClass · 0.70
EdgeClass · 0.70
addMethod · 0.45
flushMethod · 0.45
executeMethod · 0.45
scalarsMethod · 0.45
returningMethod · 0.45

Tested by

no test coverage detected