MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_execution_options

Method test_execution_options

test/orm/test_session.py:772–864  ·  view source on GitHub ↗
(
        self,
        session_type: testing.Variation,
        merge: testing.Variation,
        method: testing.Variation,
        add_statement_options: testing.Variation,
    )

Source from the content-addressed store, hash-verified

770 )
771 @testing.variation("add_statement_options", [True, False])
772 def test_execution_options(
773 self,
774 session_type: testing.Variation,
775 merge: testing.Variation,
776 method: testing.Variation,
777 add_statement_options: testing.Variation,
778 ):
779 users, User = self.tables.users, self.classes.User
780 self.mapper_registry.map_imperatively(User, users)
781
782 session_execution_options = {
783 "populate_existing": True,
784 "autoflush": False,
785 "opt1": "z",
786 "opt5": "q",
787 }
788
789 expected_opts = session_execution_options
790
791 if add_statement_options:
792 statement_options = {"opt2": "w", "opt4": "y", "opt5": "w"}
793 expected_opts = {**expected_opts, **statement_options}
794 else:
795 statement_options = {}
796
797 if merge:
798 query_opts = {
799 "compiled_cache": {},
800 "opt1": "q",
801 "opt2": "p",
802 "opt3": "r",
803 "populate_existing": False,
804 }
805 expected_opts = {**expected_opts, **query_opts}
806 else:
807 query_opts = {}
808
809 if session_type.plain:
810 sess = Session(
811 testing.db, execution_options=session_execution_options
812 )
813 elif session_type.sessionmaker:
814 maker = sessionmaker(
815 testing.db, execution_options=session_execution_options
816 )
817 sess = maker()
818 else:
819 session_type.fail()
820
821 gather_options = {}
822
823 @event.listens_for(sess, "do_orm_execute")
824 def check(ctx: ORMExecuteState) -> None:
825 assert not gather_options
826 gather_options.update(ctx.execution_options)
827
828 if method.scalar:
829 statement = select(User).limit(1)

Callers

nothing calls this directly

Calls 15

scalarMethod · 0.95
executeMethod · 0.95
scalarsMethod · 0.95
getMethod · 0.95
queryMethod · 0.95
closeMethod · 0.95
SessionClass · 0.90
sessionmakerClass · 0.90
selectFunction · 0.90
eq_Function · 0.90
map_imperativelyMethod · 0.80
failMethod · 0.45

Tested by

no test coverage detected