summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2009-06-10 21:18:24 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2009-06-10 21:18:24 +0000
commit45cec095b4904ba71425d2fe18c143982dd08f43 (patch)
treeaf5e540fdcbf1cb2a3337157d69d4b40be010fa8 /test/sql
parent698a3c1ac665e7cd2ef8d5ad3ebf51b7fe6661f4 (diff)
downloadsqlalchemy-45cec095b4904ba71425d2fe18c143982dd08f43.tar.gz
- unit tests have been migrated from unittest to nose.
See README.unittests for information on how to run the tests. [ticket:970]
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/_base.py2
-rw-r--r--test/sql/alltests.py38
-rw-r--r--test/sql/test_case_statement.py (renamed from test/sql/case_statement.py)14
-rw-r--r--test/sql/test_columns.py (renamed from test/sql/columns.py)12
-rw-r--r--test/sql/test_constraints.py (renamed from test/sql/constraints.py)22
-rw-r--r--test/sql/test_defaults.py (renamed from test/sql/defaults.py)43
-rw-r--r--test/sql/test_functions.py (renamed from test/sql/functions.py)12
-rw-r--r--test/sql/test_generative.py (renamed from test/sql/generative.py)23
-rw-r--r--test/sql/test_labels.py (renamed from test/sql/labels.py)22
-rw-r--r--test/sql/test_query.py (renamed from test/sql/query.py)136
-rw-r--r--test/sql/test_quote.py (renamed from test/sql/quote.py)13
-rw-r--r--test/sql/test_rowcount.py (renamed from test/sql/rowcount.py)15
-rw-r--r--test/sql/test_select.py (renamed from test/sql/select.py)28
-rw-r--r--[-rwxr-xr-x]test/sql/test_selectable.py (renamed from test/sql/selectable.py)22
-rw-r--r--test/sql/test_types.py (renamed from test/sql/testtypes.py)108
-rw-r--r--test/sql/test_unicode.py (renamed from test/sql/unicode.py)15
16 files changed, 252 insertions, 273 deletions
diff --git a/test/sql/_base.py b/test/sql/_base.py
index c1a107eeb..48879ae7e 100644
--- a/test/sql/_base.py
+++ b/test/sql/_base.py
@@ -1,4 +1,4 @@
-from engine import _base as engine_base
+from test.engine import _base as engine_base
TablesTest = engine_base.TablesTest
diff --git a/test/sql/alltests.py b/test/sql/alltests.py
deleted file mode 100644
index f01b0e620..000000000
--- a/test/sql/alltests.py
+++ /dev/null
@@ -1,38 +0,0 @@
-import testenv; testenv.configure_for_tests()
-from testlib import sa_unittest as unittest
-
-
-def suite():
- modules_to_test = (
- 'sql.testtypes',
- 'sql.columns',
- 'sql.constraints',
-
- 'sql.generative',
-
- # SQL syntax
- 'sql.select',
- 'sql.selectable',
- 'sql.case_statement',
- 'sql.labels',
- 'sql.unicode',
-
- # assorted round-trip tests
- 'sql.functions',
- 'sql.query',
- 'sql.quote',
- 'sql.rowcount',
-
- # defaults, sequences (postgres/oracle)
- 'sql.defaults',
- )
- alltests = unittest.TestSuite()
- for name in modules_to_test:
- mod = __import__(name)
- for token in name.split('.')[1:]:
- mod = getattr(mod, token)
- alltests.addTest(unittest.findTestCases(mod, suiteClass=None))
- return alltests
-
-if __name__ == '__main__':
- testenv.main(suite())
diff --git a/test/sql/case_statement.py b/test/sql/test_case_statement.py
index 1d5383749..3f3abe7e1 100644
--- a/test/sql/case_statement.py
+++ b/test/sql/test_case_statement.py
@@ -1,14 +1,15 @@
-import testenv; testenv.configure_for_tests()
+from sqlalchemy.test.testing import assert_raises, assert_raises_message
import sys
from sqlalchemy import *
-from testlib import *
+from sqlalchemy.test import *
from sqlalchemy import util, exc
from sqlalchemy.sql import table, column
class CaseTest(TestBase, AssertsCompiledSQL):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
metadata = MetaData(testing.db)
global info_table
info_table = Table('infos', metadata,
@@ -24,7 +25,8 @@ class CaseTest(TestBase, AssertsCompiledSQL):
{'pk':4, 'info':'pk_4_data'},
{'pk':5, 'info':'pk_5_data'},
{'pk':6, 'info':'pk_6_data'})
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
info_table.drop()
@testing.fails_on('firebird', 'FIXME: unknown')
@@ -93,7 +95,7 @@ class CaseTest(TestBase, AssertsCompiledSQL):
def test_literal_interpretation(self):
t = table('test', column('col1'))
- self.assertRaises(exc.ArgumentError, case, [("x", "y")])
+ assert_raises(exc.ArgumentError, case, [("x", "y")])
self.assert_compile(case([("x", "y")], value=t.c.col1), "CASE test.col1 WHEN :param_1 THEN :param_2 END")
self.assert_compile(case([(t.c.col1==7, "y")], else_="z"), "CASE WHEN (test.col1 = :col1_1) THEN :param_1 ELSE :param_2 END")
@@ -133,5 +135,3 @@ class CaseTest(TestBase, AssertsCompiledSQL):
('other', 3),
]
-if __name__ == "__main__":
- testenv.main()
diff --git a/test/sql/columns.py b/test/sql/test_columns.py
index 661be891a..e9dabe142 100644
--- a/test/sql/columns.py
+++ b/test/sql/test_columns.py
@@ -1,7 +1,7 @@
-import testenv; testenv.configure_for_tests()
+from sqlalchemy.test.testing import assert_raises, assert_raises_message
from sqlalchemy import *
from sqlalchemy import exc, sql
-from testlib import *
+from sqlalchemy.test import *
from sqlalchemy import Table, Column # don't use testlib's wrappers
@@ -37,7 +37,7 @@ class ColumnDefinitionTest(TestBase):
def test_incomplete(self):
c = self.columns()
- self.assertRaises(exc.ArgumentError, Table, 't', MetaData(), *c)
+ assert_raises(exc.ArgumentError, Table, 't', MetaData(), *c)
def test_incomplete_key(self):
c = Column(Integer)
@@ -52,9 +52,7 @@ class ColumnDefinitionTest(TestBase):
def test_bogus(self):
- self.assertRaises(exc.ArgumentError, Column, 'foo', name='bar')
- self.assertRaises(exc.ArgumentError, Column, 'foo', Integer,
+ assert_raises(exc.ArgumentError, Column, 'foo', name='bar')
+ assert_raises(exc.ArgumentError, Column, 'foo', Integer,
type_=Integer())
-if __name__ == "__main__":
- testenv.main()
diff --git a/test/sql/constraints.py b/test/sql/test_constraints.py
index d019aa037..8abeb3533 100644
--- a/test/sql/constraints.py
+++ b/test/sql/test_constraints.py
@@ -1,16 +1,16 @@
-import testenv; testenv.configure_for_tests()
+from sqlalchemy.test.testing import eq_, assert_raises, assert_raises_message
from sqlalchemy import *
from sqlalchemy import exc
-from testlib import *
-from testlib import config, engines
+from sqlalchemy.test import *
+from sqlalchemy.test import config, engines
class ConstraintTest(TestBase, AssertsExecutionResults):
- def setUp(self):
+ def setup(self):
global metadata
metadata = MetaData(testing.db)
- def tearDown(self):
+ def teardown(self):
metadata.drop_all()
def test_constraint(self):
@@ -33,7 +33,7 @@ class ConstraintTest(TestBase, AssertsExecutionResults):
def test_double_fk_usage_raises(self):
f = ForeignKey('b.id')
- self.assertRaises(exc.InvalidRequestError, Table, "a", metadata,
+ assert_raises(exc.InvalidRequestError, Table, "a", metadata,
Column('x', Integer, f),
Column('y', Integer, f)
)
@@ -219,14 +219,14 @@ class ConstraintTest(TestBase, AssertsExecutionResults):
t1 = Table("sometable", MetaData(), Column("foo", Integer))
schemagen.visit_index(Index("this_name_is_too_long_for_what_were_doing", t1.c.foo))
- self.assertEquals(schemagen.buffer.getvalue(), "CREATE INDEX this_name_is_t_1 ON sometable (foo)")
+ eq_(schemagen.buffer.getvalue(), "CREATE INDEX this_name_is_t_1 ON sometable (foo)")
schemagen.buffer.truncate(0)
schemagen.visit_index(Index("this_other_name_is_too_long_for_what_were_doing", t1.c.foo))
- self.assertEquals(schemagen.buffer.getvalue(), "CREATE INDEX this_other_nam_2 ON sometable (foo)")
+ eq_(schemagen.buffer.getvalue(), "CREATE INDEX this_other_nam_2 ON sometable (foo)")
schemadrop = dialect.schemadropper(dialect, None)
schemadrop.execute = lambda: None
- self.assertRaises(exc.IdentifierError, schemadrop.visit_index, Index("this_name_is_too_long_for_what_were_doing", t1.c.foo))
+ assert_raises(exc.IdentifierError, schemadrop.visit_index, Index("this_name_is_too_long_for_what_were_doing", t1.c.foo))
class ConstraintCompilationTest(TestBase, AssertsExecutionResults):
@@ -245,7 +245,7 @@ class ConstraintCompilationTest(TestBase, AssertsExecutionResults):
def clear(self):
del self.statements[:]
- def setUp(self):
+ def setup(self):
self.sql = self.accum()
opts = config.db_opts.copy()
opts['strategy'] = 'mock'
@@ -333,5 +333,3 @@ class ConstraintCompilationTest(TestBase, AssertsExecutionResults):
assert 'INITIALLY DEFERRED' in self.sql, self.sql
-if __name__ == "__main__":
- testenv.main()
diff --git a/test/sql/defaults.py b/test/sql/test_defaults.py
index bea6dc04b..964157466 100644
--- a/test/sql/defaults.py
+++ b/test/sql/test_defaults.py
@@ -1,16 +1,19 @@
-import testenv; testenv.configure_for_tests()
+from sqlalchemy.test.testing import eq_, assert_raises, assert_raises_message
import datetime
from sqlalchemy import Sequence, Column, func
from sqlalchemy.sql import select, text
-from testlib import sa, testing
-from testlib.sa import MetaData, Table, Integer, String, ForeignKey, Boolean
-from testlib.testing import eq_
-from sql import _base
+import sqlalchemy as sa
+from sqlalchemy.test import testing
+from sqlalchemy import MetaData, Integer, String, ForeignKey, Boolean
+from sqlalchemy.test.schema import Table
+from sqlalchemy.test.testing import eq_
+from test.sql import _base
class DefaultTest(testing.TestBase):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global t, f, f2, ts, currenttime, metadata, default_generator
db = testing.db
@@ -117,10 +120,11 @@ class DefaultTest(testing.TestBase):
server_default='ddl'))
t.create()
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
t.drop()
- def tearDown(self):
+ def teardown(self):
default_generator['x'] = 50
t.delete().execute()
@@ -139,7 +143,7 @@ class DefaultTest(testing.TestBase):
fn4 = FN4()
for fn in fn1, fn2, fn3, fn4:
- self.assertRaisesMessage(sa.exc.ArgumentError,
+ assert_raises_message(sa.exc.ArgumentError,
ex_msg,
sa.ColumnDefault, fn)
@@ -387,7 +391,8 @@ class DefaultTest(testing.TestBase):
class PKDefaultTest(_base.TablesTest):
__requires__ = ('subqueries',)
- def define_tables(self, metadata):
+ @classmethod
+ def define_tables(cls, metadata):
t2 = Table('t2', metadata,
Column('nextid', Integer))
@@ -411,7 +416,8 @@ class PKDefaultTest(_base.TablesTest):
class PKIncrementTest(_base.TablesTest):
run_define_tables = 'each'
- def define_tables(self, metadata):
+ @classmethod
+ def define_tables(cls, metadata):
Table("aitable", metadata,
Column('id', Integer, Sequence('ai_id_seq', optional=True),
primary_key=True),
@@ -484,8 +490,8 @@ class EmptyInsertTest(testing.TestBase):
try:
result = t1.insert().execute()
- self.assertEquals(1, select([func.count(text('*'))], from_obj=t1).scalar())
- self.assertEquals(True, t1.select().scalar())
+ eq_(1, select([func.count(text('*'))], from_obj=t1).scalar())
+ eq_(True, t1.select().scalar())
finally:
metadata.drop_all()
@@ -493,7 +499,8 @@ class AutoIncrementTest(_base.TablesTest):
__requires__ = ('identity',)
run_define_tables = 'each'
- def define_tables(self, metadata):
+ @classmethod
+ def define_tables(cls, metadata):
"""Each test manipulates self.metadata individually."""
@testing.exclude('sqlite', '<', (3, 4), 'no database support')
@@ -542,7 +549,8 @@ class AutoIncrementTest(_base.TablesTest):
class SequenceTest(testing.TestBase):
__requires__ = ('sequences',)
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global cartitems, sometable, metadata
metadata = MetaData(testing.db)
cartitems = Table("cartitems", metadata,
@@ -626,9 +634,8 @@ class SequenceTest(testing.TestBase):
x = cartitems.c.cart_id.sequence.execute()
self.assert_(1 <= x <= 4)
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
metadata.drop_all()
-if __name__ == "__main__":
- testenv.main()
diff --git a/test/sql/functions.py b/test/sql/test_functions.py
index 17d8a35e9..e9bf49ce3 100644
--- a/test/sql/functions.py
+++ b/test/sql/test_functions.py
@@ -1,15 +1,15 @@
-import testenv; testenv.configure_for_tests()
+from sqlalchemy.test.testing import eq_
import datetime
from sqlalchemy import *
from sqlalchemy.sql import table, column
from sqlalchemy import databases, sql, util
from sqlalchemy.sql.compiler import BIND_TEMPLATES
from sqlalchemy.engine import default
-from testlib.engines import all_dialects
+from sqlalchemy.test.engines import all_dialects
from sqlalchemy import types as sqltypes
-from testlib import *
+from sqlalchemy.test import *
from sqlalchemy.sql.functions import GenericFunction
-from testlib.testing import eq_
+from sqlalchemy.test.testing import eq_
from decimal import Decimal as _python_Decimal
from sqlalchemy.databases import *
@@ -237,7 +237,7 @@ class ExecuteTest(TestBase):
t2.insert(values=dict(value=func.length("asfda") + -19)).execute(stuff="hi")
res = exec_sorted(select([t2.c.value, t2.c.stuff]))
- self.assertEquals(res, [(-14, 'hi'), (3, None), (7, None)])
+ eq_(res, [(-14, 'hi'), (3, None), (7, None)])
t2.update(values=dict(value=func.length("asdsafasd"))).execute(stuff="some stuff")
assert select([t2.c.value, t2.c.stuff]).execute().fetchall() == [(9,"some stuff"), (9,"some stuff"), (9,"some stuff")]
@@ -315,5 +315,3 @@ def exec_sorted(statement, *args, **kw):
return sorted([tuple(row)
for row in statement.execute(*args, **kw).fetchall()])
-if __name__ == '__main__':
- testenv.main()
diff --git a/test/sql/generative.py b/test/sql/test_generative.py
index 3947a450f..ca427ca5f 100644
--- a/test/sql/generative.py
+++ b/test/sql/test_generative.py
@@ -1,8 +1,7 @@
-import testenv; testenv.configure_for_tests()
from sqlalchemy import *
from sqlalchemy.sql import table, column, ClauseElement
from sqlalchemy.sql.expression import _clone, _from_objects
-from testlib import *
+from sqlalchemy.test import *
from sqlalchemy.sql.visitors import *
from sqlalchemy import util
from sqlalchemy.sql import util as sql_util
@@ -12,7 +11,8 @@ class TraversalTest(TestBase, AssertsExecutionResults):
"""test ClauseVisitor's traversal, particularly its ability to copy and modify
a ClauseElement in place."""
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global A, B
# establish two ficticious ClauseElements.
@@ -162,7 +162,8 @@ class TraversalTest(TestBase, AssertsExecutionResults):
class ClauseTest(TestBase, AssertsCompiledSQL):
"""test copy-in-place behavior of various ClauseElements."""
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global t1, t2
t1 = table("table1",
column("col1"),
@@ -361,7 +362,8 @@ class ClauseTest(TestBase, AssertsCompiledSQL):
self.assert_compile(s2, "SELECT 1 FROM (SELECT table1.col1 AS col1, table1.col2 AS col2, table1.col3 AS col3 FROM table1 WHERE table1.col1 = :col1_1) AS anon_1 WHERE table1.col1 = anon_1.col1")
class ClauseAdapterTest(TestBase, AssertsCompiledSQL):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global t1, t2
t1 = table("table1",
column("col1"),
@@ -630,7 +632,8 @@ class ClauseAdapterTest(TestBase, AssertsCompiledSQL):
)
class SpliceJoinsTest(TestBase, AssertsCompiledSQL):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global table1, table2, table3, table4
def _table(name):
return table(name, column("col1"), column("col2"),column("col3"))
@@ -691,7 +694,8 @@ class SpliceJoinsTest(TestBase, AssertsCompiledSQL):
class SelectTest(TestBase, AssertsCompiledSQL):
"""tests the generative capability of Select"""
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global t1, t2
t1 = table("table1",
column("col1"),
@@ -772,7 +776,8 @@ class InsertTest(TestBase, AssertsCompiledSQL):
# fixme: consolidate converage from elsewhere here and expand
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global t1, t2
t1 = table("table1",
column("col1"),
@@ -811,5 +816,3 @@ class InsertTest(TestBase, AssertsCompiledSQL):
"table1 (col1, col2, col3) "
"VALUES (:col1, :col2, :col3)")
-if __name__ == '__main__':
- testenv.main()
diff --git a/test/sql/labels.py b/test/sql/test_labels.py
index 94ee20342..b946b0ae9 100644
--- a/test/sql/labels.py
+++ b/test/sql/test_labels.py
@@ -1,7 +1,7 @@
-import testenv; testenv.configure_for_tests()
+from sqlalchemy.test.testing import assert_raises, assert_raises_message
from sqlalchemy import *
from sqlalchemy import exc as exceptions
-from testlib import *
+from sqlalchemy.test import *
from sqlalchemy.engine import default
IDENT_LENGTH = 29
@@ -16,7 +16,8 @@ class LabelTypeTest(TestBase):
assert isinstance(select([t.c.col2]).as_scalar().label('lala').type, Float)
class LongLabelsTest(TestBase, AssertsCompiledSQL):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global metadata, table1, table2, maxlen
metadata = MetaData(testing.db)
table1 = Table("some_large_named_table", metadata,
@@ -34,20 +35,21 @@ class LongLabelsTest(TestBase, AssertsCompiledSQL):
maxlen = testing.db.dialect.max_identifier_length
testing.db.dialect.max_identifier_length = IDENT_LENGTH
- def tearDown(self):
+ def teardown(self):
table1.delete().execute()
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
metadata.drop_all()
testing.db.dialect.max_identifier_length = maxlen
def test_too_long_name_disallowed(self):
m = MetaData(testing.db)
t1 = Table("this_name_is_too_long_for_what_were_doing_in_this_test", m, Column('foo', Integer))
- self.assertRaises(exceptions.IdentifierError, m.create_all)
- self.assertRaises(exceptions.IdentifierError, m.drop_all)
- self.assertRaises(exceptions.IdentifierError, t1.create)
- self.assertRaises(exceptions.IdentifierError, t1.drop)
+ assert_raises(exceptions.IdentifierError, m.create_all)
+ assert_raises(exceptions.IdentifierError, m.drop_all)
+ assert_raises(exceptions.IdentifierError, t1.create)
+ assert_raises(exceptions.IdentifierError, t1.drop)
def test_result(self):
table1.insert().execute(**{"this_is_the_primarykey_column":1, "this_is_the_data_column":"data1"})
@@ -191,5 +193,3 @@ class LongLabelsTest(TestBase, AssertsCompiledSQL):
"FROM some_large_named_table WHERE some_large_named_table.this_is_the_primarykey_column = :_1) AS _1", dialect=compile_dialect)
-if __name__ == '__main__':
- testenv.main()
diff --git a/test/sql/query.py b/test/sql/test_query.py
index b428d8991..c9305b615 100644
--- a/test/sql/query.py
+++ b/test/sql/test_query.py
@@ -1,14 +1,14 @@
-import testenv; testenv.configure_for_tests()
import datetime
from sqlalchemy import *
from sqlalchemy import exc, sql
from sqlalchemy.engine import default
-from testlib import *
-from testlib.testing import eq_
+from sqlalchemy.test import *
+from sqlalchemy.test.testing import eq_
class QueryTest(TestBase):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global users, users2, addresses, metadata
metadata = MetaData(testing.db)
users = Table('query_users', metadata,
@@ -31,7 +31,8 @@ class QueryTest(TestBase):
users.delete().execute()
users2.delete().execute()
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
metadata.drop_all()
def test_insert(self):
@@ -174,19 +175,19 @@ class QueryTest(TestBase):
)
concat = ("test: " + users.c.user_name).label('thedata')
- self.assertEquals(
+ eq_(
select([concat]).order_by(concat).execute().fetchall(),
[("test: ed",), ("test: fred",), ("test: jack",)]
)
concat = ("test: " + users.c.user_name).label('thedata')
- self.assertEquals(
+ eq_(
select([concat]).order_by(desc(concat)).execute().fetchall(),
[("test: jack",), ("test: fred",), ("test: ed",)]
)
concat = ("test: " + users.c.user_name).label('thedata')
- self.assertEquals(
+ eq_(
select([concat]).order_by(concat + "x").execute().fetchall(),
[("test: ed",), ("test: fred",), ("test: jack",)]
)
@@ -211,11 +212,11 @@ class QueryTest(TestBase):
def test_or_and_as_columns(self):
true, false = literal(True), literal(False)
- self.assertEquals(testing.db.execute(select([and_(true, false)])).scalar(), False)
- self.assertEquals(testing.db.execute(select([and_(true, true)])).scalar(), True)
- self.assertEquals(testing.db.execute(select([or_(true, false)])).scalar(), True)
- self.assertEquals(testing.db.execute(select([or_(false, false)])).scalar(), False)
- self.assertEquals(testing.db.execute(select([not_(or_(false, false))])).scalar(), True)
+ eq_(testing.db.execute(select([and_(true, false)])).scalar(), False)
+ eq_(testing.db.execute(select([and_(true, true)])).scalar(), True)
+ eq_(testing.db.execute(select([or_(true, false)])).scalar(), True)
+ eq_(testing.db.execute(select([or_(false, false)])).scalar(), False)
+ eq_(testing.db.execute(select([not_(or_(false, false))])).scalar(), True)
row = testing.db.execute(select([or_(false, false).label("x"), and_(true, false).label("y")])).fetchone()
assert row.x == False
@@ -272,13 +273,13 @@ class QueryTest(TestBase):
{'user_id':4, 'user_name':'OnE'},
)
- self.assertEquals(select([users.c.user_id]).where(users.c.user_name.ilike('one')).execute().fetchall(), [(1, ), (3, ), (4, )])
+ eq_(select([users.c.user_id]).where(users.c.user_name.ilike('one')).execute().fetchall(), [(1, ), (3, ), (4, )])
- self.assertEquals(select([users.c.user_id]).where(users.c.user_name.ilike('TWO')).execute().fetchall(), [(2, )])
+ eq_(select([users.c.user_id]).where(users.c.user_name.ilike('TWO')).execute().fetchall(), [(2, )])
if testing.against('postgres'):
- self.assertEquals(select([users.c.user_id]).where(users.c.user_name.like('one')).execute().fetchall(), [(1, )])
- self.assertEquals(select([users.c.user_id]).where(users.c.user_name.like('TWO')).execute().fetchall(), [])
+ eq_(select([users.c.user_id]).where(users.c.user_name.like('one')).execute().fetchall(), [(1, )])
+ eq_(select([users.c.user_id]).where(users.c.user_name.like('TWO')).execute().fetchall(), [])
def test_compiled_execute(self):
@@ -388,7 +389,7 @@ class QueryTest(TestBase):
def a_eq(executable, wanted):
got = list(executable.execute())
- self.assertEquals(got, wanted)
+ eq_(got, wanted)
for labels in False, True:
a_eq(users.select(order_by=[users.c.user_id],
@@ -511,23 +512,23 @@ class QueryTest(TestBase):
def test_keys(self):
users.insert().execute(user_id=1, user_name='foo')
r = users.select().execute().fetchone()
- self.assertEqual([x.lower() for x in r.keys()], ['user_id', 'user_name'])
+ eq_([x.lower() for x in r.keys()], ['user_id', 'user_name'])
def test_items(self):
users.insert().execute(user_id=1, user_name='foo')
r = users.select().execute().fetchone()
- self.assertEqual([(x[0].lower(), x[1]) for x in r.items()], [('user_id', 1), ('user_name', 'foo')])
+ eq_([(x[0].lower(), x[1]) for x in r.items()], [('user_id', 1), ('user_name', 'foo')])
def test_len(self):
users.insert().execute(user_id=1, user_name='foo')
r = users.select().execute().fetchone()
- self.assertEqual(len(r), 2)
+ eq_(len(r), 2)
r.close()
r = testing.db.execute('select user_name, user_id from query_users').fetchone()
- self.assertEqual(len(r), 2)
+ eq_(len(r), 2)
r.close()
r = testing.db.execute('select user_name from query_users').fetchone()
- self.assertEqual(len(r), 1)
+ eq_(len(r), 1)
r.close()
def test_cant_execute_join(self):
@@ -542,19 +543,19 @@ class QueryTest(TestBase):
# should return values in column definition order
users.insert().execute(user_id=1, user_name='foo')
r = users.select(users.c.user_id==1).execute().fetchone()
- self.assertEqual(r[0], 1)
- self.assertEqual(r[1], 'foo')
- self.assertEqual([x.lower() for x in r.keys()], ['user_id', 'user_name'])
- self.assertEqual(r.values(), [1, 'foo'])
+ eq_(r[0], 1)
+ eq_(r[1], 'foo')
+ eq_([x.lower() for x in r.keys()], ['user_id', 'user_name'])
+ eq_(r.values(), [1, 'foo'])
def test_column_order_with_text_query(self):
# should return values in query order
users.insert().execute(user_id=1, user_name='foo')
r = testing.db.execute('select user_name, user_id from query_users').fetchone()
- self.assertEqual(r[0], 'foo')
- self.assertEqual(r[1], 1)
- self.assertEqual([x.lower() for x in r.keys()], ['user_name', 'user_id'])
- self.assertEqual(r.values(), ['foo', 1])
+ eq_(r[0], 'foo')
+ eq_(r[1], 1)
+ eq_([x.lower() for x in r.keys()], ['user_name', 'user_id'])
+ eq_(r.values(), ['foo', 1])
@testing.crashes('oracle', 'FIXME: unknown, varify not fails_on()')
@testing.crashes('firebird', 'An identifier must begin with a letter')
@@ -657,9 +658,10 @@ class PercentSchemaNamesTest(TestBase):
operation the same way we do for text() and column labels.
"""
+ @classmethod
@testing.crashes('mysql', 'mysqldb calls name % (params)')
@testing.crashes('postgres', 'postgres calls name % (params)')
- def setUpAll(self):
+ def setup_class(cls):
global percent_table, metadata
metadata = MetaData(testing.db)
percent_table = Table('percent%table', metadata,
@@ -669,9 +671,10 @@ class PercentSchemaNamesTest(TestBase):
)
metadata.create_all()
+ @classmethod
@testing.crashes('mysql', 'mysqldb calls name % (params)')
@testing.crashes('postgres', 'postgres calls name % (params)')
- def tearDownAll(self):
+ def teardown_class(cls):
metadata.drop_all()
@testing.crashes('mysql', 'mysqldb calls name % (params)')
@@ -734,7 +737,8 @@ class PercentSchemaNamesTest(TestBase):
class LimitTest(TestBase):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global users, addresses, metadata
metadata = MetaData(testing.db)
users = Table('query_users', metadata,
@@ -746,9 +750,7 @@ class LimitTest(TestBase):
Column('user_id', Integer, ForeignKey('query_users.user_id')),
Column('address', String(30)))
metadata.create_all()
- self._data()
-
- def _data(self):
+
users.insert().execute(user_id=1, user_name='john')
addresses.insert().execute(address_id=1, user_id=1, address='addr1')
users.insert().execute(user_id=2, user_name='jack')
@@ -764,7 +766,8 @@ class LimitTest(TestBase):
users.insert().execute(user_id=7, user_name='fido')
addresses.insert().execute(address_id=7, user_id=7, address='addr5')
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
metadata.drop_all()
def test_select_limit(self):
@@ -805,7 +808,8 @@ class LimitTest(TestBase):
class CompoundTest(TestBase):
"""test compound statements like UNION, INTERSECT, particularly their ability to nest on
different databases."""
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global metadata, t1, t2, t3
metadata = MetaData(testing.db)
t1 = Table('t1', metadata,
@@ -842,7 +846,8 @@ class CompoundTest(TestBase):
dict(col2="t3col2r3", col3="ccc", col4="bbb"),
])
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
metadata.drop_all()
def _fetchall_sorted(self, executed):
@@ -861,10 +866,10 @@ class CompoundTest(TestBase):
wanted = [('aaa', 'aaa'), ('bbb', 'bbb'), ('bbb', 'ccc'),
('ccc', 'aaa')]
found1 = self._fetchall_sorted(u.execute())
- self.assertEquals(found1, wanted)
+ eq_(found1, wanted)
found2 = self._fetchall_sorted(u.alias('bar').select().execute())
- self.assertEquals(found2, wanted)
+ eq_(found2, wanted)
def test_union_ordered(self):
(s1, s2) = (
@@ -877,7 +882,7 @@ class CompoundTest(TestBase):
wanted = [('aaa', 'aaa'), ('bbb', 'bbb'), ('bbb', 'ccc'),
('ccc', 'aaa')]
- self.assertEquals(u.execute().fetchall(), wanted)
+ eq_(u.execute().fetchall(), wanted)
@testing.fails_on('maxdb', 'FIXME: unknown')
@testing.requires.subqueries
@@ -892,7 +897,7 @@ class CompoundTest(TestBase):
wanted = [('aaa', 'aaa'), ('bbb', 'bbb'), ('bbb', 'ccc'),
('ccc', 'aaa')]
- self.assertEquals(u.alias('bar').select().execute().fetchall(), wanted)
+ eq_(u.alias('bar').select().execute().fetchall(), wanted)
@testing.crashes('oracle', 'FIXME: unknown, verify not fails_on')
@testing.fails_on('mysql', 'FIXME: unknown')
@@ -908,10 +913,10 @@ class CompoundTest(TestBase):
wanted = [('aaa',),('aaa',),('bbb',), ('bbb',), ('ccc',),('ccc',)]
found1 = self._fetchall_sorted(e.execute())
- self.assertEquals(found1, wanted)
+ eq_(found1, wanted)
found2 = self._fetchall_sorted(e.alias('foo').select().execute())
- self.assertEquals(found2, wanted)
+ eq_(found2, wanted)
@testing.crashes('firebird', 'Does not support intersect')
@testing.crashes('sybase', 'FIXME: unknown, verify not fails_on')
@@ -925,10 +930,10 @@ class CompoundTest(TestBase):
wanted = [('aaa', 'bbb'), ('bbb', 'ccc'), ('ccc', 'aaa')]
found1 = self._fetchall_sorted(i.execute())
- self.assertEquals(found1, wanted)
+ eq_(found1, wanted)
found2 = self._fetchall_sorted(i.alias('bar').select().execute())
- self.assertEquals(found2, wanted)
+ eq_(found2, wanted)
@testing.crashes('firebird', 'Does not support except')
@testing.crashes('oracle', 'FIXME: unknown, verify not fails_on')
@@ -945,7 +950,7 @@ class CompoundTest(TestBase):
('bbb', 'bbb'), ('ccc', 'bbb'), ('ccc', 'ccc')]
found = self._fetchall_sorted(e.alias('bar').select().execute())
- self.assertEquals(found, wanted)
+ eq_(found, wanted)
@testing.crashes('firebird', 'Does not support except')
@testing.crashes('oracle', 'FIXME: unknown, verify not fails_on')
@@ -962,10 +967,10 @@ class CompoundTest(TestBase):
('bbb', 'bbb'), ('ccc', 'bbb'), ('ccc', 'ccc')]
found1 = self._fetchall_sorted(e.execute())
- self.assertEquals(found1, wanted)
+ eq_(found1, wanted)
found2 = self._fetchall_sorted(e.alias('bar').select().execute())
- self.assertEquals(found2, wanted)
+ eq_(found2, wanted)
@testing.crashes('firebird', 'Does not support except')
@testing.crashes('oracle', 'FIXME: unknown, verify not fails_on')
@@ -981,8 +986,8 @@ class CompoundTest(TestBase):
select([t3.c.col3], t3.c.col3 == 'ccc'), #ccc
)
)
- self.assertEquals(e.execute().fetchall(), [('ccc',)])
- self.assertEquals(e.alias('foo').select().execute().fetchall(),
+ eq_(e.execute().fetchall(), [('ccc',)])
+ eq_(e.alias('foo').select().execute().fetchall(),
[('ccc',)])
@testing.crashes('firebird', 'Does not support intersect')
@@ -999,7 +1004,7 @@ class CompoundTest(TestBase):
wanted = [('aaa', 'bbb'), ('bbb', 'ccc'), ('ccc', 'aaa')]
found = self._fetchall_sorted(u.execute())
- self.assertEquals(found, wanted)
+ eq_(found, wanted)
@testing.crashes('firebird', 'Does not support intersect')
@testing.fails_on('mysql', 'FIXME: unknown')
@@ -1015,7 +1020,7 @@ class CompoundTest(TestBase):
wanted = [('aaa', 'bbb'), ('bbb', 'ccc'), ('ccc', 'aaa')]
found = self._fetchall_sorted(ua.select().execute())
- self.assertEquals(found, wanted)
+ eq_(found, wanted)
class JoinTest(TestBase):
@@ -1028,7 +1033,8 @@ class JoinTest(TestBase):
database seems to be sensitive to this.
"""
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global metadata
global t1, t2, t3
@@ -1057,7 +1063,8 @@ class JoinTest(TestBase):
{'t2_id': 21, 't1_id': 11, 'name': 't2 #21'})
t3.insert().execute({'t3_id': 30, 't2_id': 20, 'name': 't3 #30'})
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
metadata.drop_all()
def assertRows(self, statement, expected):
@@ -1066,7 +1073,7 @@ class JoinTest(TestBase):
found = sorted([tuple(row)
for row in statement.execute().fetchall()])
- self.assertEquals(found, sorted(expected))
+ eq_(found, sorted(expected))
def test_join_x1(self):
"""Joins t1->t2."""
@@ -1289,7 +1296,8 @@ class JoinTest(TestBase):
class OperatorTest(TestBase):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global metadata, flds
metadata = MetaData(testing.db)
flds = Table('flds', metadata,
@@ -1304,18 +1312,14 @@ class OperatorTest(TestBase):
dict(intcol=13, strcol='bar')
])
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
metadata.drop_all()
@testing.fails_on('maxdb', 'FIXME: unknown')
def test_modulo(self):
- self.assertEquals(
+ eq_(
select([flds.c.intcol % 3],
order_by=flds.c.idcol).execute().fetchall(),
[(2,),(1,)]
)
-
-
-
-if __name__ == "__main__":
- testenv.main()
diff --git a/test/sql/quote.py b/test/sql/test_quote.py
index 106189afe..64e097b85 100644
--- a/test/sql/quote.py
+++ b/test/sql/test_quote.py
@@ -1,12 +1,12 @@
-import testenv; testenv.configure_for_tests()
from sqlalchemy import *
from sqlalchemy import sql
from sqlalchemy.sql import compiler
-from testlib import *
+from sqlalchemy.test import *
class QuoteTest(TestBase, AssertsCompiledSQL):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
# TODO: figure out which databases/which identifiers allow special
# characters to be used, such as: spaces, quote characters,
# punctuation characters, set up tests for those as well.
@@ -24,11 +24,12 @@ class QuoteTest(TestBase, AssertsCompiledSQL):
table1.create()
table2.create()
- def tearDown(self):
+ def teardown(self):
table1.delete().execute()
table2.delete().execute()
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
table1.drop()
table2.drop()
@@ -207,5 +208,3 @@ class PreparerTest(TestBase):
a_eq(unformat('`foo`.bar'), ['foo', 'bar'])
a_eq(unformat('`foo`.`b``a``r`.`baz`'), ['foo', 'b`a`r', 'baz'])
-if __name__ == "__main__":
- testenv.main()
diff --git a/test/sql/rowcount.py b/test/sql/test_rowcount.py
index 3c9caad75..82301a4a5 100644
--- a/test/sql/rowcount.py
+++ b/test/sql/test_rowcount.py
@@ -1,11 +1,11 @@
-import testenv; testenv.configure_for_tests()
from sqlalchemy import *
-from testlib import *
+from sqlalchemy.test import *
class FoundRowsTest(TestBase, AssertsExecutionResults):
"""tests rowcount functionality"""
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
metadata = MetaData(testing.db)
global employees_table
@@ -17,7 +17,7 @@ class FoundRowsTest(TestBase, AssertsExecutionResults):
)
employees_table.create()
- def setUp(self):
+ def setup(self):
global data
data = [ ('Angela', 'A'),
('Andrew', 'A'),
@@ -31,10 +31,11 @@ class FoundRowsTest(TestBase, AssertsExecutionResults):
i = employees_table.insert()
i.execute(*[{'name':n, 'department':d} for n, d in data])
- def tearDown(self):
+ def teardown(self):
employees_table.delete().execute()
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
employees_table.drop()
def testbasic(self):
@@ -67,5 +68,3 @@ class FoundRowsTest(TestBase, AssertsExecutionResults):
if testing.db.dialect.supports_sane_rowcount:
assert r.rowcount == 3
-if __name__ == '__main__':
- testenv.main()
diff --git a/test/sql/select.py b/test/sql/test_select.py
index 2ec5b8da5..1d9e531de 100644
--- a/test/sql/select.py
+++ b/test/sql/test_select.py
@@ -1,4 +1,4 @@
-import testenv; testenv.configure_for_tests()
+from sqlalchemy.test.testing import eq_, assert_raises, assert_raises_message
import datetime, re, operator
from sqlalchemy import *
from sqlalchemy import exc, sql, util
@@ -6,7 +6,7 @@ from sqlalchemy.sql import table, column, label, compiler
from sqlalchemy.sql.expression import ClauseList
from sqlalchemy.engine import default
from sqlalchemy.databases import sqlite, postgres, mysql, oracle, firebird, mssql
-from testlib import *
+from sqlalchemy.test import *
table1 = table('mytable',
column('myid', Integer),
@@ -185,7 +185,7 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A
t2 = table('t2', column('c'), column('d'))
s = select([t.c.a]).where(t.c.a==t2.c.d).as_scalar()
s2 =select([t, t2, s])
- self.assertRaises(exc.InvalidRequestError, str, s2)
+ assert_raises(exc.InvalidRequestError, str, s2)
# intentional again
s = s.correlate(t, t2)
@@ -1149,10 +1149,10 @@ UNION SELECT mytable.myid FROM mytable"
# check that conflicts with "unique" params are caught
s = select([table1], or_(table1.c.myid==7, table1.c.myid==bindparam('myid_1')))
- self.assertRaisesMessage(exc.CompileError, "conflicts with unique bind parameter of the same name", str, s)
+ assert_raises_message(exc.CompileError, "conflicts with unique bind parameter of the same name", str, s)
s = select([table1], or_(table1.c.myid==7, table1.c.myid==8, table1.c.myid==bindparam('myid_1')))
- self.assertRaisesMessage(exc.CompileError, "conflicts with unique bind parameter of the same name", str, s)
+ assert_raises_message(exc.CompileError, "conflicts with unique bind parameter of the same name", str, s)
def test_binds_no_hash_collision(self):
"""test that construct_params doesn't corrupt dict due to hash collisions"""
@@ -1287,20 +1287,20 @@ UNION SELECT mytable.myid FROM mytable WHERE mytable.myid = :myid_2)")
)
def check_results(dialect, expected_results, literal):
- self.assertEqual(len(expected_results), 5, 'Incorrect number of expected results')
- self.assertEqual(str(cast(tbl.c.v1, Numeric).compile(dialect=dialect)), 'CAST(casttest.v1 AS %s)' %expected_results[0])
- self.assertEqual(str(cast(tbl.c.v1, Numeric(12, 9)).compile(dialect=dialect)), 'CAST(casttest.v1 AS %s)' %expected_results[1])
- self.assertEqual(str(cast(tbl.c.ts, Date).compile(dialect=dialect)), 'CAST(casttest.ts AS %s)' %expected_results[2])
- self.assertEqual(str(cast(1234, TEXT).compile(dialect=dialect)), 'CAST(%s AS %s)' %(literal, expected_results[3]))
- self.assertEqual(str(cast('test', String(20)).compile(dialect=dialect)), 'CAST(%s AS %s)' %(literal, expected_results[4]))
+ eq_(len(expected_results), 5, 'Incorrect number of expected results')
+ eq_(str(cast(tbl.c.v1, Numeric).compile(dialect=dialect)), 'CAST(casttest.v1 AS %s)' %expected_results[0])
+ eq_(str(cast(tbl.c.v1, Numeric(12, 9)).compile(dialect=dialect)), 'CAST(casttest.v1 AS %s)' %expected_results[1])
+ eq_(str(cast(tbl.c.ts, Date).compile(dialect=dialect)), 'CAST(casttest.ts AS %s)' %expected_results[2])
+ eq_(str(cast(1234, TEXT).compile(dialect=dialect)), 'CAST(%s AS %s)' %(literal, expected_results[3]))
+ eq_(str(cast('test', String(20)).compile(dialect=dialect)), 'CAST(%s AS %s)' %(literal, expected_results[4]))
# fixme: shoving all of this dialect-specific stuff in one test
# is now officialy completely ridiculous AND non-obviously omits
# coverage on other dialects.
sel = select([tbl, cast(tbl.c.v1, Numeric)]).compile(dialect=dialect)
if isinstance(dialect, type(mysql.dialect())):
- self.assertEqual(str(sel), "SELECT casttest.id, casttest.v1, casttest.v2, casttest.ts, CAST(casttest.v1 AS DECIMAL(10, 2)) AS anon_1 \nFROM casttest")
+ eq_(str(sel), "SELECT casttest.id, casttest.v1, casttest.v2, casttest.ts, CAST(casttest.v1 AS DECIMAL(10, 2)) AS anon_1 \nFROM casttest")
else:
- self.assertEqual(str(sel), "SELECT casttest.id, casttest.v1, casttest.v2, casttest.ts, CAST(casttest.v1 AS NUMERIC(10, 2)) AS anon_1 \nFROM casttest")
+ eq_(str(sel), "SELECT casttest.id, casttest.v1, casttest.v2, casttest.ts, CAST(casttest.v1 AS NUMERIC(10, 2)) AS anon_1 \nFROM casttest")
# first test with Postgres engine
check_results(postgres.dialect(), ['NUMERIC(10, 2)', 'NUMERIC(12, 9)', 'DATE', 'TEXT', 'VARCHAR(20)'], '%(param_1)s')
@@ -1548,5 +1548,3 @@ class SchemaTest(TestBase, AssertsCompiledSQL):
self.assert_compile(table4.insert(values=(2, 5, 'test')), "INSERT INTO remote_owner.remotetable (rem_id, datatype_id, value) VALUES "\
"(:rem_id, :datatype_id, :value)")
-if __name__ == "__main__":
- testenv.main()
diff --git a/test/sql/selectable.py b/test/sql/test_selectable.py
index e9ed5f565..a172eb452 100755..100644
--- a/test/sql/selectable.py
+++ b/test/sql/test_selectable.py
@@ -1,8 +1,8 @@
"""Test various algorithmic properties of selectables."""
-import testenv; testenv.configure_for_tests()
+from sqlalchemy.test.testing import eq_, assert_raises, assert_raises_message
from sqlalchemy import *
-from testlib import *
+from sqlalchemy.test import *
from sqlalchemy.sql import util as sql_util, visitors
from sqlalchemy import exc
from sqlalchemy.sql import table, column
@@ -228,7 +228,7 @@ class SelectableTest(TestBase, AssertsExecutionResults):
s = select([t2, t3], use_labels=True)
- self.assertRaises(exc.NoReferencedTableError, s.join, t1)
+ assert_raises(exc.NoReferencedTableError, s.join, t1)
class PrimaryKeyTest(TestBase, AssertsExecutionResults):
def test_join_pk_collapse_implicit(self):
@@ -304,12 +304,12 @@ class PrimaryKeyTest(TestBase, AssertsExecutionResults):
Column('id', Integer, ForeignKey( 'Employee.id', ), primary_key=True),
)
- self.assertEquals(
+ eq_(
util.column_set(employee.join(engineer, employee.c.id==engineer.c.id).primary_key),
util.column_set([employee.c.id])
)
- self.assertEquals(
+ eq_(
util.column_set(employee.join(engineer, engineer.c.id==employee.c.id).primary_key),
util.column_set([employee.c.id])
)
@@ -329,7 +329,7 @@ class ReduceTest(TestBase, AssertsExecutionResults):
Column('t3data', String(30)))
- self.assertEquals(
+ eq_(
util.column_set(sql_util.reduce_columns([t1.c.t1id, t1.c.t1data, t2.c.t2id, t2.c.t2data, t3.c.t3id, t3.c.t3data])),
util.column_set([t1.c.t1id, t1.c.t1data, t2.c.t2data, t3.c.t3data])
)
@@ -349,7 +349,7 @@ class ReduceTest(TestBase, AssertsExecutionResults):
s = select([engineers, managers]).where(engineers.c.engineer_name==managers.c.manager_name)
- self.assertEquals(util.column_set(sql_util.reduce_columns(list(s.c), s)),
+ eq_(util.column_set(sql_util.reduce_columns(list(s.c), s)),
util.column_set([s.c.engineer_id, s.c.engineer_name, s.c.manager_id])
)
@@ -374,7 +374,7 @@ class ReduceTest(TestBase, AssertsExecutionResults):
)
pjoin = people.outerjoin(engineers).outerjoin(managers).select(use_labels=True).alias('pjoin')
- self.assertEquals(
+ eq_(
util.column_set(sql_util.reduce_columns([pjoin.c.people_person_id, pjoin.c.engineers_person_id, pjoin.c.managers_person_id])),
util.column_set([pjoin.c.people_person_id])
)
@@ -398,7 +398,7 @@ class ReduceTest(TestBase, AssertsExecutionResults):
'Item':base_item_table.join(item_table),
}, None, 'item_join')
- self.assertEquals(
+ eq_(
util.column_set(sql_util.reduce_columns([item_join.c.id, item_join.c.dummy, item_join.c.child_name])),
util.column_set([item_join.c.id, item_join.c.dummy, item_join.c.child_name])
)
@@ -423,7 +423,7 @@ class ReduceTest(TestBase, AssertsExecutionResults):
'c': page_table.join(magazine_page_table).join(classified_page_table),
}, None, 'page_join')
- self.assertEquals(
+ eq_(
util.column_set(sql_util.reduce_columns([pjoin.c.id, pjoin.c.page_id, pjoin.c.magazine_page_id])),
util.column_set([pjoin.c.id])
)
@@ -522,5 +522,3 @@ class AnnotationsTest(TestBase):
assert b4.left is bin.left # since column is immutable
assert b4.right is not bin.right is not b2.right is not b3.right
-if __name__ == "__main__":
- testenv.main()
diff --git a/test/sql/testtypes.py b/test/sql/test_types.py
index e5cffe328..13b6d0954 100644
--- a/test/sql/testtypes.py
+++ b/test/sql/test_types.py
@@ -1,13 +1,13 @@
+from sqlalchemy.test.testing import eq_, assert_raises, assert_raises_message
import decimal
-import testenv; testenv.configure_for_tests()
-import datetime, os, pickleable, re
+import datetime, os, re
from sqlalchemy import *
from sqlalchemy import exc, types, util
from sqlalchemy.sql import operators
-from testlib.testing import eq_
+from sqlalchemy.test.testing import eq_
import sqlalchemy.engine.url as url
from sqlalchemy.databases import mssql, oracle, mysql, postgres, firebird
-from testlib import *
+from sqlalchemy.test import *
class AdaptTest(TestBase):
@@ -121,13 +121,14 @@ class UserDefinedTest(TestBase):
l
):
for col in row[1:5]:
- self.assertEquals(col, assertstr)
- self.assertEquals(row[5], assertint)
- self.assertEquals(row[6], assertint2)
+ eq_(col, assertstr)
+ eq_(row[5], assertint)
+ eq_(row[6], assertint2)
for col in row[3], row[4]:
assert isinstance(col, unicode)
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global users, metadata
class MyType(types.TypeEngine):
@@ -226,7 +227,8 @@ class UserDefinedTest(TestBase):
metadata.create_all()
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
metadata.drop_all()
class ColumnsTest(TestBase, AssertsExecutionResults):
@@ -263,14 +265,15 @@ class ColumnsTest(TestBase, AssertsExecutionResults):
)
for aCol in testTable.c:
- self.assertEquals(
+ eq_(
expectedResults[aCol.name],
db.dialect.schemagenerator(db.dialect, db, None, None).\
get_column_specification(aCol))
class UnicodeTest(TestBase, AssertsExecutionResults):
"""tests the Unicode type. also tests the TypeDecorator with instances in the types package."""
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global unicode_table
metadata = MetaData(testing.db)
unicode_table = Table('unicode_table', metadata,
@@ -280,10 +283,11 @@ class UnicodeTest(TestBase, AssertsExecutionResults):
Column('plain_varchar', String(250))
)
unicode_table.create()
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
unicode_table.drop()
- def tearDown(self):
+ def teardown(self):
unicode_table.delete().execute()
def test_round_trip(self):
@@ -387,7 +391,8 @@ class BinaryTest(TestBase, AssertsExecutionResults):
('mysql', '<', (4, 1, 1)), # screwy varbinary types
)
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global binary_table, MyPickleType
class MyPickleType(types.TypeDecorator):
@@ -416,10 +421,11 @@ class BinaryTest(TestBase, AssertsExecutionResults):
)
binary_table.create()
- def tearDown(self):
+ def teardown(self):
binary_table.delete().execute()
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
binary_table.drop()
@testing.fails_on('mssql', 'MSSQl BINARY type right pads the fixed length with \x00')
@@ -439,21 +445,22 @@ class BinaryTest(TestBase, AssertsExecutionResults):
text("select * from binary_table order by binary_table.primary_id", typemap={'pickled':PickleType, 'mypickle':MyPickleType}, bind=testing.db)
):
l = stmt.execute().fetchall()
- self.assertEquals(list(stream1), list(l[0]['data']))
- self.assertEquals(list(stream1[0:100]), list(l[0]['data_slice']))
- self.assertEquals(list(stream2), list(l[1]['data']))
- self.assertEquals(testobj1, l[0]['pickled'])
- self.assertEquals(testobj2, l[1]['pickled'])
- self.assertEquals(testobj3.moredata, l[0]['mypickle'].moredata)
- self.assertEquals(l[0]['mypickle'].stuff, 'this is the right stuff')
+ eq_(list(stream1), list(l[0]['data']))
+ eq_(list(stream1[0:100]), list(l[0]['data_slice']))
+ eq_(list(stream2), list(l[1]['data']))
+ eq_(testobj1, l[0]['pickled'])
+ eq_(testobj2, l[1]['pickled'])
+ eq_(testobj3.moredata, l[0]['mypickle'].moredata)
+ eq_(l[0]['mypickle'].stuff, 'this is the right stuff')
def load_stream(self, name, len=12579):
- f = os.path.join(os.path.dirname(testenv.__file__), name)
+ f = os.path.join(os.path.dirname(__file__), "..", name)
# put a number less than the typical MySQL default BLOB size
return file(f).read(len)
class ExpressionTest(TestBase, AssertsExecutionResults):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global test_table, meta
class MyCustomType(types.TypeEngine):
@@ -481,7 +488,8 @@ class ExpressionTest(TestBase, AssertsExecutionResults):
test_table.insert().execute({'id':1, 'data':'somedata', 'atimestamp':datetime.date(2007, 10, 15), 'avalue':25})
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
meta.drop_all()
def test_control(self):
@@ -523,7 +531,8 @@ class ExpressionTest(TestBase, AssertsExecutionResults):
assert testing.db.execute(select([expr])).scalar() == -15
class DateTest(TestBase, AssertsExecutionResults):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global users_with_date, insert_data
db = testing.db
@@ -605,7 +614,8 @@ class DateTest(TestBase, AssertsExecutionResults):
for idict in insert_dicts:
users_with_date.insert().execute(**idict)
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
users_with_date.drop()
def testdate(self):
@@ -649,8 +659,8 @@ class DateTest(TestBase, AssertsExecutionResults):
# test mismatched date/datetime
t.insert().execute(adate=d2, adatetime=d2)
- self.assertEquals(select([t.c.adate, t.c.adatetime], t.c.adate==d1).execute().fetchall(), [(d1, d2)])
- self.assertEquals(select([t.c.adate, t.c.adatetime], t.c.adate==d1).execute().fetchall(), [(d1, d2)])
+ eq_(select([t.c.adate, t.c.adatetime], t.c.adate==d1).execute().fetchall(), [(d1, d2)])
+ eq_(select([t.c.adate, t.c.adatetime], t.c.adate==d1).execute().fetchall(), [(d1, d2)])
finally:
t.drop(checkfirst=True)
@@ -674,7 +684,8 @@ def _missing_decimal():
return True
class NumericTest(TestBase, AssertsExecutionResults):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global numeric_table, metadata
metadata = MetaData(testing.db)
numeric_table = Table('numeric_table', metadata,
@@ -686,10 +697,11 @@ class NumericTest(TestBase, AssertsExecutionResults):
)
metadata.create_all()
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
metadata.drop_all()
- def tearDown(self):
+ def teardown(self):
numeric_table.delete().execute()
@testing.fails_if(_missing_decimal)
@@ -723,7 +735,7 @@ class NumericTest(TestBase, AssertsExecutionResults):
assert isinstance(row['fcasdec'], decimal.Decimal)
def test_length_deprecation(self):
- self.assertRaises(exc.SADeprecationWarning, Numeric, length=8)
+ assert_raises(exc.SADeprecationWarning, Numeric, length=8)
@testing.uses_deprecated(".*is deprecated for Numeric")
def go():
@@ -751,7 +763,8 @@ class NumericTest(TestBase, AssertsExecutionResults):
class IntervalTest(TestBase, AssertsExecutionResults):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global interval_table, metadata
metadata = MetaData(testing.db)
interval_table = Table("intervaltable", metadata,
@@ -760,10 +773,11 @@ class IntervalTest(TestBase, AssertsExecutionResults):
)
metadata.create_all()
- def tearDown(self):
+ def teardown(self):
interval_table.delete().execute()
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
metadata.drop_all()
def test_roundtrip(self):
@@ -776,14 +790,16 @@ class IntervalTest(TestBase, AssertsExecutionResults):
assert interval_table.select().execute().fetchone()['interval'] is None
class BooleanTest(TestBase, AssertsExecutionResults):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global bool_table
metadata = MetaData(testing.db)
bool_table = Table('booltest', metadata,
Column('id', Integer, primary_key=True),
Column('value', Boolean))
bool_table.create()
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
bool_table.drop()
def testbasic(self):
bool_table.insert().execute(id=1, value=True)
@@ -802,11 +818,11 @@ class PickleTest(TestBase):
def test_noeq_deprecation(self):
p1 = PickleType()
- self.assertRaises(DeprecationWarning,
+ assert_raises(DeprecationWarning,
p1.compare_values, pickleable.BarWithoutCompare(1, 2), pickleable.BarWithoutCompare(1, 2)
)
- self.assertRaises(DeprecationWarning,
+ assert_raises(DeprecationWarning,
p1.compare_values, pickleable.OldSchoolWithoutCompare(1, 2), pickleable.OldSchoolWithoutCompare(1, 2)
)
@@ -833,7 +849,7 @@ class PickleTest(TestBase):
):
assert p1.compare_values(p1.copy_value(obj), obj)
- self.assertRaises(NotImplementedError, p1.compare_values, pickleable.BrokenComparable('foo'),pickleable.BrokenComparable('foo'))
+ assert_raises(NotImplementedError, p1.compare_values, pickleable.BrokenComparable('foo'),pickleable.BrokenComparable('foo'))
def test_nonmutable_comparison(self):
p1 = PickleType()
@@ -846,11 +862,13 @@ class PickleTest(TestBase):
assert p1.compare_values(p1.copy_value(obj), obj)
class CallableTest(TestBase):
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global meta
meta = MetaData(testing.db)
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
meta.drop_all()
def test_callable_as_arg(self):
@@ -871,5 +889,3 @@ class CallableTest(TestBase):
assert isinstance(thang_table.c.name.type, Unicode)
thang_table.create()
-if __name__ == "__main__":
- testenv.main()
diff --git a/test/sql/unicode.py b/test/sql/test_unicode.py
index c5002aaff..d75913267 100644
--- a/test/sql/unicode.py
+++ b/test/sql/test_unicode.py
@@ -1,16 +1,16 @@
# coding: utf-8
"""verrrrry basic unicode column name testing"""
-import testenv; testenv.configure_for_tests()
from sqlalchemy import *
-from testlib import *
-from testlib.engines import utf8_engine
+from sqlalchemy.test import *
+from sqlalchemy.test.engines import utf8_engine
from sqlalchemy.sql import column
class UnicodeSchemaTest(TestBase):
__requires__ = ('unicode_ddl',)
- def setUpAll(self):
+ @classmethod
+ def setup_class(cls):
global unicode_bind, metadata, t1, t2, t3
unicode_bind = utf8_engine()
@@ -56,13 +56,14 @@ class UnicodeSchemaTest(TestBase):
)
metadata.create_all()
- def tearDown(self):
+ def teardown(self):
if metadata.tables:
t3.delete().execute()
t2.delete().execute()
t1.delete().execute()
- def tearDownAll(self):
+ @classmethod
+ def teardown_class(cls):
global unicode_bind
metadata.drop_all()
del unicode_bind
@@ -135,5 +136,3 @@ class EscapesDefaultsTest(testing.TestBase):
t1.drop()
-if __name__ == '__main__':
- testenv.main()