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()
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)
run_setup_mappers = 'each'
run_inserts = 'each'
run_deletes = 'each'
-
+
metadata = fixture_metadata
fixture_classes = dict(User=User,
Order=Order,
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.
could create duplicate entries in the final sort
"""
+
def define_tables(self, metadata):
Table('a', metadata,
Column('id', Integer, primary_key=True),
class BiDirectionalManyToOneTest(_base.MappedTest):
-
+ run_define_tables = 'each'
+
def define_tables(self, metadata):
Table('t1', metadata,
Column('id', Integer, primary_key=True),
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,
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),
dependencies are sorted.
"""
-
+ run_define_tables = 'each'
+
def define_tables(self, metadata):
Table('ball', metadata,
Column('id', Integer, primary_key=True,
# 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():
_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)
User, EmailUser = None, None
class PickleTest(_fixtures.FixtureTest):
-
+ run_inserts = None
+
@testing.resolve_artifact_names
def test_transient(self):
mapper(User, users, properties={
{'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 "
class ManyToOneTest(_fixtures.FixtureTest):
-
+ run_inserts = None
+
@testing.resolve_artifact_names
def test_m2o_one_to_one(self):
# TODO: put assertion in here !!!
{'name':'round'},
{'name':'small'}])}]
- _fixtures.run_inserts_for(keywords)
session = create_session()
objects = []
mapper(Item, items, properties=dict(
keywords=relation(IKAssociation, lazy=False)))
- _fixtures.run_inserts_for(keywords)
session = create_session()
def fixture():
# 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]