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

Function assert_engine

lib/sqlalchemy/testing/assertsql.py:478–520  ·  view source on GitHub ↗
(engine)

Source from the content-addressed store, hash-verified

476
477@contextlib.contextmanager
478def assert_engine(engine):
479 asserter = SQLAsserter()
480
481 orig = []
482
483 @event.listens_for(engine, "before_execute")
484 def connection_execute(
485 conn, clauseelement, multiparams, params, execution_options
486 ):
487 conn._WORKAROUND_ISSUE_13018 = True
488 # grab the original statement + params before any cursor
489 # execution
490 orig[:] = clauseelement, multiparams, params
491
492 @event.listens_for(engine, "after_cursor_execute")
493 def cursor_execute(
494 conn, cursor, statement, parameters, context, executemany
495 ):
496 if not context:
497 return
498 # then grab real cursor statements and associate them all
499 # around a single context
500 if (
501 asserter.accumulated
502 and asserter.accumulated[-1].context is context
503 ):
504 obs = asserter.accumulated[-1]
505 else:
506 obs = SQLExecuteObserved(context, orig[0], orig[1], orig[2])
507 asserter.accumulated.append(obs)
508
509 obs.statements.append(
510 SQLCursorExecuteObserved(
511 statement, parameters, context, executemany
512 )
513 )
514
515 try:
516 yield asserter
517 finally:
518 event.remove(engine, "after_cursor_execute", cursor_execute)
519 event.remove(engine, "before_execute", connection_execute)
520 asserter._close()

Callers 8

test_insert_computedMethod · 0.90
test_update_computedMethod · 0.90
test_insert_identityMethod · 0.90
test_query_joinMethod · 0.90
test_eager_joinMethod · 0.90
test_existsMethod · 0.90
test_eager_selectinMethod · 0.90
test_load_both_wpolyMethod · 0.90

Calls 3

_closeMethod · 0.95
SQLAsserterClass · 0.85
removeMethod · 0.45

Tested by 8

test_insert_computedMethod · 0.72
test_update_computedMethod · 0.72
test_insert_identityMethod · 0.72
test_query_joinMethod · 0.72
test_eager_joinMethod · 0.72
test_existsMethod · 0.72
test_eager_selectinMethod · 0.72
test_load_both_wpolyMethod · 0.72