summaryrefslogtreecommitdiff
path: root/test/ext
diff options
context:
space:
mode:
Diffstat (limited to 'test/ext')
-rw-r--r--test/ext/alltests.py36
-rw-r--r--test/ext/test_associationproxy.py (renamed from test/ext/associationproxy.py)38
-rw-r--r--test/ext/test_compiler.py (renamed from test/ext/compiler.py)5
-rw-r--r--test/ext/test_declarative.py (renamed from test/ext/declarative.py)63
-rw-r--r--test/ext/test_orderinglist.py (renamed from test/ext/orderinglist.py)11
-rw-r--r--test/ext/test_serializer.py (renamed from test/ext/serializer.py)23
6 files changed, 72 insertions, 104 deletions
diff --git a/test/ext/alltests.py b/test/ext/alltests.py
deleted file mode 100644
index 9f5353e04..000000000
--- a/test/ext/alltests.py
+++ /dev/null
@@ -1,36 +0,0 @@
-import testenv; testenv.configure_for_tests()
-import doctest, sys
-
-from testlib import sa_unittest as unittest
-
-
-def suite():
- unittest_modules = (
- 'ext.declarative',
- 'ext.orderinglist',
- 'ext.associationproxy',
- 'ext.serializer',
- 'ext.compiler',
- )
-
- if sys.version_info < (2, 4):
- doctest_modules = ()
- else:
- doctest_modules = (
- ('sqlalchemy.ext.orderinglist', {'optionflags': doctest.ELLIPSIS}),
- ('sqlalchemy.ext.sqlsoup', {})
- )
-
- alltests = unittest.TestSuite()
- for name in unittest_modules:
- mod = __import__(name)
- for token in name.split('.')[1:]:
- mod = getattr(mod, token)
- alltests.addTest(unittest.findTestCases(mod, suiteClass=None))
- for name, opts in doctest_modules:
- alltests.addTest(doctest.DocTestSuite(name, **opts))
- return alltests
-
-
-if __name__ == '__main__':
- testenv.main(suite())
diff --git a/test/ext/associationproxy.py b/test/ext/test_associationproxy.py
index 821ed9072..742f98baf 100644
--- a/test/ext/associationproxy.py
+++ b/test/ext/test_associationproxy.py
@@ -1,10 +1,10 @@
-import testenv; testenv.configure_for_tests()
+from sqlalchemy.test.testing import eq_, assert_raises, assert_raises_message
import gc
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.orm.collections import collection
from sqlalchemy.ext.associationproxy import *
-from testlib import *
+from sqlalchemy.test import *
class DictCollection(dict):
@@ -34,7 +34,7 @@ class ObjectCollection(object):
return iter(self.values)
class _CollectionOperations(TestBase):
- def setUp(self):
+ def setup(self):
collection_class = self.collection_class
metadata = MetaData(testing.db)
@@ -77,7 +77,7 @@ class _CollectionOperations(TestBase):
self.session = create_session()
self.Parent, self.Child = Parent, Child
- def tearDown(self):
+ def teardown(self):
self.metadata.drop_all()
def roundtrip(self, obj):
@@ -189,7 +189,7 @@ class _CollectionOperations(TestBase):
self.assert_(p1.children == after)
self.assert_([c.name for c in p1._children] == after)
- self.assertRaises(TypeError, set, [p1.children])
+ assert_raises(TypeError, set, [p1.children])
p1.children *= 0
after = []
@@ -342,7 +342,7 @@ class CustomDictTest(DictTest):
except TypeError:
self.assert_(True)
- self.assertRaises(TypeError, set, [p1.children])
+ assert_raises(TypeError, set, [p1.children])
class SetTest(_CollectionOperations):
@@ -458,7 +458,7 @@ class SetTest(_CollectionOperations):
except TypeError:
self.assert_(True)
- self.assertRaises(TypeError, set, [p1.children])
+ assert_raises(TypeError, set, [p1.children])
def test_set_comparisons(self):
@@ -473,19 +473,19 @@ class SetTest(_CollectionOperations):
set(['c','d']), set(['e', 'f', 'g']),
set()):
- self.assertEqual(p1.children.union(other),
+ eq_(p1.children.union(other),
control.union(other))
- self.assertEqual(p1.children.difference(other),
+ eq_(p1.children.difference(other),
control.difference(other))
- self.assertEqual((p1.children - other),
+ eq_((p1.children - other),
(control - other))
- self.assertEqual(p1.children.intersection(other),
+ eq_(p1.children.intersection(other),
control.intersection(other))
- self.assertEqual(p1.children.symmetric_difference(other),
+ eq_(p1.children.symmetric_difference(other),
control.symmetric_difference(other))
- self.assertEqual(p1.children.issubset(other),
+ eq_(p1.children.issubset(other),
control.issubset(other))
- self.assertEqual(p1.children.issuperset(other),
+ eq_(p1.children.issuperset(other),
control.issuperset(other))
self.assert_((p1.children == other) == (control == other))
@@ -714,7 +714,7 @@ class ScalarTest(TestBase):
class LazyLoadTest(TestBase):
- def setUp(self):
+ def setup(self):
metadata = MetaData(testing.db)
parents_table = Table('Parent', metadata,
@@ -748,7 +748,7 @@ class LazyLoadTest(TestBase):
self.Parent, self.Child = Parent, Child
self.table = parents_table
- def tearDown(self):
+ def teardown(self):
self.metadata.drop_all()
def roundtrip(self, obj):
@@ -823,7 +823,7 @@ class LazyLoadTest(TestBase):
class ReconstitutionTest(TestBase):
- def setUp(self):
+ def setup(self):
metadata = MetaData(testing.db)
parents = Table('parents', metadata,
Column('id', Integer, primary_key=True,
@@ -852,7 +852,7 @@ class ReconstitutionTest(TestBase):
self.metadata = metadata
self.Parent = Parent
- def tearDown(self):
+ def teardown(self):
self.metadata.drop_all()
def test_weak_identity_map(self):
@@ -883,5 +883,3 @@ class ReconstitutionTest(TestBase):
assert set(p_copy.kids) == set(['c1', 'c2']), p.kids
-if __name__ == "__main__":
- testenv.main()
diff --git a/test/ext/compiler.py b/test/ext/test_compiler.py
index 370ea62ab..ce2549099 100644
--- a/test/ext/compiler.py
+++ b/test/ext/test_compiler.py
@@ -1,9 +1,8 @@
-import testenv; testenv.configure_for_tests()
from sqlalchemy import *
from sqlalchemy.sql.expression import ClauseElement, ColumnClause
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql import table, column
-from testlib import *
+from sqlalchemy.test import *
class UserDefinedTest(TestBase, AssertsCompiledSQL):
@@ -122,5 +121,3 @@ class UserDefinedTest(TestBase, AssertsCompiledSQL):
"DROP THINGY",
)
-if __name__ == '__main__':
- testenv.main()
diff --git a/test/ext/declarative.py b/test/ext/test_declarative.py
index f5130b215..c49c00cec 100644
--- a/test/ext/declarative.py
+++ b/test/ext/test_declarative.py
@@ -1,21 +1,24 @@
-import testenv; testenv.configure_for_tests()
+from sqlalchemy.test.testing import eq_, assert_raises, assert_raises_message
from sqlalchemy.ext import declarative as decl
from sqlalchemy import exc
-from testlib import sa, testing
-from testlib.sa import MetaData, Table, Column, Integer, String, ForeignKey, ForeignKeyConstraint, asc, Index
-from testlib.sa.orm import relation, create_session, class_mapper, eagerload, compile_mappers, backref, clear_mappers, polymorphic_union, deferred
-from testlib.testing import eq_
+import sqlalchemy as sa
+from sqlalchemy.test import testing
+from sqlalchemy import MetaData, Integer, String, ForeignKey, ForeignKeyConstraint, asc, Index
+from sqlalchemy.test.schema import Table
+from sqlalchemy.test.schema import Column
+from sqlalchemy.orm import relation, create_session, class_mapper, eagerload, compile_mappers, backref, clear_mappers, polymorphic_union, deferred
+from sqlalchemy.test.testing import eq_
-from orm._base import ComparableEntity, MappedTest
+from test.orm._base import ComparableEntity, MappedTest
class DeclarativeTestBase(testing.TestBase, testing.AssertsExecutionResults):
- def setUp(self):
+ def setup(self):
global Base
Base = decl.declarative_base(testing.db)
- def tearDown(self):
+ def teardown(self):
clear_mappers()
Base.metadata.drop_all()
@@ -64,7 +67,7 @@ class DeclarativeTest(DeclarativeTestBase):
def go():
class User(Base):
id = Column('id', Integer, primary_key=True)
- self.assertRaisesMessage(sa.exc.InvalidRequestError, "does not have a __table__", go)
+ assert_raises_message(sa.exc.InvalidRequestError, "does not have a __table__", go)
def test_cant_add_columns(self):
t = Table('t', Base.metadata, Column('id', Integer, primary_key=True), Column('data', String))
@@ -73,7 +76,7 @@ class DeclarativeTest(DeclarativeTestBase):
__table__ = t
foo = Column(Integer, primary_key=True)
# can't specify new columns not already in the table
- self.assertRaisesMessage(sa.exc.ArgumentError, "Can't add additional column 'foo' when specifying __table__", go)
+ assert_raises_message(sa.exc.ArgumentError, "Can't add additional column 'foo' when specifying __table__", go)
# regular re-mapping works tho
class Bar(Base):
@@ -144,7 +147,7 @@ class DeclarativeTest(DeclarativeTestBase):
sess.add(u1)
sess.flush()
sess.expunge_all()
- self.assertEquals(sess.query(User).filter(User.name == 'ed').one(),
+ eq_(sess.query(User).filter(User.name == 'ed').one(),
User(name='ed', addresses=[Address(email='xyz'), Address(email='def'), Address(email='abc')])
)
@@ -152,7 +155,7 @@ class DeclarativeTest(DeclarativeTestBase):
__tablename__ = 'foo'
id = Column(Integer, primary_key=True)
rel = relation("User", primaryjoin="User.addresses==Foo.id")
- self.assertRaisesMessage(exc.InvalidRequestError, "'addresses' is not an instance of ColumnProperty", compile_mappers)
+ assert_raises_message(exc.InvalidRequestError, "'addresses' is not an instance of ColumnProperty", compile_mappers)
def test_string_dependency_resolution_in_backref(self):
class User(Base, ComparableEntity):
@@ -206,7 +209,7 @@ class DeclarativeTest(DeclarativeTestBase):
sess.add(u1)
sess.flush()
sess.expunge_all()
- self.assertEquals(sess.query(User).filter(User.name == 'ed').one(),
+ eq_(sess.query(User).filter(User.name == 'ed').one(),
User(name='ed', addresses=[Address(email='abc'), Address(email='def'), Address(email='xyz')])
)
@@ -224,7 +227,7 @@ class DeclarativeTest(DeclarativeTestBase):
# this used to raise an error when accessing User.id but that's no longer the case
# since we got rid of _CompileOnAttr.
- self.assertRaises(sa.exc.ArgumentError, compile_mappers)
+ assert_raises(sa.exc.ArgumentError, compile_mappers)
def test_nice_dependency_error_works_with_hasattr(self):
class User(Base):
@@ -235,7 +238,7 @@ class DeclarativeTest(DeclarativeTestBase):
# hasattr() on a compile-loaded attribute
hasattr(User.addresses, 'property')
# the exeption is preserved
- self.assertRaisesMessage(sa.exc.InvalidRequestError, r"suppressed within a hasattr\(\)", compile_mappers)
+ assert_raises_message(sa.exc.InvalidRequestError, r"suppressed within a hasattr\(\)", compile_mappers)
def test_custom_base(self):
class MyBase(object):
@@ -255,7 +258,7 @@ class DeclarativeTest(DeclarativeTestBase):
i = Index('my_index', User.name)
# compile fails due to the nonexistent Addresses relation
- self.assertRaises(sa.exc.InvalidRequestError, compile_mappers)
+ assert_raises(sa.exc.InvalidRequestError, compile_mappers)
# index configured
assert i in User.__table__.indexes
@@ -440,7 +443,7 @@ class DeclarativeTest(DeclarativeTestBase):
id = Column('id', Integer, primary_key=True),
name = Column('name', String(50))
assert False
- self.assertRaisesMessage(
+ assert_raises_message(
sa.exc.ArgumentError,
"Mapper Mapper|User|users could not assemble any primary key",
define)
@@ -1204,7 +1207,7 @@ class DeclarativeInheritanceTest(DeclarativeTestBase):
__mapper_args__ = {'polymorphic_identity':'engineer'}
primary_language = Column('primary_language', String(50))
foo_bar = Column(Integer, primary_key=True)
- self.assertRaisesMessage(sa.exc.ArgumentError, "place primary key", go)
+ assert_raises_message(sa.exc.ArgumentError, "place primary key", go)
def test_single_no_table_args(self):
class Person(Base, ComparableEntity):
@@ -1219,7 +1222,7 @@ class DeclarativeInheritanceTest(DeclarativeTestBase):
__mapper_args__ = {'polymorphic_identity':'engineer'}
primary_language = Column('primary_language', String(50))
__table_args__ = ()
- self.assertRaisesMessage(sa.exc.ArgumentError, "place __table_args__", go)
+ assert_raises_message(sa.exc.ArgumentError, "place __table_args__", go)
def test_concrete(self):
engineers = Table('engineers', Base.metadata,
@@ -1270,10 +1273,11 @@ class DeclarativeInheritanceTest(DeclarativeTestBase):
)
-def produce_test(inline, stringbased):
+def _produce_test(inline, stringbased):
class ExplicitJoinTest(MappedTest):
- def define_tables(self, metadata):
+ @classmethod
+ def define_tables(cls, metadata):
global User, Address
Base = decl.declarative_base(metadata=metadata)
@@ -1300,7 +1304,8 @@ def produce_test(inline, stringbased):
else:
Address.user = relation(User, primaryjoin=User.id==Address.user_id, backref="addresses")
- def insert_data(self):
+ @classmethod
+ def insert_data(cls):
params = [dict(zip(('id', 'name'), column_values)) for column_values in
[(7, 'jack'),
(8, 'ed'),
@@ -1337,12 +1342,13 @@ def produce_test(inline, stringbased):
for inline in (True, False):
for stringbased in (True, False):
- testclass = produce_test(inline, stringbased)
+ testclass = _produce_test(inline, stringbased)
exec("%s = testclass" % testclass.__name__)
del testclass
class DeclarativeReflectionTest(testing.TestBase):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global reflection_metadata
reflection_metadata = MetaData(testing.db)
@@ -1364,15 +1370,16 @@ class DeclarativeReflectionTest(testing.TestBase):
reflection_metadata.create_all()
- def setUp(self):
+ def setup(self):
global Base
Base = decl.declarative_base(testing.db)
- def tearDown(self):
+ def teardown(self):
for t in reversed(reflection_metadata.sorted_tables):
t.delete().execute()
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
reflection_metadata.drop_all()
def test_basic(self):
@@ -1436,7 +1443,7 @@ class DeclarativeReflectionTest(testing.TestBase):
eq_(a1, Address(email='two'))
eq_(a1.user, User(nom='u1'))
- self.assertRaises(TypeError, User, name='u3')
+ assert_raises(TypeError, User, name='u3')
def test_supplied_fk(self):
meta = MetaData(testing.db)
diff --git a/test/ext/orderinglist.py b/test/ext/test_orderinglist.py
index c111a02de..4adc77960 100644
--- a/test/ext/orderinglist.py
+++ b/test/ext/test_orderinglist.py
@@ -1,9 +1,8 @@
-import testenv; testenv.configure_for_tests()
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.orderinglist import *
-from testlib.testing import eq_
-from testlib import *
+from sqlalchemy.test.testing import eq_
+from sqlalchemy.test import *
metadata = None
@@ -39,7 +38,7 @@ def alpha_ordering(index, collection):
return s
class OrderingListTest(TestBase):
- def setUp(self):
+ def setup(self):
global metadata, slides_table, bullets_table, Slide, Bullet
slides_table, bullets_table = None, None
Slide, Bullet = None, None
@@ -87,7 +86,7 @@ class OrderingListTest(TestBase):
metadata.create_all()
- def tearDown(self):
+ def teardown(self):
metadata.drop_all()
def test_append_no_reorder(self):
@@ -399,5 +398,3 @@ class OrderingListTest(TestBase):
self.assert_(alpha[li].position == pos)
-if __name__ == "__main__":
- testenv.main()
diff --git a/test/ext/serializer.py b/test/ext/test_serializer.py
index 048eccdfd..b8a8e3fef 100644
--- a/test/ext/serializer.py
+++ b/test/ext/test_serializer.py
@@ -1,13 +1,15 @@
-import testenv; testenv.configure_for_tests()
from sqlalchemy.ext import serializer
from sqlalchemy import exc
-from testlib import sa, testing
-from testlib.sa import MetaData, Table, Column, Integer, String, ForeignKey, select, desc, func, util
-from testlib.sa.orm import relation, sessionmaker, scoped_session, class_mapper, mapper, eagerload, compile_mappers, aliased
-from testlib.testing import eq_
+import sqlalchemy as sa
+from sqlalchemy.test import testing
+from sqlalchemy import MetaData, Integer, String, ForeignKey, select, desc, func, util
+from sqlalchemy.test.schema import Table
+from sqlalchemy.test.schema import Column
+from sqlalchemy.orm import relation, sessionmaker, scoped_session, class_mapper, mapper, eagerload, compile_mappers, aliased
+from sqlalchemy.test.testing import eq_
-from orm._base import ComparableEntity, MappedTest
+from test.orm._base import ComparableEntity, MappedTest
class User(ComparableEntity):
@@ -21,7 +23,8 @@ class SerializeTest(MappedTest):
run_inserts = 'once'
run_deletes = None
- def define_tables(self, metadata):
+ @classmethod
+ def define_tables(cls, metadata):
global users, addresses
users = Table('users', metadata,
Column('id', Integer, primary_key=True),
@@ -33,7 +36,8 @@ class SerializeTest(MappedTest):
Column('user_id', Integer, ForeignKey('users.id')),
)
- def setup_mappers(self):
+ @classmethod
+ def setup_mappers(cls):
global Session
Session = scoped_session(sessionmaker())
@@ -44,7 +48,8 @@ class SerializeTest(MappedTest):
compile_mappers()
- def insert_data(self):
+ @classmethod
+ def insert_data(cls):
params = [dict(zip(('id', 'name'), column_values)) for column_values in
[(7, 'jack'),
(8, 'ed'),