MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_one_or_none

Method test_one_or_none

test/aaa_profiling/test_resultset.py:127–155  ·  view source on GitHub ↗
(self, one_or_first, rows_present)

Source from the content-addressed store, hash-verified

125 (False, 2),
126 )
127 def test_one_or_none(self, one_or_first, rows_present):
128 # TODO: this is not testing the ORM level "scalar_mapping"
129 # mode which has a different performance profile
130 t, t2 = self.tables("table1", "table2")
131
132 with testing.db.connect().execution_options(
133 compiled_cache=None
134 ) as conn:
135 stmt = t.select()
136 if rows_present == 0:
137 stmt = stmt.where(1 == 0)
138 elif rows_present == 1:
139 stmt = stmt.limit(1)
140
141 result = conn.execute(stmt)
142
143 @profiling.function_call_count()
144 def go():
145 if one_or_first:
146 result.one()
147 else:
148 result.first()
149
150 try:
151 go()
152 finally:
153 # hmmmm, connection close context manager does not
154 # seem to be handling this for a profile that skips
155 result.close()
156
157 def test_contains_doesnt_compile(self, connection):
158 t, t2 = self.tables("table1", "table2")

Callers

nothing calls this directly

Calls 8

goFunction · 0.70
execution_optionsMethod · 0.45
connectMethod · 0.45
selectMethod · 0.45
whereMethod · 0.45
limitMethod · 0.45
executeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected