From: Mike Bayer Date: Tue, 29 Aug 2017 17:37:02 +0000 (-0400) Subject: Generalize autocommit testing X-Git-Tag: origin~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec4f567f31856a92bd91144112cd29df356a8ca8;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Generalize autocommit testing To support adding AUTOCOMMIT to more dialects, add a suite test Change-Id: I585dcce19fcdce70e8cf21aea4edaa97d7bf2bb9 --- diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py index 95aef0e175..08a7b1cedc 100644 --- a/lib/sqlalchemy/testing/requirements.py +++ b/lib/sqlalchemy/testing/requirements.py @@ -512,6 +512,11 @@ class SuiteRequirements(Requirements): return exclusions.open() + @property + def autocommit(self): + """target dialect supports 'AUTOCOMMIT' as an isolation_level""" + return exclusions.closed() + @property def json_type(self): """target platform implements a native JSON type.""" diff --git a/lib/sqlalchemy/testing/suite/test_dialect.py b/lib/sqlalchemy/testing/suite/test_dialect.py index 0e62c347fe..5dd1f05017 100644 --- a/lib/sqlalchemy/testing/suite/test_dialect.py +++ b/lib/sqlalchemy/testing/suite/test_dialect.py @@ -43,6 +43,49 @@ class ExceptionTest(fixtures.TablesTest): ) +class AutocommitTest(fixtures.TablesTest): + + run_deletes = 'each' + + __requires__ = 'autocommit', + + __backend__ = True + + @classmethod + def define_tables(cls, metadata): + Table('some_table', metadata, + Column('id', Integer, primary_key=True, autoincrement=False), + Column('data', String(50)), + test_needs_acid=True + ) + + def _test_conn_autocommits(self, conn, autocommit): + trans = conn.begin() + conn.execute( + self.tables.some_table.insert(), + {"id": 1, "data": "some data"} + ) + trans.rollback() + + eq_( + conn.scalar(select([self.tables.some_table.c.id])), + 1 if autocommit else None + ) + + conn.execute(self.tables.some_table.delete()) + + def test_autocommit_on(self): + conn = config.db.connect() + c2 = conn.execution_options(isolation_level='AUTOCOMMIT') + self._test_conn_autocommits(c2, True) + conn.invalidate() + self._test_conn_autocommits(conn, False) + + def test_autocommit_off(self): + conn = config.db.connect() + self._test_conn_autocommits(conn, False) + + class EscapingTest(fixtures.TestBase): @provide_metadata def test_percent_sign_round_trip(self): diff --git a/test/requirements.py b/test/requirements.py index ee3bb2db52..4fcf541e31 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -264,6 +264,13 @@ class DefaultRequirements(SuiteRequirements): + fails_on('postgresql+pypostgresql', 'pypostgresql bombs on multiple isolation level calls') + @property + def autocommit(self): + """target dialect supports 'AUTOCOMMIT' as an isolation_level""" + return only_on( + ('postgresql', 'mysql'), + "dialect does not support AUTOCOMMIT isolation mode") + @property def row_triggers(self): """Target must support standard statement-running EACH ROW triggers."""