MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / test_nesting_with_functions

Method test_nesting_with_functions

test/orm/test_assorted_eager.py:487–566  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

485 pass
486
487 def test_nesting_with_functions(self):
488 Stat, Foo, stats, foo, Data, datas = (
489 self.classes.Stat,
490 self.classes.Foo,
491 self.tables.stats,
492 self.tables.foo,
493 self.classes.Data,
494 self.tables.datas,
495 )
496
497 self.mapper_registry.map_imperatively(Data, datas)
498 self.mapper_registry.map_imperatively(
499 Foo,
500 foo,
501 properties={
502 "data": relationship(
503 Data, backref=backref("foo", uselist=False)
504 )
505 },
506 )
507
508 self.mapper_registry.map_imperatively(
509 Stat, stats, properties={"data": relationship(Data)}
510 )
511
512 session = fixture_session()
513
514 data = [Data(a=x) for x in range(5)]
515 session.add_all(data)
516
517 session.add_all(
518 (
519 Stat(data=data[0], somedata=1),
520 Stat(data=data[1], somedata=2),
521 Stat(data=data[2], somedata=3),
522 Stat(data=data[3], somedata=4),
523 Stat(data=data[4], somedata=5),
524 Stat(data=data[0], somedata=6),
525 Stat(data=data[1], somedata=7),
526 Stat(data=data[2], somedata=8),
527 Stat(data=data[3], somedata=9),
528 Stat(data=data[4], somedata=10),
529 )
530 )
531 session.flush()
532
533 arb_data = (
534 sa.select(
535 stats.c.data_id, sa.func.max(stats.c.somedata).label("max")
536 )
537 .where(stats.c.data_id <= 5)
538 .group_by(stats.c.data_id)
539 )
540
541 arb_result = session.connection().execute(arb_data).fetchall()
542
543 # order the result list descending based on 'max'
544 arb_result.sort(key=lambda a: a._mapping["max"], reverse=True)

Callers

nothing calls this directly

Calls 15

relationshipFunction · 0.90
backrefFunction · 0.90
fixture_sessionFunction · 0.90
eq_Function · 0.90
StatClass · 0.85
map_imperativelyMethod · 0.80
maxMethod · 0.80
joinedloadMethod · 0.80
DataClass · 0.70
add_allMethod · 0.45
flushMethod · 0.45
group_byMethod · 0.45

Tested by

no test coverage detected