From: Jason Kirtland Date: Fri, 15 Aug 2008 23:17:24 +0000 (+0000) Subject: - Mock engines take on the .name of their dialect. [ticket:1123] X-Git-Tag: rel_0_5rc1~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10848388a385a5619a5a626abea2e1ddf10d36d6;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Mock engines take on the .name of their dialect. [ticket:1123] Slightly backward incompatible: the .name is a read-only property. The test suite was assigning .name = 'mock'; this no longer works. --- diff --git a/lib/sqlalchemy/engine/strategies.py b/lib/sqlalchemy/engine/strategies.py index c9e65982ef..62a4b9bb84 100644 --- a/lib/sqlalchemy/engine/strategies.py +++ b/lib/sqlalchemy/engine/strategies.py @@ -1,20 +1,20 @@ """Strategies for creating new instances of Engine types. -These are semi-private implementation classes which -provide the underlying behavior for the "strategy" keyword argument -available on [sqlalchemy.engine#create_engine()]. -Current available options are ``plain``, ``threadlocal``, and -``mock``. - -New strategies can be added via new ``EngineStrategy`` -classes. -""" +These are semi-private implementation classes which provide the +underlying behavior for the "strategy" keyword argument available on +[sqlalchemy.engine#create_engine()]. Current available options are +``plain``, ``threadlocal``, and ``mock``. + +New strategies can be added via new ``EngineStrategy`` classes. +""" +from operator import attrgetter from sqlalchemy.engine import base, threadlocal, url from sqlalchemy import util, exc from sqlalchemy import pool as poollib + strategies = {} class EngineStrategy(object): @@ -189,7 +189,8 @@ class MockEngineStrategy(EngineStrategy): self.execute = execute engine = property(lambda s: s) - dialect = property(lambda s:s._dialect) + dialect = property(attrgetter('_dialect')) + name = property(lambda s: s._dialect.name) def contextual_connect(self, **kwargs): return self diff --git a/test/engine/ddlevents.py b/test/engine/ddlevents.py index 9894a29005..8274c63476 100644 --- a/test/engine/ddlevents.py +++ b/test/engine/ddlevents.py @@ -319,12 +319,12 @@ class DDLTest(TestBase): 'S S-T T-"s s"."t t"-b') def test_filter(self): cx = self.mock_engine() - cx.name = 'mock' tbl = Table('t', MetaData(), Column('id', Integer)) + target = cx.name assert DDL('')._should_execute('x', tbl, cx) - assert DDL('', on='mock')._should_execute('x', tbl, cx) + assert DDL('', on=target)._should_execute('x', tbl, cx) assert not DDL('', on='bogus')._should_execute('x', tbl, cx) assert DDL('', on=lambda x,y,z: True)._should_execute('x', tbl, cx) assert(DDL('', on=lambda x,y,z: z.engine.name != 'bogus').