From 8f04c5319120773906161548b82a8d83e387843e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 16 Jul 2012 17:37:32 -0400 Subject: [PATCH] some test fixes and cleanup --- lib/sqlalchemy/orm/util.py | 18 ++++++++++-------- test/aaa_profiling/test_orm.py | 34 +++++++++++++++++----------------- test/orm/test_inspect.py | 2 +- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 03af1ad766..e9e11ee875 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -93,7 +93,8 @@ def _validator_events(desc, key, validator, include_removes): if include_removes: event.listen(desc, "remove", remove, raw=True, retval=True) -def polymorphic_union(table_map, typecolname, aliasname='p_union', cast_nulls=True): +def polymorphic_union(table_map, typecolname, + aliasname='p_union', cast_nulls=True): """Create a ``UNION`` statement used by a polymorphic mapper. See :ref:`concrete_inheritance` for an example of how @@ -102,13 +103,14 @@ def polymorphic_union(table_map, typecolname, aliasname='p_union', cast_nulls=Tr :param table_map: mapping of polymorphic identities to :class:`.Table` objects. :param typecolname: string name of a "discriminator" column, which will be - derived from the query, producing the polymorphic identity for each row. If - ``None``, no polymorphic discriminator is generated. + derived from the query, producing the polymorphic identity for + each row. If ``None``, no polymorphic discriminator is generated. :param aliasname: name of the :func:`~sqlalchemy.sql.expression.alias()` construct generated. - :param cast_nulls: if True, non-existent columns, which are represented as labeled - NULLs, will be passed into CAST. This is a legacy behavior that is problematic - on some backends such as Oracle - in which case it can be set to False. + :param cast_nulls: if True, non-existent columns, which are represented + as labeled NULLs, will be passed into CAST. This is a legacy behavior + that is problematic on some backends such as Oracle - in which case it + can be set to False. """ @@ -312,7 +314,7 @@ class PathRegistry(object): @classmethod def coerce(cls, raw): - return util.reduce(lambda prev, next:prev[next], raw, cls.root) + return util.reduce(lambda prev, next: prev[next], raw, cls.root) @classmethod def token(cls, token): @@ -320,7 +322,7 @@ class PathRegistry(object): def __add__(self, other): return util.reduce( - lambda prev, next:prev[next], + lambda prev, next: prev[next], other.path, self) def __repr__(self): diff --git a/test/aaa_profiling/test_orm.py b/test/aaa_profiling/test_orm.py index d66d2704dd..4295f51e4d 100644 --- a/test/aaa_profiling/test_orm.py +++ b/test/aaa_profiling/test_orm.py @@ -62,7 +62,7 @@ class MergeTest(fixtures.MappedTest): # bigger operation so using a small variance @profiling.function_call_count(variance=0.05, - versions={'2.7':93, '2.6':93, '2.5':94, '3': 100}) + versions={'2.7':96, '2.6':96, '2.5':96, '3': 100}) def go(): return sess2.merge(p1, load=False) p2 = go() @@ -70,7 +70,7 @@ class MergeTest(fixtures.MappedTest): # third call, merge object already present. almost no calls. @profiling.function_call_count(variance=0.05, - versions={'2.7':15, '2.6':15, '2.5':16, '3': 16}) + versions={'2.7':16, '2.6':16, '2.5':16, '3': 16}) def go(): return sess2.merge(p2, load=False) p3 = go() @@ -90,7 +90,7 @@ class MergeTest(fixtures.MappedTest): @profiling.function_call_count(variance=0.10, versions={'2.5':1050, '2.6':1050, - '2.6+cextension':1014, + '2.6+cextension':1014, '2.7':1014, '3':1050} ) @@ -106,14 +106,14 @@ class MergeTest(fixtures.MappedTest): class LoadManyToOneFromIdentityTest(fixtures.MappedTest): """test overhead associated with many-to-one fetches. - Prior to the refactor of LoadLazyAttribute and + Prior to the refactor of LoadLazyAttribute and query._get(), the load from identity map took 2x as many calls (65K calls here instead of around 33K) to load 1000 related objects from the identity map. """ - # only need to test for unexpected variance in a large call + # only need to test for unexpected variance in a large call # count here, # so remove some platforms that have wildly divergent # callcounts. @@ -122,13 +122,13 @@ class LoadManyToOneFromIdentityTest(fixtures.MappedTest): @classmethod def define_tables(cls, metadata): - parent = Table('parent', metadata, - Column('id', Integer, primary_key=True), + parent = Table('parent', metadata, + Column('id', Integer, primary_key=True), Column('data', String(20)), Column('child_id', Integer, ForeignKey('child.id')) ) - child = Table('child', metadata, + child = Table('child', metadata, Column('id', Integer,primary_key=True), Column('data', String(20)) ) @@ -162,10 +162,10 @@ class LoadManyToOneFromIdentityTest(fixtures.MappedTest): ]) parent.insert().execute([ { - 'id':i, - 'data':'p%dc%d' % (i, (i % 250) + 1), + 'id':i, + 'data':'p%dc%d' % (i, (i % 250) + 1), 'child_id':(i % 250) + 1 - } + } for i in xrange(1, 1000) ]) @@ -201,18 +201,18 @@ class MergeBackrefsTest(fixtures.MappedTest): @classmethod def define_tables(cls, metadata): Table('a', metadata, - Column('id', Integer, primary_key=True), + Column('id', Integer, primary_key=True), Column('c_id', Integer, ForeignKey('c.id')) ) Table('b', metadata, - Column('id', Integer, primary_key=True), + Column('id', Integer, primary_key=True), Column('a_id', Integer, ForeignKey('a.id')) ) Table('c', metadata, - Column('id', Integer, primary_key=True), + Column('id', Integer, primary_key=True), ) Table('d', metadata, - Column('id', Integer, primary_key=True), + Column('id', Integer, primary_key=True), Column('a_id', Integer, ForeignKey('a.id')) ) @@ -248,7 +248,7 @@ class MergeBackrefsTest(fixtures.MappedTest): cls.classes.C, cls.classes.D s = Session() s.add_all([ - A(id=i, + A(id=i, bs=[B(id=(i * 50) + j) for j in xrange(1, 50)], c=C(id=i), ds=[D(id=(i * 50) + j) for j in xrange(1, 50)] @@ -263,7 +263,7 @@ class MergeBackrefsTest(fixtures.MappedTest): self.classes.C, self.classes.D s = Session() for a in [ - A(id=i, + A(id=i, bs=[B(id=(i * 50) + j) for j in xrange(1, 50)], c=C(id=i), ds=[D(id=(i * 50) + j) for j in xrange(1, 50)] diff --git a/test/orm/test_inspect.py b/test/orm/test_inspect.py index 128539e68c..4ee01ac62f 100644 --- a/test/orm/test_inspect.py +++ b/test/orm/test_inspect.py @@ -67,7 +67,7 @@ class TestORMInspection(_fixtures.FixtureTest): ualias = aliased(Address) insp = inspect(ualias) is_(insp.mapper, inspect(Address)) - is_(insp.selectable, ualias._AliasedClass__alias) + is_(insp.selectable, ualias._AliasedClass__adapter.selectable) assert not insp.is_selectable assert insp.is_aliased_class -- 2.47.3