- break test_insert tests into explicitly get_lastrowid() vs. implicit_returning tests,
fix up requirements to split them out
self.isdelete = compiled.isdelete
if self.isinsert or self.isupdate or self.isdelete:
- self._is_explicit_returning = compiled.statement._returning
- self._is_implicit_returning = compiled.returning and \
- not compiled.statement._returning
+ self._is_explicit_returning = bool(compiled.statement._returning)
+ self._is_implicit_returning = bool(compiled.returning and \
+ not compiled.statement._returning)
if not parameters:
self.compiled_parameters = [compiled.construct_params()]
engine.dispose = dispose
return engine
+
def testing_engine(url=None, options=None):
"""Produce an engine configured by --options with optional overrides."""
profiling = None
assertions = None
requirements = None
+config = None
util = None
file_config = None
db_url = None
db_opts = {}
options = None
+_existing_engine = None
def _log(option, opt_str, value, parser):
global logging
# late imports, has to happen after config as well
# as nose plugins like coverage
global util, fixtures, engines, exclusions, \
- assertions, warnings, profiling
+ assertions, warnings, profiling,\
+ config
from sqlalchemy.testing import fixtures, engines, exclusions, \
- assertions, warnings, profiling
+ assertions, warnings, profiling, config
from sqlalchemy import util
def describeTest(self, test):
test_suite.__name__ = cls.__name__
for requirement in cls.__requires__:
check = getattr(config.requirements, requirement)
- try:
- check(test_suite)()
- except TypeError:
- import pdb
- pdb.set_trace()
+ check(test_suite)()
if cls.__unsupported_on__:
spec = exclusions.db_spec(*cls.__unsupported_on__)
engines.testing_reaper._after_test_ctx()
warnings.resetwarnings()
+ def _setup_engine(self, ctx):
+ if getattr(ctx, '__engine_options__', None):
+ global _existing_engine
+ _existing_engine = config.db
+ config.db = engines.testing_engine(options=ctx.__engine_options__)
+
+ def _restore_engine(self, ctx):
+ global _existing_engine
+ if _existing_engine is not None:
+ config.db = _existing_engine
+ _existing_engine = None
+
def startContext(self, ctx):
if not isinstance(ctx, type) \
or not issubclass(ctx, fixtures.TestBase):
return
self._do_skips(ctx)
+ self._setup_engine(ctx)
def stopContext(self, ctx):
if not isinstance(ctx, type) \
engines.testing_reaper._stop_test_ctx()
if not options.low_connections:
assertions.global_cleanup_assertions()
+ self._restore_engine(ctx)
"Backend does not require denormalized names."
)
+ @property
+ def implements_get_lastrowid(self):
+ """"target dialect implements the executioncontext.get_lastrowid()
+ method without reliance on RETURNING.
+
+ """
+ return exclusions.open()
+
+ @property
+ def emulated_lastrowid(self):
+ """"target dialect retrieves cursor.lastrowid, or fetches
+ from a database-side function after an insert() construct executes,
+ within the get_lastrowid() method.
+
+ Only dialects that "pre-execute", or need RETURNING to get last
+ inserted id, would return closed/fail/skip for this.
+
+ """
+ return exclusions.closed()
+
@property
def dbapi_lastrowid(self):
""""target platform includes a 'lastrowid' accessor on the DBAPI
from ..schema import Table, Column
-class InsertSequencingTest(fixtures.TablesTest):
+class LastrowidTest(fixtures.TablesTest):
run_deletes = 'each'
+ __requires__ = 'implements_get_lastrowid', 'autoincrement_insert'
+
+ __engine_options__ = {"implicit_returning": False}
+
@classmethod
def define_tables(cls, metadata):
Table('autoinc_pk', metadata,
Column('data', String(50))
)
- def _assert_round_trip(self, table):
- row = config.db.execute(table.select()).first()
+ def _assert_round_trip(self, table, conn):
+ row = conn.execute(table.select()).first()
eq_(
row,
(1, "some data")
)
- @requirements.autoincrement_insert
def test_autoincrement_on_insert(self):
config.db.execute(
self.tables.autoinc_pk.insert(),
data="some data"
)
- self._assert_round_trip(self.tables.autoinc_pk)
+ self._assert_round_trip(self.tables.autoinc_pk, config.db)
- @requirements.autoincrement_insert
def test_last_inserted_id(self):
r = config.db.execute(
class ReturningTest(fixtures.TablesTest):
run_deletes = 'each'
- __requires__ = 'returning',
+ __requires__ = 'returning', 'autoincrement_insert'
+
+ __engine_options__ = {"implicit_returning": True}
+
+ def _assert_round_trip(self, table, conn):
+ row = conn.execute(table.select()).first()
+ eq_(
+ row,
+ (1, "some data")
+ )
@classmethod
def define_tables(cls, metadata):
fetched_pk = config.db.scalar(select([table.c.id]))
eq_(fetched_pk, pk)
+ def test_autoincrement_on_insert_implcit_returning(self):
+
+ config.db.execute(
+ self.tables.autoinc_pk.insert(),
+ data="some data"
+ )
+ self._assert_round_trip(self.tables.autoinc_pk, config.db)
+
+ def test_last_inserted_id_implicit_returning(self):
+
+ r = config.db.execute(
+ self.tables.autoinc_pk.insert(),
+ data="some data"
+ )
+ pk = config.db.scalar(select([self.tables.autoinc_pk.c.id]))
+ eq_(
+ r.inserted_primary_key,
+ [pk]
+ )
-__all__ = ('InsertSequencingTest', 'InsertBehaviorTest', 'ReturningTest')
+__all__ = ('LastrowidTest', 'InsertBehaviorTest', 'ReturningTest')