From 9d700bc60cea22f480fdfaa96c610dc496c89f60 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 10 May 2008 18:38:20 +0000 Subject: [PATCH] correcting dataload profiles for various tests --- test/orm/_base.py | 9 ++++++--- test/orm/_fixtures.py | 2 +- test/orm/assorted_eager.py | 4 +++- test/orm/cycles.py | 11 +++++++++-- test/orm/memusage.py | 22 +++++++++++++++------- test/orm/pickled.py | 3 ++- test/orm/unitofwork.py | 7 +++---- test/testlib/testing.py | 2 +- 8 files changed, 40 insertions(+), 20 deletions(-) diff --git a/test/orm/_base.py b/test/orm/_base.py index bfce00d0f0..444d4b88cc 100644 --- a/test/orm/_base.py +++ b/test/orm/_base.py @@ -174,8 +174,10 @@ class MappedTest(ORMTest): if self.run_define_tables == 'each': self.tables.clear() self.metadata.drop_all() + self.metadata.clear() self.define_tables(self.metadata) self.metadata.create_all() + self.tables.update(self.metadata.tables) if self.run_setup_classes == 'each': self.classes.clear() @@ -197,12 +199,13 @@ class MappedTest(ORMTest): if self.run_setup_mappers == 'each': sa.orm.clear_mappers() - - if self.run_deletes: + + # no need to run deletes if tables are recreated on setup + if self.run_define_tables != 'each' and self.run_deletes: for table in self.metadata.table_iterator(reverse=True): try: table.delete().execute().close() - except sa.orm.DBAPIError, ex: + except sa.exc.DBAPIError, ex: print >> sys.stderr, "Error emptying table %s: %r" % ( table, ex) diff --git a/test/orm/_fixtures.py b/test/orm/_fixtures.py index 07367895fe..09fab5dbaa 100644 --- a/test/orm/_fixtures.py +++ b/test/orm/_fixtures.py @@ -242,7 +242,7 @@ class FixtureTest(_base.MappedTest): run_setup_mappers = 'each' run_inserts = 'each' run_deletes = 'each' - + metadata = fixture_metadata fixture_classes = dict(User=User, Order=Order, diff --git a/test/orm/assorted_eager.py b/test/orm/assorted_eager.py index 47247928a8..c8c0f6a723 100644 --- a/test/orm/assorted_eager.py +++ b/test/orm/assorted_eager.py @@ -14,7 +14,9 @@ from orm import _base class EagerTest(_base.MappedTest): - + run_deletes = None + run_inserts = "once" + def define_tables(self, metadata): # determine a literal value for "false" based on the dialect # FIXME: this PassiveDefault setup is bogus. diff --git a/test/orm/cycles.py b/test/orm/cycles.py index d21cd1974b..c92228def7 100644 --- a/test/orm/cycles.py +++ b/test/orm/cycles.py @@ -228,6 +228,7 @@ class InheritTestTwo(_base.MappedTest): could create duplicate entries in the final sort """ + def define_tables(self, metadata): Table('a', metadata, Column('id', Integer, primary_key=True), @@ -273,7 +274,8 @@ class InheritTestTwo(_base.MappedTest): class BiDirectionalManyToOneTest(_base.MappedTest): - + run_define_tables = 'each' + def define_tables(self, metadata): Table('t1', metadata, Column('id', Integer, primary_key=True), @@ -360,6 +362,8 @@ class BiDirectionalManyToOneTest(_base.MappedTest): class BiDirectionalOneToManyTest(_base.MappedTest): """tests two mappers with a one-to-many relation to each other.""" + run_define_tables = 'each' + def define_tables(self, metadata): Table('t1', metadata, Column('c1', Integer, primary_key=True, @@ -407,6 +411,8 @@ class BiDirectionalOneToManyTest(_base.MappedTest): class BiDirectionalOneToManyTest2(_base.MappedTest): """Two mappers with a one-to-many relation to each other, with a second one-to-many on one of the mappers""" + run_define_tables = 'each' + def define_tables(self, metadata): Table('t1', metadata, Column('c1', Integer, primary_key=True), @@ -479,7 +485,8 @@ class OneToManyManyToOneTest(_base.MappedTest): dependencies are sorted. """ - + run_define_tables = 'each' + def define_tables(self, metadata): Table('ball', metadata, Column('id', Integer, primary_key=True, diff --git a/test/orm/memusage.py b/test/orm/memusage.py index 2c431bf461..f9c645c8b3 100644 --- a/test/orm/memusage.py +++ b/test/orm/memusage.py @@ -31,12 +31,9 @@ def profile_memory(func): # if a drop is detected, it's assumed that GC is able # to reduce memory. better methodology would # make this more accurate. - for i, x in enumerate(samples): - if i < len(samples) - 1 and x < samples[i+1]: - continue - else: - return - assert False, repr(samples) + for i in range(len(samples) - 20, len(samples)): + if samples[i] > samples[i-1]: + assert False, repr(samples) + " %d > %d" % (samples[i], samples[i-1]) return profile def assert_no_mappers(): @@ -50,7 +47,18 @@ class EnsureZeroed(_base.ORMTest): _mapper_registry.clear() class MemUsageTest(EnsureZeroed): - + + @testing.fails_if(lambda:True) + def test_fixture(self): + class Foo(object): + pass + + x = [] + @profile_memory + def go(): + x[-1:] = [Foo(), Foo(), Foo(), Foo(), Foo(), Foo()] + go() + def test_session(self): metadata = MetaData(testing.db) diff --git a/test/orm/pickled.py b/test/orm/pickled.py index ecce320a55..a4eadf5a97 100644 --- a/test/orm/pickled.py +++ b/test/orm/pickled.py @@ -9,7 +9,8 @@ from orm import _base, _fixtures User, EmailUser = None, None class PickleTest(_fixtures.FixtureTest): - + run_inserts = None + @testing.resolve_artifact_names def test_transient(self): mapper(User, users, properties={ diff --git a/test/orm/unitofwork.py b/test/orm/unitofwork.py index c722a4cfe0..f9be94c98b 100644 --- a/test/orm/unitofwork.py +++ b/test/orm/unitofwork.py @@ -1061,7 +1061,7 @@ class OneToManyTest(_fixtures.FixtureTest): {'users_id': u2.id, 'name': 'user2modified'}), ("UPDATE addresses SET user_id=:user_id " - "WHERE addresses.id = :email_addresses_id", + "WHERE addresses.id = :addresses_id", {'user_id': None, 'addresses_id': a1.id}), ("UPDATE addresses SET user_id=:user_id " @@ -1473,7 +1473,8 @@ class SaveTest(_fixtures.FixtureTest): class ManyToOneTest(_fixtures.FixtureTest): - + run_inserts = None + @testing.resolve_artifact_names def test_m2o_one_to_one(self): # TODO: put assertion in here !!! @@ -1684,7 +1685,6 @@ class ManyToManyTest(_fixtures.FixtureTest): {'name':'round'}, {'name':'small'}])}] - _fixtures.run_inserts_for(keywords) session = create_session() objects = [] @@ -1855,7 +1855,6 @@ class ManyToManyTest(_fixtures.FixtureTest): mapper(Item, items, properties=dict( keywords=relation(IKAssociation, lazy=False))) - _fixtures.run_inserts_for(keywords) session = create_session() def fixture(): diff --git a/test/testlib/testing.py b/test/testlib/testing.py index 67918c5d4d..e1f8e43502 100644 --- a/test/testlib/testing.py +++ b/test/testlib/testing.py @@ -562,7 +562,7 @@ def resolve_artifact_names(fn): # rebound functions aren't regular Python.. # # Also: it's lame that CPython accepts a dict-subclass for globals, but - # only calls dict methods. Taht would allow 'global' to pass through to + # only calls dict methods. That would allow 'global' to pass through to # the func_globals. def resolved(*args, **kwargs): self = args[0] -- 2.47.3