summaryrefslogtreecommitdiff
path: root/test/testlib
diff options
context:
space:
mode:
Diffstat (limited to 'test/testlib')
-rw-r--r--test/testlib/config.py33
-rw-r--r--test/testlib/fixtures.py57
-rw-r--r--test/testlib/orm.py3
-rw-r--r--test/testlib/profiling.py1
-rw-r--r--test/testlib/schema.py3
-rw-r--r--test/testlib/tables.py44
-rw-r--r--test/testlib/testing.py4
7 files changed, 85 insertions, 60 deletions
diff --git a/test/testlib/config.py b/test/testlib/config.py
index 9644c96dc..ac9f39717 100644
--- a/test/testlib/config.py
+++ b/test/testlib/config.py
@@ -1,4 +1,3 @@
-import testbase
import optparse, os, sys, re, ConfigParser, StringIO, time, warnings
logging, require = None, None
@@ -44,6 +43,29 @@ def configure():
return options, file_config
+def configure_defaults():
+ global options, config
+ global getopts_options, file_config
+ global db
+
+ file_config = ConfigParser.ConfigParser()
+ file_config.readfp(StringIO.StringIO(base_config))
+ file_config.read(['test.cfg', os.path.expanduser('~/.satest.cfg')])
+ (options, args) = parser.parse_args([])
+
+ # make error messages raised by decorators that depend on a default
+ # database clearer.
+ class _engine_bomb(object):
+ def __getattr__(self, key):
+ raise RuntimeError('No default engine available, testlib '
+ 'was configured with defaults only.')
+
+ db = _engine_bomb()
+ import testlib.testing
+ testlib.testing.db = db
+
+ return options, file_config
+
def _log(option, opt_str, value, parser):
global logging
if not logging:
@@ -150,7 +172,7 @@ class _ordered_map(object):
def __iter__(self):
for key in self._keys:
yield self._data[key]
-
+
# at one point in refactoring, modules were injecting into the config
# process. this could probably just become a list now.
post_configure = _ordered_map()
@@ -205,9 +227,10 @@ def _engine_pool(options, file_config):
post_configure['engine_pool'] = _engine_pool
def _create_testing_engine(options, file_config):
- from testlib import engines
+ from testlib import engines, testing
global db
db = engines.testing_engine(db_url, db_opts)
+ testing.db = db
post_configure['create_engine'] = _create_testing_engine
def _prep_testing_database(options, file_config):
@@ -242,7 +265,7 @@ post_configure['prep_db'] = _prep_testing_database
def _set_table_options(options, file_config):
import testlib.schema
-
+
table_options = testlib.schema.table_options
for spec in options.tableopts:
key, value = spec.split('=')
@@ -268,7 +291,7 @@ post_configure['topological'] = _reverse_topological
def _set_profile_targets(options, file_config):
from testlib import profiling
-
+
profile_config = profiling.profile_config
for target in options.profile_targets:
diff --git a/test/testlib/fixtures.py b/test/testlib/fixtures.py
index 2a4b457ac..bbd27a39f 100644
--- a/test/testlib/fixtures.py
+++ b/test/testlib/fixtures.py
@@ -1,4 +1,5 @@
-import testbase
+# can't be imported until the path is setup; be sure to configure
+# first if covering.
from sqlalchemy import *
from sqlalchemy import util
from testlib import *
@@ -8,22 +9,22 @@ class Base(object):
def __init__(self, **kwargs):
for k in kwargs:
setattr(self, k, kwargs[k])
-
+
# TODO: add recursion checks to this
def __repr__(self):
return "%s(%s)" % (
- (self.__class__.__name__),
+ (self.__class__.__name__),
','.join(["%s=%s" % (key, repr(getattr(self, key))) for key in self.__dict__ if not key.startswith('_')])
)
-
+
def __ne__(self, other):
return not self.__eq__(other)
-
+
def __eq__(self, other):
"""'passively' compare this object to another.
-
+
only look at attributes that are present on the source object.
-
+
"""
if self in _recursion_stack:
@@ -40,7 +41,7 @@ class Base(object):
else:
a = self
b = other
-
+
for attr in a.__dict__.keys():
if attr[0] == '_':
continue
@@ -75,7 +76,7 @@ class Base(object):
return True
finally:
_recursion_stack.remove(self)
-
+
class User(Base):pass
class Order(Base):pass
class Item(Base):pass
@@ -97,18 +98,18 @@ orders = Table('orders', metadata,
Column('isopen', Integer)
)
-addresses = Table('addresses', metadata,
+addresses = Table('addresses', metadata,
Column('id', Integer, primary_key=True),
Column('user_id', None, ForeignKey('users.id')),
Column('email_address', String(50), nullable=False))
-dingalings = Table("dingalings", metadata,
+dingalings = Table("dingalings", metadata,
Column('id', Integer, primary_key=True),
Column('address_id', None, ForeignKey('addresses.id')),
Column('data', String(30))
)
-
-items = Table('items', metadata,
+
+items = Table('items', metadata,
Column('id', Integer, primary_key=True),
Column('description', String(30), nullable=False)
)
@@ -117,11 +118,11 @@ order_items = Table('order_items', metadata,
Column('item_id', None, ForeignKey('items.id')),
Column('order_id', None, ForeignKey('orders.id')))
-item_keywords = Table('item_keywords', metadata,
+item_keywords = Table('item_keywords', metadata,
Column('item_id', None, ForeignKey('items.id')),
Column('keyword_id', None, ForeignKey('keywords.id')))
-keywords = Table('keywords', metadata,
+keywords = Table('keywords', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(30), nullable=False)
)
@@ -189,7 +190,7 @@ def install_fixture_data():
# this many-to-many table has the keywords inserted
# in primary key order, to appease the unit tests.
- # this is because postgres, oracle, and sqlite all support
+ # this is because postgres, oracle, and sqlite all support
# true insert-order row id, but of course our pal MySQL does not,
# so the best it can do is order by, well something, so there you go.
item_keywords.insert().execute(
@@ -206,35 +207,35 @@ def install_fixture_data():
class FixtureTest(ORMTest):
refresh_data = False
-
+
def setUpAll(self):
super(FixtureTest, self).setUpAll()
if self.keep_data:
install_fixture_data()
-
+
def setUp(self):
if self.refresh_data:
install_fixture_data()
-
+
def define_tables(self, meta):
pass
FixtureTest.metadata = metadata
-
+
class Fixtures(object):
@property
def user_address_result(self):
return [
User(id=7, addresses=[
Address(id=1)
- ]),
+ ]),
User(id=8, addresses=[
Address(id=2, email_address='ed@wood.com'),
Address(id=3, email_address='ed@bettyboop.com'),
Address(id=4, email_address='ed@lala.com'),
- ]),
+ ]),
User(id=9, addresses=[
Address(id=5)
- ]),
+ ]),
User(id=10, addresses=[])
]
@@ -247,18 +248,18 @@ class Fixtures(object):
Order(description='order 1', items=[Item(description='item 1'), Item(description='item 2'), Item(description='item 3')]),
Order(description='order 3'),
Order(description='order 5'),
- ]),
+ ]),
User(id=8, addresses=[
Address(id=2),
Address(id=3),
Address(id=4)
- ]),
+ ]),
User(id=9, addresses=[
Address(id=5)
], orders=[
Order(description='order 2', items=[Item(description='item 1'), Item(description='item 2'), Item(description='item 3')]),
Order(description='order 4', items=[Item(description='item 1'), Item(description='item 5')]),
- ]),
+ ]),
User(id=10, addresses=[])
]
@@ -276,8 +277,8 @@ class Fixtures(object):
Order(id=4, items=[Item(id=1), Item(id=5)]),
]),
User(id=10)
- ]
-
+ ]
+
@property
def item_keyword_result(self):
return [
diff --git a/test/testlib/orm.py b/test/testlib/orm.py
index f7d761b36..9662a4443 100644
--- a/test/testlib/orm.py
+++ b/test/testlib/orm.py
@@ -1,6 +1,5 @@
-import testbase
-from testlib import config
import inspect, re
+from testlib import config
orm = None
__all__ = 'mapper',
diff --git a/test/testlib/profiling.py b/test/testlib/profiling.py
index 61f6bb8f2..ac7ca84d7 100644
--- a/test/testlib/profiling.py
+++ b/test/testlib/profiling.py
@@ -1,6 +1,5 @@
"""Profiling support for unit and performance tests."""
-import testbase
import os, sys
from testlib.config import parser, post_configure
import testlib.config
diff --git a/test/testlib/schema.py b/test/testlib/schema.py
index 8151508d0..152660380 100644
--- a/test/testlib/schema.py
+++ b/test/testlib/schema.py
@@ -1,4 +1,3 @@
-import testbase
from testlib import testing
schema = None
@@ -18,7 +17,7 @@ def Table(*args, **kw):
kw.update(table_options)
- if testbase.db.name == 'mysql':
+ if testing.against('mysql'):
if 'mysql_engine' not in kw and 'mysql_type' not in kw:
if 'test_needs_fk' in test_opts or 'test_needs_acid' in test_opts:
kw['mysql_engine'] = 'InnoDB'
diff --git a/test/testlib/tables.py b/test/testlib/tables.py
index 69c84c5b3..4ec92cc8b 100644
--- a/test/testlib/tables.py
+++ b/test/testlib/tables.py
@@ -1,10 +1,13 @@
-import testbase
+# can't be imported until the path is setup; be sure to configure
+# first if covering.
from sqlalchemy import *
+from testlib import testing
from testlib.schema import Table, Column
-# these are older test fixtures, used primarily by test/orm/mapper.py and test/orm/unitofwork.py.
-# newer unit tests make usage of test/orm/fixtures.py.
+# these are older test fixtures, used primarily by test/orm/mapper.py and
+# test/orm/unitofwork.py. newer unit tests make usage of
+# test/orm/fixtures.py.
metadata = MetaData()
@@ -39,7 +42,7 @@ keywords = Table('keywords', metadata,
Column('name', VARCHAR(50)),
)
-userkeywords = Table('userkeywords', metadata,
+userkeywords = Table('userkeywords', metadata,
Column('user_id', INT, ForeignKey("users")),
Column('keyword_id', INT, ForeignKey("keywords")),
)
@@ -52,18 +55,18 @@ itemkeywords = Table('itemkeywords', metadata,
def create():
if not metadata.bind:
- metadata.bind = testbase.db
+ metadata.bind = testing.db
metadata.create_all()
def drop():
if not metadata.bind:
- metadata.bind = testbase.db
+ metadata.bind = testing.db
metadata.drop_all()
def delete():
for t in metadata.table_iterator(reverse=True):
t.delete().execute()
def user_data():
if not metadata.bind:
- metadata.bind = testbase.db
+ metadata.bind = testing.db
users.insert().execute(
dict(user_id = 7, user_name = 'jack'),
dict(user_id = 8, user_name = 'ed'),
@@ -71,10 +74,10 @@ def user_data():
)
def delete_user_data():
users.delete().execute()
-
+
def data():
delete()
-
+
# with SQLITE, the OID column of a table defaults to the primary key, if it has one.
# so to database-neutrally get rows back in "insert order" based on OID, we
# have to also put the primary keys in order for the purpose of these tests
@@ -112,10 +115,10 @@ def data():
dict(keyword_id=6, name='round'),
dict(keyword_id=7, name='square')
)
-
+
# this many-to-many table has the keywords inserted
# in primary key order, to appease the unit tests.
- # this is because postgres, oracle, and sqlite all support
+ # this is because postgres, oracle, and sqlite all support
# true insert-order row id, but of course our pal MySQL does not,
# so the best it can do is order by, well something, so there you go.
itemkeywords.insert().execute(
@@ -133,7 +136,7 @@ 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] != '_'))
-
+
class User(BaseObject):
def __init__(self):
self.user_id = None
@@ -147,7 +150,7 @@ class Order(BaseObject):
class Item(BaseObject):
pass
-
+
class Keyword(BaseObject):
pass
@@ -159,33 +162,33 @@ user_address_result = [
{'user_id' : 9, 'addresses' : (Address, [])}
]
-user_address_orders_result = [{'user_id' : 7,
+user_address_orders_result = [{'user_id' : 7,
'addresses' : (Address, [{'address_id' : 1}]),
'orders' : (Order, [{'order_id' : 1}, {'order_id' : 3},{'order_id' : 5},])
},
- {'user_id' : 8,
+ {'user_id' : 8,
'addresses' : (Address, [{'address_id' : 2}, {'address_id' : 3}, {'address_id' : 4}]),
'orders' : (Order, [])
},
- {'user_id' : 9,
+ {'user_id' : 9,
'addresses' : (Address, []),
'orders' : (Order, [{'order_id' : 2},{'order_id' : 4}])
}]
user_all_result = [
-{'user_id' : 7,
+{'user_id' : 7,
'addresses' : (Address, [{'address_id' : 1}]),
'orders' : (Order, [
- {'order_id' : 1, 'items': (Item, [])},
+ {'order_id' : 1, 'items': (Item, [])},
{'order_id' : 3, 'items': (Item, [{'item_id':3, 'item_name':'item 3'}, {'item_id':4, 'item_name':'item 4'}, {'item_id':5, 'item_name':'item 5'}])},
{'order_id' : 5, 'items': (Item, [])},
])
},
-{'user_id' : 8,
+{'user_id' : 8,
'addresses' : (Address, [{'address_id' : 2}, {'address_id' : 3}, {'address_id' : 4}]),
'orders' : (Order, [])
},
-{'user_id' : 9,
+{'user_id' : 9,
'addresses' : (Address, []),
'orders' : (Order, [
{'order_id' : 2, 'items': (Item, [{'item_id':1, 'item_name':'item 1'}, {'item_id':2, 'item_name':'item 2'}])},
@@ -215,4 +218,3 @@ order_result = [
{'order_id' : 4, 'items':(Item, [])},
{'order_id' : 5, 'items':(Item, [])},
]
-
diff --git a/test/testlib/testing.py b/test/testlib/testing.py
index 1231dc126..1b5a55f04 100644
--- a/test/testlib/testing.py
+++ b/test/testlib/testing.py
@@ -2,7 +2,6 @@
# monkeypatches unittest.TestLoader.suiteClass at import time
-import testbase
import itertools, unittest, re, sys, os, operator, warnings
from cStringIO import StringIO
import testlib.config as config
@@ -21,6 +20,9 @@ _ops = { '<': operator.lt,
'between': lambda val, pair: val >= pair[0] and val <= pair[1],
}
+# 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.