diff options
author | Jason Kirtland <jek@discorporate.us> | 2008-01-19 23:37:11 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2008-01-19 23:37:11 +0000 |
commit | 4be99db15b7a62b37493c86da07bcc787f44a7df (patch) | |
tree | b9d71342f22e307a08c38487d63c795039f10b96 | |
parent | 21193cebe22f44982cb70ecd64743df63494b17d (diff) | |
download | sqlalchemy-4be99db15b7a62b37493c86da07bcc787f44a7df.tar.gz |
- Restored 2.3 compat. in lib/sqlalchemy
- Part one of test suite fixes to run on 2.3
Lots of failures still around sets; sets.Set differs from __builtin__.set
particularly in the binops. We depend on set extensively now and may need to
provide a corrected sets.Set subclass on 2.3.
-rw-r--r-- | lib/sqlalchemy/orm/dependency.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/query.py | 2 | ||||
-rw-r--r-- | test/base/utils.py | 2 | ||||
-rw-r--r-- | test/orm/dynamic.py | 16 | ||||
-rw-r--r-- | test/orm/inheritance/abc_polymorphic.py | 3 | ||||
-rw-r--r-- | test/orm/inheritance/basic.py | 2 | ||||
-rw-r--r-- | test/orm/inheritance/magazine.py | 3 | ||||
-rw-r--r-- | test/orm/inheritance/polymorph.py | 14 | ||||
-rw-r--r-- | test/orm/inheritance/polymorph2.py | 4 | ||||
-rw-r--r-- | test/orm/relationships.py | 12 | ||||
-rw-r--r-- | test/testlib/__init__.py | 4 | ||||
-rw-r--r-- | test/testlib/compat.py | 22 | ||||
-rw-r--r-- | test/testlib/engines.py | 30 | ||||
-rw-r--r-- | test/testlib/profiling.py | 1 | ||||
-rw-r--r-- | test/testlib/tables.py | 5 | ||||
-rw-r--r-- | test/testlib/testing.py | 42 | ||||
-rw-r--r-- | test/zblog/blog.py | 1 |
17 files changed, 89 insertions, 76 deletions
diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py index c28598542..f675aff50 100644 --- a/lib/sqlalchemy/orm/dependency.py +++ b/lib/sqlalchemy/orm/dependency.py @@ -282,7 +282,7 @@ class DetectKeySwitch(DependencyProcessor): self._process_key_switches(deplist, uowcommit) def _process_key_switches(self, deplist, uowcommit): - switchers = util.Set(s for s in deplist if self._pks_changed(uowcommit, s)) + switchers = util.Set([s for s in deplist if self._pks_changed(uowcommit, s)]) if switchers: # yes, we're doing a linear search right now through the UOW. only # takes effect when primary key values have actually changed. diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index ab31b328b..201d0e2e3 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -880,7 +880,7 @@ class Query(object): if tuples: rows = util.OrderedSet() for row in fetch: - rows.add(tuple(proc(context, row) for proc in process)) + rows.add(tuple([proc(context, row) for proc in process])) else: rows = util.UniqueAppender([]) for row in fetch: diff --git a/test/base/utils.py b/test/base/utils.py index 5ebc33921..61e2b95a8 100644 --- a/test/base/utils.py +++ b/test/base/utils.py @@ -2,7 +2,7 @@ import testenv; testenv.configure_for_tests() import unittest from sqlalchemy import util, sql, exceptions from testlib import * - +from testlib import sorted class OrderedDictTest(PersistTest): def test_odict(self): diff --git a/test/orm/dynamic.py b/test/orm/dynamic.py index 199eb474f..3382f0205 100644 --- a/test/orm/dynamic.py +++ b/test/orm/dynamic.py @@ -170,6 +170,7 @@ class FlushTest(FixtureTest): sess.delete(u) sess.close() + def create_backref_test(autoflush, saveuser): def test_backref(self): mapper(User, users, properties={ @@ -203,10 +204,9 @@ def create_backref_test(autoflush, saveuser): sess.flush() self.assert_(list(u.addresses) == []) - test_backref.__name__ = "test%s%s" % ( - (autoflush and "_autoflush" or ""), - (saveuser and "_saveuser" or "_savead"), - ) + test_backref = _function_named( + test_backref, "test%s%s" % ((autoflush and "_autoflush" or ""), + (saveuser and "_saveuser" or "_savead"))) setattr(FlushTest, test_backref.__name__, test_backref) for autoflush in (False, True): @@ -216,7 +216,7 @@ for autoflush in (False, True): class DontDereferenceTest(ORMTest): def define_tables(self, metadata): global users_table, addresses_table - + users_table = Table('users', metadata, Column('id', Integer, primary_key=True), Column('name', String(40)), @@ -245,7 +245,7 @@ class DontDereferenceTest(ORMTest): session.save(user) session.flush() session.clear() - + def query1(): session = create_session(metadata.bind) user = session.query(User).first() @@ -263,7 +263,7 @@ class DontDereferenceTest(ORMTest): self.assertEquals(query1(), [Address(email_address='joe@joesdomain.example')] ) self.assertEquals(query2(), [Address(email_address='joe@joesdomain.example')] ) self.assertEquals(query3(), [Address(email_address='joe@joesdomain.example')] ) - - + + if __name__ == '__main__': testenv.main() diff --git a/test/orm/inheritance/abc_polymorphic.py b/test/orm/inheritance/abc_polymorphic.py index 79cc91d2c..076c7b76b 100644 --- a/test/orm/inheritance/abc_polymorphic.py +++ b/test/orm/inheritance/abc_polymorphic.py @@ -77,7 +77,8 @@ class ABCTest(ORMTest): C(cdata='c2', bdata='c2', adata='c2'), ] == sess.query(C).all() - test_roundtrip.__name__ = 'test_%s' % fetchtype + test_roundtrip = _function_named( + test_roundtrip, 'test_%s' % fetchtype) return test_roundtrip test_union = make_test('union') diff --git a/test/orm/inheritance/basic.py b/test/orm/inheritance/basic.py index 39b9fb916..3f3bf4bdb 100644 --- a/test/orm/inheritance/basic.py +++ b/test/orm/inheritance/basic.py @@ -215,7 +215,7 @@ class GetTest(ORMTest): self.assert_sql_count(testing.db, go, 3) - test_get.__name__ = name + test_get = _function_named(test_get, name) return test_get test_get_polymorphic = create_test(True, 'test_get_polymorphic') diff --git a/test/orm/inheritance/magazine.py b/test/orm/inheritance/magazine.py index b5c5096f5..621f9639f 100644 --- a/test/orm/inheritance/magazine.py +++ b/test/orm/inheritance/magazine.py @@ -207,7 +207,8 @@ def generate_round_trip_test(use_unions=False, use_joins=False): print [page, page2, page3] assert repr(p.issues[0].locations[0].magazine.pages) == repr([page, page2, page3]), repr(p.issues[0].locations[0].magazine.pages) - test_roundtrip.__name__ = "test_%s" % (not use_union and (use_joins and "joins" or "select") or "unions") + test_roundtrip = _function_named( + test_roundtrip, "test_%s" % (not use_union and (use_joins and "joins" or "select") or "unions")) setattr(MagazineTest, test_roundtrip.__name__, test_roundtrip) for (use_union, use_join) in [(True, False), (False, True), (False, False)]: diff --git a/test/orm/inheritance/polymorph.py b/test/orm/inheritance/polymorph.py index 5f0e74fa3..faee63360 100644 --- a/test/orm/inheritance/polymorph.py +++ b/test/orm/inheritance/polymorph.py @@ -342,13 +342,13 @@ def generate_round_trip_test(include_base=False, lazy_relation=True, redefine_co session.delete(c) session.flush() - test_roundtrip.__name__ = "test_%s%s%s%s%s" % ( - (lazy_relation and "lazy" or "eager"), - (include_base and "_inclbase" or ""), - (redefine_colprop and "_redefcol" or ""), - (polymorphic_fetch != 'union' and '_' + polymorphic_fetch or (use_literal_join and "_litjoin" or "")), - (use_outer_joins and '_outerjoins' or '') - ) + test_roundtrip = _function_named( + test_roundtrip, "test_%s%s%s%s%s" % ( + (lazy_relation and "lazy" or "eager"), + (include_base and "_inclbase" or ""), + (redefine_colprop and "_redefcol" or ""), + (polymorphic_fetch != 'union' and '_' + polymorphic_fetch or (use_literal_join and "_litjoin" or "")), + (use_outer_joins and '_outerjoins' or ''))) setattr(RoundTripTest, test_roundtrip.__name__, test_roundtrip) for include_base in [True, False]: diff --git a/test/orm/inheritance/polymorph2.py b/test/orm/inheritance/polymorph2.py index 96a8ddbf6..0f0fff672 100644 --- a/test/orm/inheritance/polymorph2.py +++ b/test/orm/inheritance/polymorph2.py @@ -289,7 +289,9 @@ def generate_test(jointype="join1", usedata=False): assert p.data.data == 'ps data' assert m.data.data == 'ms data' - do_test.__name__ = 'test_relationonbaseclass_%s_%s' % (jointype, data and "nodata" or "data") + do_test = _function_named( + do_test, 'test_relationonbaseclass_%s_%s' % ( + jointype, data and "nodata" or "data")) return do_test for jointype in ["join1", "join2", "join3", "join4"]: diff --git a/test/orm/relationships.py b/test/orm/relationships.py index e23f107ee..40f70bf62 100644 --- a/test/orm/relationships.py +++ b/test/orm/relationships.py @@ -999,13 +999,17 @@ class CustomCollectionsTest(ORMTest): pass class MyCollection(object): - def __init__(self): self.data = [] + def __init__(self): + self.data = [] @collection.appender - def append(self, value): self.data.append(value) + def append(self, value): + self.data.append(value) @collection.remover - def remove(self, value): self.data.remove(value) + def remove(self, value): + self.data.remove(value) @collection.iterator - def __iter__(self): return iter(self.data) + def __iter__(self): + return iter(self.data) mapper(Parent, sometable, properties={ 'children':relation(Child, collection_class=MyCollection) diff --git a/test/testlib/__init__.py b/test/testlib/__init__.py index d7daaddf8..46852191a 100644 --- a/test/testlib/__init__.py +++ b/test/testlib/__init__.py @@ -11,6 +11,7 @@ from testlib.testing import rowset from testlib.testing import PersistTest, AssertMixin, ORMTest, SQLCompileTest import testlib.profiling as profiling import testlib.engines as engines +from testlib.compat import set, sorted, _function_named __all__ = ('testing', @@ -18,4 +19,5 @@ __all__ = ('testing', 'Table', 'Column', 'rowset', 'PersistTest', 'AssertMixin', 'ORMTest', 'SQLCompileTest', - 'profiling', 'engines') + 'profiling', 'engines', + 'set', 'sorted', '_function_named') diff --git a/test/testlib/compat.py b/test/testlib/compat.py new file mode 100644 index 000000000..590bf50f4 --- /dev/null +++ b/test/testlib/compat.py @@ -0,0 +1,22 @@ +import new + +__all__ = 'set', 'sorted', '_function_named' + +try: + set = set +except NameError: + from sets import Set as set + +try: + sorted = sorted +except NameError: + def sorted(iterable): + return list(iterable).sort() + +def _function_named(fn, newname): + try: + fn.__name__ = newname + except: + fn = new.function(fn.func_code, fn.func_globals, newname, + fn.func_defaults, fn.func_closure) + return fn diff --git a/test/testlib/engines.py b/test/testlib/engines.py index b576a1536..8cb321597 100644 --- a/test/testlib/engines.py +++ b/test/testlib/engines.py @@ -1,14 +1,15 @@ import sys, weakref from testlib import config +from testlib.compat import * class ConnectionKiller(object): def __init__(self): self.proxy_refs = weakref.WeakKeyDictionary() - + def checkout(self, dbapi_con, con_record, con_proxy): self.proxy_refs[con_proxy] = True - + def _apply_all(self, methods): for rec in self.proxy_refs: if rec is not None and rec.is_valid: @@ -29,12 +30,12 @@ class ConnectionKiller(object): def close_all(self): self._apply_all(('rollback', 'close')) - + def assert_all_closed(self): for rec in self.proxy_refs: if rec.is_valid: assert False - + testing_reaper = ConnectionKiller() def assert_conns_closed(fn): @@ -43,9 +44,8 @@ def assert_conns_closed(fn): fn(*args, **kw) finally: testing_reaper.assert_all_closed() - decorated.__name__ = fn.__name__ - return decorated - + return _function_named(decorated, fn.__name__) + def rollback_open_connections(fn): """Decorator that rolls back all open connections after fn execution.""" @@ -54,8 +54,7 @@ def rollback_open_connections(fn): fn(*args, **kw) finally: testing_reaper.rollback_all() - decorated.__name__ = fn.__name__ - return decorated + return _function_named(decorated, fn.__name__) def close_open_connections(fn): """Decorator that closes all connections after fn execution.""" @@ -65,14 +64,13 @@ def close_open_connections(fn): fn(*args, **kw) finally: testing_reaper.close_all() - decorated.__name__ = fn.__name__ - return decorated + return _function_named(decorated, fn.__name__) class ReconnectFixture(object): def __init__(self, dbapi): self.dbapi = dbapi self.connections = [] - + def __getattr__(self, key): return getattr(self.dbapi, key) @@ -85,17 +83,17 @@ class ReconnectFixture(object): for c in list(self.connections): c.close() self.connections = [] - + def reconnecting_engine(url=None, options=None): url = url or config.db_url dbapi = config.db.dialect.dbapi engine = testing_engine(url, {'module':ReconnectFixture(dbapi)}) engine.test_shutdown = engine.dialect.dbapi.shutdown return engine - + def testing_engine(url=None, options=None): """Produce an engine configured by --options with optional overrides.""" - + from sqlalchemy import create_engine from testlib.testing import ExecutionContextWrapper @@ -133,5 +131,3 @@ def utf8_engine(url=None, options=None): url = str(url) return testing_engine(url, options) - - diff --git a/test/testlib/profiling.py b/test/testlib/profiling.py index ac7ca84d7..8867d0169 100644 --- a/test/testlib/profiling.py +++ b/test/testlib/profiling.py @@ -2,6 +2,7 @@ import os, sys from testlib.config import parser, post_configure +from testlib.compat import * import testlib.config __all__ = 'profiled', 'function_call_count' diff --git a/test/testlib/tables.py b/test/testlib/tables.py index 4ec92cc8b..33b1b20db 100644 --- a/test/testlib/tables.py +++ b/test/testlib/tables.py @@ -135,7 +135,10 @@ def data(): class BaseObject(object): def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, ",".join("%s=%s" % (k, repr(v)) for k, v in self.__dict__.iteritems() if k[0] != '_')) + return "%s(%s)" % (self.__class__.__name__, + ",".join(["%s=%s" % (k, repr(v)) + for k, v in self.__dict__.iteritems() + if k[0] != '_'])) class User(BaseObject): def __init__(self): diff --git a/test/testlib/testing.py b/test/testlib/testing.py index 1b5a55f04..b05795efd 100644 --- a/test/testlib/testing.py +++ b/test/testlib/testing.py @@ -2,9 +2,11 @@ # monkeypatches unittest.TestLoader.suiteClass at import time -import itertools, unittest, re, sys, os, operator, warnings +import itertools, os, operator, re, sys, unittest, warnings from cStringIO import StringIO import testlib.config as config +from testlib.compat import * + sql, MetaData, clear_mappers, Session, util = None, None, None, None, None sa_exceptions = None @@ -23,6 +25,7 @@ _ops = { '<': operator.lt, # sugar ('testing.db'); set here by config() at runtime db = None + def fails_on(*dbs): """Mark a test as expected to fail on one or more database implementations. @@ -49,11 +52,7 @@ def fails_on(*dbs): raise AssertionError( "Unexpected success for '%s' on DB implementation '%s'" % (fn_name, config.db.name)) - try: - maybe.__name__ = fn_name - except: - pass - return maybe + return _function_named(maybe, fn_name) return decorate def fails_on_everything_except(*dbs): @@ -80,11 +79,7 @@ def fails_on_everything_except(*dbs): raise AssertionError( "Unexpected success for '%s' on DB implementation '%s'" % (fn_name, config.db.name)) - try: - maybe.__name__ = fn_name - except: - pass - return maybe + return _function_named(maybe, fn_name) return decorate def unsupported(*dbs): @@ -103,17 +98,14 @@ def unsupported(*dbs): return True else: return fn(*args, **kw) - try: - maybe.__name__ = fn_name - except: - pass - return maybe + return _function_named(maybe, fn_name) return decorate def exclude(db, op, spec): """Mark a test as unsupported by specific database server versions. Stackable, both with other excludes and other decorators. Examples:: + # Not supported by mydb versions less than 1, 0 @exclude('mydb', '<', (1,0)) # Other operators work too @@ -130,11 +122,7 @@ def exclude(db, op, spec): return True else: return fn(*args, **kw) - try: - maybe.__name__ = fn_name - except: - pass - return maybe + return _function_named(maybe, fn_name) return decorate def _is_excluded(db, op, spec): @@ -204,11 +192,7 @@ def emits_warning(*messages): return fn(*args, **kw) finally: resetwarnings() - try: - safe.__name__ = fn.__name__ - except: - pass - return safe + return _function_named(safe, fn.__name__) return decorate def uses_deprecated(*messages): @@ -247,11 +231,7 @@ def uses_deprecated(*messages): return fn(*args, **kw) finally: resetwarnings() - try: - safe.__name__ = fn.__name__ - except: - pass - return safe + return _function_named(safe, fn.__name__) return decorate def resetwarnings(): diff --git a/test/zblog/blog.py b/test/zblog/blog.py index 04dd33ac5..9e48a202f 100644 --- a/test/zblog/blog.py +++ b/test/zblog/blog.py @@ -1,6 +1,7 @@ __all__ = ['Blog', 'Post', 'Topic', 'TopicAssociation', 'Comment'] import datetime +from testlib.compat import * class Blog(object): def __init__(self, owner=None): |