MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_bulk_insert_heterogeneous

Method test_bulk_insert_heterogeneous

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

Source from the content-addressed store, hash-verified

376
377 @testing.combinations("legacy", "statement")
378 def test_bulk_insert_heterogeneous(self, type_):
379 Edge, Point = (self.classes.Edge, self.classes.Point)
380 Graph = self.classes.Graph
381
382 sess = self._fixture()
383
384 graph = Graph(id=2)
385 sess.add(graph)
386 sess.flush()
387 graph_id = 2
388
389 d1 = [
390 {
391 "start": Point(random.randint(1, 50), random.randint(1, 50)),
392 "end": Point(random.randint(1, 50), random.randint(1, 50)),
393 "graph_id": graph_id,
394 }
395 for i in range(3)
396 ]
397 d2 = [
398 {
399 "start": Point(random.randint(1, 50), random.randint(1, 50)),
400 "graph_id": graph_id,
401 }
402 for i in range(2)
403 ]
404 d3 = [
405 {
406 "x2": random.randint(1, 50),
407 "y2": random.randint(1, 50),
408 "graph_id": graph_id,
409 }
410 for i in range(2)
411 ]
412 data = d1 + d2 + d3
413 random.shuffle(data)
414
415 assert_data = [
416 {
417 "start": d["start"] if "start" in d else None,
418 "end": (
419 d["end"]
420 if "end" in d
421 else Point(d["x2"], d["y2"]) if "x2" in d else None
422 ),
423 "graph_id": d["graph_id"],
424 }
425 for d in data
426 ]
427
428 if type_ == "statement":
429 sess.execute(insert(Edge), data)
430 elif type_ == "legacy":
431 sess.bulk_insert_mappings(Edge, data)
432 else:
433 assert False
434
435 edges = self.tables.edges

Callers

nothing calls this directly

Calls 13

_fixtureMethod · 0.95
insertFunction · 0.90
eq_Function · 0.90
selectFunction · 0.90
GraphClass · 0.70
PointClass · 0.70
addMethod · 0.45
flushMethod · 0.45
executeMethod · 0.45
bulk_insert_mappingsMethod · 0.45
allMethod · 0.45
order_byMethod · 0.45

Tested by

no test coverage detected