diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-06-10 21:18:24 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-06-10 21:18:24 +0000 |
| commit | 45cec095b4904ba71425d2fe18c143982dd08f43 (patch) | |
| tree | af5e540fdcbf1cb2a3337157d69d4b40be010fa8 /test/dialect | |
| parent | 698a3c1ac665e7cd2ef8d5ad3ebf51b7fe6661f4 (diff) | |
| download | sqlalchemy-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/dialect')
| -rw-r--r-- | test/dialect/alltests.py | 28 | ||||
| -rw-r--r-- | test/dialect/test_access.py (renamed from test/dialect/access.py) | 5 | ||||
| -rw-r--r-- | test/dialect/test_firebird.py (renamed from test/dialect/firebird.py) | 54 | ||||
| -rw-r--r-- | test/dialect/test_informix.py (renamed from test/dialect/informix.py) | 5 | ||||
| -rw-r--r-- | test/dialect/test_maxdb.py (renamed from test/dialect/maxdb.py) | 12 | ||||
| -rw-r--r--[-rwxr-xr-x] | test/dialect/test_mssql.py (renamed from test/dialect/mssql.py) | 116 | ||||
| -rw-r--r-- | test/dialect/test_mysql.py (renamed from test/dialect/mysql.py) | 54 | ||||
| -rw-r--r-- | test/dialect/test_oracle.py (renamed from test/dialect/oracle.py) | 30 | ||||
| -rw-r--r-- | test/dialect/test_postgres.py (renamed from test/dialect/postgres.py) | 155 | ||||
| -rw-r--r-- | test/dialect/test_sqlite.py (renamed from test/dialect/sqlite.py) | 46 | ||||
| -rw-r--r-- | test/dialect/test_sybase.py (renamed from test/dialect/sybase.py) | 5 |
11 files changed, 245 insertions, 265 deletions
diff --git a/test/dialect/alltests.py b/test/dialect/alltests.py deleted file mode 100644 index 0defb6a15..000000000 --- a/test/dialect/alltests.py +++ /dev/null @@ -1,28 +0,0 @@ -import testenv; testenv.configure_for_tests() -from testlib import sa_unittest as unittest - - -def suite(): - modules_to_test = ( - 'dialect.access', - 'dialect.firebird', - 'dialect.informix', - 'dialect.maxdb', - 'dialect.mssql', - 'dialect.mysql', - 'dialect.oracle', - 'dialect.postgres', - 'dialect.sqlite', - 'dialect.sybase', - ) - 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/dialect/access.py b/test/dialect/test_access.py index 57af45a9d..0ea8d9a61 100644 --- a/test/dialect/access.py +++ b/test/dialect/test_access.py @@ -1,8 +1,7 @@ -import testenv; testenv.configure_for_tests() from sqlalchemy import * from sqlalchemy import sql from sqlalchemy.databases import access -from testlib import * +from sqlalchemy.test import * class CompileTest(TestBase, AssertsCompiledSQL): @@ -30,5 +29,3 @@ class CompileTest(TestBase, AssertsCompiledSQL): 'SELECT DATEPART("%s", t.col1) AS anon_1 FROM t' % subst) -if __name__ == "__main__": - testenv.main() diff --git a/test/dialect/firebird.py b/test/dialect/test_firebird.py index 5a0109dcc..fa608c9a1 100644 --- a/test/dialect/firebird.py +++ b/test/dialect/test_firebird.py @@ -1,9 +1,9 @@ -import testenv; testenv.configure_for_tests() +from sqlalchemy.test.testing import eq_ from sqlalchemy import * from sqlalchemy.databases import firebird from sqlalchemy.exc import ProgrammingError from sqlalchemy.sql import table, column -from testlib import * +from sqlalchemy.test import * class DomainReflectionTest(TestBase, AssertsExecutionResults): @@ -11,7 +11,8 @@ class DomainReflectionTest(TestBase, AssertsExecutionResults): __only_on__ = 'firebird' - def setUpAll(self): + @classmethod + def setup_class(cls): con = testing.db.connect() try: con.execute('CREATE DOMAIN int_domain AS INTEGER DEFAULT 42 NOT NULL') @@ -38,7 +39,8 @@ class DomainReflectionTest(TestBase, AssertsExecutionResults): NEW.question = gen_id(gen_testtable_id, 1); END''') - def tearDownAll(self): + @classmethod + def teardown_class(cls): con = testing.db.connect() con.execute('DROP TABLE testtable') con.execute('DROP DOMAIN int_domain') @@ -50,22 +52,22 @@ class DomainReflectionTest(TestBase, AssertsExecutionResults): def test_table_is_reflected(self): metadata = MetaData(testing.db) table = Table('testtable', metadata, autoload=True) - self.assertEquals(set(table.columns.keys()), + eq_(set(table.columns.keys()), set(['question', 'answer', 'remark', 'photo', 'd', 't', 'dt']), "Columns of reflected table didn't equal expected columns") - self.assertEquals(table.c.question.primary_key, True) - self.assertEquals(table.c.question.sequence.name, 'gen_testtable_id') - self.assertEquals(table.c.question.type.__class__, firebird.FBInteger) - self.assertEquals(table.c.question.server_default.arg.text, "42") - self.assertEquals(table.c.answer.type.__class__, firebird.FBString) - self.assertEquals(table.c.answer.server_default.arg.text, "'no answer'") - self.assertEquals(table.c.remark.type.__class__, firebird.FBText) - self.assertEquals(table.c.remark.server_default.arg.text, "''") - self.assertEquals(table.c.photo.type.__class__, firebird.FBBinary) + eq_(table.c.question.primary_key, True) + eq_(table.c.question.sequence.name, 'gen_testtable_id') + eq_(table.c.question.type.__class__, firebird.FBInteger) + eq_(table.c.question.server_default.arg.text, "42") + eq_(table.c.answer.type.__class__, firebird.FBString) + eq_(table.c.answer.server_default.arg.text, "'no answer'") + eq_(table.c.remark.type.__class__, firebird.FBText) + eq_(table.c.remark.server_default.arg.text, "''") + eq_(table.c.photo.type.__class__, firebird.FBBinary) # The following assume a Dialect 3 database - self.assertEquals(table.c.d.type.__class__, firebird.FBDate) - self.assertEquals(table.c.t.type.__class__, firebird.FBTime) - self.assertEquals(table.c.dt.type.__class__, firebird.FBDateTime) + eq_(table.c.d.type.__class__, firebird.FBDate) + eq_(table.c.t.type.__class__, firebird.FBTime) + eq_(table.c.dt.type.__class__, firebird.FBDateTime) class CompileTest(TestBase, AssertsCompiledSQL): @@ -140,10 +142,10 @@ class ReturningTest(TestBase, AssertsExecutionResults): table.insert().execute([{'persons': 5, 'full': False}, {'persons': 3, 'full': False}]) result = table.update(table.c.persons > 4, dict(full=True), firebird_returning=[table.c.id]).execute() - self.assertEqual(result.fetchall(), [(1,)]) + eq_(result.fetchall(), [(1,)]) result2 = select([table.c.id, table.c.full]).order_by(table.c.id).execute() - self.assertEqual(result2.fetchall(), [(1,True),(2,False)]) + eq_(result2.fetchall(), [(1,True),(2,False)]) finally: table.drop() @@ -159,19 +161,19 @@ class ReturningTest(TestBase, AssertsExecutionResults): try: result = table.insert(firebird_returning=[table.c.id]).execute({'persons': 1, 'full': False}) - self.assertEqual(result.fetchall(), [(1,)]) + eq_(result.fetchall(), [(1,)]) # Multiple inserts only return the last row result2 = table.insert(firebird_returning=[table]).execute( [{'persons': 2, 'full': False}, {'persons': 3, 'full': True}]) - self.assertEqual(result2.fetchall(), [(3,3,True)]) + eq_(result2.fetchall(), [(3,3,True)]) result3 = table.insert(firebird_returning=[table.c.id]).execute({'persons': 4, 'full': False}) - self.assertEqual([dict(row) for row in result3], [{'ID':4}]) + eq_([dict(row) for row in result3], [{'ID':4}]) result4 = testing.db.execute('insert into tables (id, persons, "full") values (5, 10, 1) returning persons') - self.assertEqual([dict(row) for row in result4], [{'PERSONS': 10}]) + eq_([dict(row) for row in result4], [{'PERSONS': 10}]) finally: table.drop() @@ -188,10 +190,10 @@ class ReturningTest(TestBase, AssertsExecutionResults): table.insert().execute([{'persons': 5, 'full': False}, {'persons': 3, 'full': False}]) result = table.delete(table.c.persons > 4, firebird_returning=[table.c.id]).execute() - self.assertEqual(result.fetchall(), [(1,)]) + eq_(result.fetchall(), [(1,)]) result2 = select([table.c.id, table.c.full]).order_by(table.c.id).execute() - self.assertEqual(result2.fetchall(), [(2,False),]) + eq_(result2.fetchall(), [(2,False),]) finally: table.drop() @@ -224,5 +226,3 @@ class MiscFBTests(TestBase): assert len(version) == 3, "Got strange version info: %s" % repr(version) -if __name__ == '__main__': - testenv.main() diff --git a/test/dialect/informix.py b/test/dialect/test_informix.py index 1fbbaa0cb..86a4e751d 100644 --- a/test/dialect/informix.py +++ b/test/dialect/test_informix.py @@ -1,7 +1,6 @@ -import testenv; testenv.configure_for_tests() from sqlalchemy import * from sqlalchemy.databases import informix -from testlib import * +from sqlalchemy.test import * class CompileTest(TestBase, AssertsCompiledSQL): @@ -19,5 +18,3 @@ class CompileTest(TestBase, AssertsCompiledSQL): self.assert_compile(t1.update().values({t1.c.col1 : t1.c.col1 + 1}), 'UPDATE t1 SET col1=(t1.col1 + ?)') -if __name__ == "__main__": - testenv.main() diff --git a/test/dialect/maxdb.py b/test/dialect/test_maxdb.py index c2daf8959..033a05533 100644 --- a/test/dialect/maxdb.py +++ b/test/dialect/test_maxdb.py @@ -1,12 +1,12 @@ """MaxDB-specific tests.""" -import testenv; testenv.configure_for_tests() +from sqlalchemy.test.testing import eq_ import StringIO, sys from sqlalchemy import * from sqlalchemy import exc, sql from decimal import Decimal from sqlalchemy.databases import maxdb -from testlib import * +from sqlalchemy.test import * # TODO @@ -43,12 +43,12 @@ class ReflectionTest(TestBase, AssertsExecutionResults): cols = ['d1','d2','n1','i1'] t.insert().execute(dict(zip(cols,vals))) roundtrip = list(t.select().execute()) - self.assertEquals(roundtrip, [tuple([1] + vals)]) + eq_(roundtrip, [tuple([1] + vals)]) t.insert().execute(dict(zip(['id'] + cols, [2] + list(roundtrip[0][1:])))) roundtrip2 = list(t.select(order_by=t.c.id).execute()) - self.assertEquals(roundtrip2, [tuple([1] + vals), + eq_(roundtrip2, [tuple([1] + vals), tuple([2] + vals)]) finally: try: @@ -233,8 +233,6 @@ class DBAPITest(TestBase, AssertsExecutionResults): def test_modulo_operator(self): st = str(select([sql.column('col') % 5]).compile(testing.db)) - self.assertEquals(st, 'SELECT mod(col, ?) FROM DUAL') + eq_(st, 'SELECT mod(col, ?) FROM DUAL') -if __name__ == "__main__": - testenv.main() diff --git a/test/dialect/mssql.py b/test/dialect/test_mssql.py index 50f9594ef..5e2c9a672 100755..100644 --- a/test/dialect/mssql.py +++ b/test/dialect/test_mssql.py @@ -1,14 +1,14 @@ # -*- encoding: utf-8 -import testenv; testenv.configure_for_tests() -import datetime, os, pickleable, re +from sqlalchemy.test.testing import eq_ +import datetime, os, re from sqlalchemy import * from sqlalchemy import types, exc from sqlalchemy.orm import * from sqlalchemy.sql import table, column from sqlalchemy.databases import mssql import sqlalchemy.engine.url as url -from testlib import * -from testlib.testing import eq_ +from sqlalchemy.test import * +from sqlalchemy.test.testing import eq_ class CompileTest(TestBase, AssertsCompiledSQL): @@ -162,7 +162,8 @@ class IdentityInsertTest(TestBase, AssertsCompiledSQL): __only_on__ = 'mssql' __dialect__ = mssql.MSSQLDialect() - def setUpAll(self): + @classmethod + def setup_class(cls): global metadata, cattable metadata = MetaData(testing.db) @@ -172,10 +173,10 @@ class IdentityInsertTest(TestBase, AssertsCompiledSQL): PrimaryKeyConstraint('id', name='PK_cattable'), ) - def setUp(self): + def setup(self): metadata.create_all() - def tearDown(self): + def teardown(self): metadata.drop_all() def test_compiled(self): @@ -185,12 +186,12 @@ class IdentityInsertTest(TestBase, AssertsCompiledSQL): cattable.insert().values(id=9, description='Python').execute() cats = cattable.select().order_by(cattable.c.id).execute() - self.assertEqual([(9, 'Python')], list(cats)) + eq_([(9, 'Python')], list(cats)) result = cattable.insert().values(description='PHP').execute() - self.assertEqual([10], result.last_inserted_ids()) + eq_([10], result.last_inserted_ids()) lastcat = cattable.select().order_by(desc(cattable.c.id)).execute() - self.assertEqual((10, 'PHP'), lastcat.fetchone()) + eq_((10, 'PHP'), lastcat.fetchone()) def test_executemany(self): cattable.insert().execute([ @@ -201,7 +202,7 @@ class IdentityInsertTest(TestBase, AssertsCompiledSQL): ]) cats = cattable.select().order_by(cattable.c.id).execute() - self.assertEqual([(1, 'Java'), (3, 'Perl'), (8, 'Ruby'), (89, 'Python')], list(cats)) + eq_([(1, 'Java'), (3, 'Perl'), (8, 'Ruby'), (89, 'Python')], list(cats)) cattable.insert().execute([ {'description': 'PHP'}, @@ -209,7 +210,7 @@ class IdentityInsertTest(TestBase, AssertsCompiledSQL): ]) lastcats = cattable.select().order_by(desc(cattable.c.id)).limit(2).execute() - self.assertEqual([(91, 'Smalltalk'), (90, 'PHP')], list(lastcats)) + eq_([(91, 'Smalltalk'), (90, 'PHP')], list(lastcats)) class ReflectionTest(TestBase): @@ -330,7 +331,8 @@ class Foo(object): class GenerativeQueryTest(TestBase): __only_on__ = 'mssql' - def setUpAll(self): + @classmethod + def setup_class(cls): global foo, metadata metadata = MetaData(testing.db) foo = Table('foo', metadata, @@ -347,7 +349,8 @@ class GenerativeQueryTest(TestBase): sess.add(Foo(bar=i, range=i%10)) sess.flush() - def tearDownAll(self): + @classmethod + def teardown_class(cls): metadata.drop_all() clear_mappers() @@ -361,7 +364,7 @@ class GenerativeQueryTest(TestBase): class SchemaTest(TestBase): - def setUp(self): + def setup(self): t = Table('sometable', MetaData(), Column('pk_column', Integer), Column('test_column', String) @@ -418,7 +421,8 @@ class MatchTest(TestBase, AssertsCompiledSQL): __only_on__ = 'mssql' __skip_if__ = (full_text_search_missing, ) - def setUpAll(self): + @classmethod + def setup_class(cls): global metadata, cattable, matchtable metadata = MetaData(testing.db) @@ -456,7 +460,8 @@ class MatchTest(TestBase, AssertsCompiledSQL): ]) DDL("WAITFOR DELAY '00:00:05'").execute(bind=engines.testing_engine()) - def tearDownAll(self): + @classmethod + def teardown_class(cls): metadata.drop_all() connection = testing.db.connect() connection.execute("DROP FULLTEXT CATALOG Catalog") @@ -467,44 +472,44 @@ class MatchTest(TestBase, AssertsCompiledSQL): def test_simple_match(self): results = matchtable.select().where(matchtable.c.title.match('python')).order_by(matchtable.c.id).execute().fetchall() - self.assertEquals([2, 5], [r.id for r in results]) + eq_([2, 5], [r.id for r in results]) def test_simple_match_with_apostrophe(self): results = matchtable.select().where(matchtable.c.title.match('"Matz''s"')).execute().fetchall() - self.assertEquals([3], [r.id for r in results]) + eq_([3], [r.id for r in results]) def test_simple_prefix_match(self): results = matchtable.select().where(matchtable.c.title.match('"nut*"')).execute().fetchall() - self.assertEquals([5], [r.id for r in results]) + eq_([5], [r.id for r in results]) def test_simple_inflectional_match(self): results = matchtable.select().where(matchtable.c.title.match('FORMSOF(INFLECTIONAL, "dives")')).execute().fetchall() - self.assertEquals([2], [r.id for r in results]) + eq_([2], [r.id for r in results]) def test_or_match(self): results1 = matchtable.select().where(or_(matchtable.c.title.match('nutshell'), matchtable.c.title.match('ruby')) ).order_by(matchtable.c.id).execute().fetchall() - self.assertEquals([3, 5], [r.id for r in results1]) + eq_([3, 5], [r.id for r in results1]) results2 = matchtable.select().where(matchtable.c.title.match('nutshell OR ruby'), ).order_by(matchtable.c.id).execute().fetchall() - self.assertEquals([3, 5], [r.id for r in results2]) + eq_([3, 5], [r.id for r in results2]) def test_and_match(self): results1 = matchtable.select().where(and_(matchtable.c.title.match('python'), matchtable.c.title.match('nutshell')) ).execute().fetchall() - self.assertEquals([5], [r.id for r in results1]) + eq_([5], [r.id for r in results1]) results2 = matchtable.select().where(matchtable.c.title.match('python AND nutshell'), ).execute().fetchall() - self.assertEquals([5], [r.id for r in results2]) + eq_([5], [r.id for r in results2]) def test_match_across_joins(self): results = matchtable.select().where(and_(cattable.c.id==matchtable.c.category_id, or_(cattable.c.description.match('Ruby'), matchtable.c.title.match('nutshell'))) ).order_by(matchtable.c.id).execute().fetchall() - self.assertEquals([1, 3, 5], [r.id for r in results]) + eq_([1, 3, 5], [r.id for r in results]) class ParseConnectTest(TestBase, AssertsCompiledSQL): @@ -514,77 +519,78 @@ class ParseConnectTest(TestBase, AssertsCompiledSQL): u = url.make_url('mssql://mydsn') dialect = mssql.MSSQLDialect_pyodbc() connection = dialect.create_connect_args(u) - self.assertEquals([['dsn=mydsn;TrustedConnection=Yes'], {}], connection) + eq_([['dsn=mydsn;TrustedConnection=Yes'], {}], connection) def test_pyodbc_connect_old_style_dsn_trusted(self): u = url.make_url('mssql:///?dsn=mydsn') dialect = mssql.MSSQLDialect_pyodbc() connection = dialect.create_connect_args(u) - self.assertEquals([['dsn=mydsn;TrustedConnection=Yes'], {}], connection) + eq_([['dsn=mydsn;TrustedConnection=Yes'], {}], connection) def test_pyodbc_connect_dsn_non_trusted(self): u = url.make_url('mssql://username:password@mydsn') dialect = mssql.MSSQLDialect_pyodbc() connection = dialect.create_connect_args(u) - self.assertEquals([['dsn=mydsn;UID=username;PWD=password'], {}], connection) + eq_([['dsn=mydsn;UID=username;PWD=password'], {}], connection) def test_pyodbc_connect_dsn_extra(self): u = url.make_url('mssql://username:password@mydsn/?LANGUAGE=us_english&foo=bar') dialect = mssql.MSSQLDialect_pyodbc() connection = dialect.create_connect_args(u) - self.assertEquals([['dsn=mydsn;UID=username;PWD=password;LANGUAGE=us_english;foo=bar'], {}], connection) + eq_([['dsn=mydsn;UID=username;PWD=password;LANGUAGE=us_english;foo=bar'], {}], connection) def test_pyodbc_connect(self): u = url.make_url('mssql://username:password@hostspec/database') dialect = mssql.MSSQLDialect_pyodbc() connection = dialect.create_connect_args(u) - self.assertEquals([['DRIVER={SQL Server};Server=hostspec;Database=database;UID=username;PWD=password'], {}], connection) + eq_([['DRIVER={SQL Server};Server=hostspec;Database=database;UID=username;PWD=password'], {}], connection) def test_pyodbc_connect_comma_port(self): u = url.make_url('mssql://username:password@hostspec:12345/database') dialect = mssql.MSSQLDialect_pyodbc() connection = dialect.create_connect_args(u) - self.assertEquals([['DRIVER={SQL Server};Server=hostspec,12345;Database=database;UID=username;PWD=password'], {}], connection) + eq_([['DRIVER={SQL Server};Server=hostspec,12345;Database=database;UID=username;PWD=password'], {}], connection) def test_pyodbc_connect_config_port(self): u = url.make_url('mssql://username:password@hostspec/database?port=12345') dialect = mssql.MSSQLDialect_pyodbc() connection = dialect.create_connect_args(u) - self.assertEquals([['DRIVER={SQL Server};Server=hostspec;Database=database;UID=username;PWD=password;port=12345'], {}], connection) + eq_([['DRIVER={SQL Server};Server=hostspec;Database=database;UID=username;PWD=password;port=12345'], {}], connection) def test_pyodbc_extra_connect(self): u = url.make_url('mssql://username:password@hostspec/database?LANGUAGE=us_english&foo=bar') dialect = mssql.MSSQLDialect_pyodbc() connection = dialect.create_connect_args(u) - self.assertEquals([['DRIVER={SQL Server};Server=hostspec;Database=database;UID=username;PWD=password;foo=bar;LANGUAGE=us_english'], {}], connection) + eq_([['DRIVER={SQL Server};Server=hostspec;Database=database;UID=username;PWD=password;foo=bar;LANGUAGE=us_english'], {}], connection) def test_pyodbc_odbc_connect(self): u = url.make_url('mssql:///?odbc_connect=DRIVER%3D%7BSQL+Server%7D%3BServer%3Dhostspec%3BDatabase%3Ddatabase%3BUID%3Dusername%3BPWD%3Dpassword') dialect = mssql.MSSQLDialect_pyodbc() connection = dialect.create_connect_args(u) - self.assertEquals([['DRIVER={SQL Server};Server=hostspec;Database=database;UID=username;PWD=password'], {}], connection) + eq_([['DRIVER={SQL Server};Server=hostspec;Database=database;UID=username;PWD=password'], {}], connection) def test_pyodbc_odbc_connect_with_dsn(self): u = url.make_url('mssql:///?odbc_connect=dsn%3Dmydsn%3BDatabase%3Ddatabase%3BUID%3Dusername%3BPWD%3Dpassword') dialect = mssql.MSSQLDialect_pyodbc() connection = dialect.create_connect_args(u) - self.assertEquals([['dsn=mydsn;Database=database;UID=username;PWD=password'], {}], connection) + eq_([['dsn=mydsn;Database=database;UID=username;PWD=password'], {}], connection) def test_pyodbc_odbc_connect_ignores_other_values(self): u = url.make_url('mssql://userdiff:passdiff@localhost/dbdiff?odbc_connect=DRIVER%3D%7BSQL+Server%7D%3BServer%3Dhostspec%3BDatabase%3Ddatabase%3BUID%3Dusername%3BPWD%3Dpassword') dialect = mssql.MSSQLDialect_pyodbc() connection = dialect.create_connect_args(u) - self.assertEquals([['DRIVER={SQL Server};Server=hostspec;Database=database;UID=username;PWD=password'], {}], connection) + eq_([['DRIVER={SQL Server};Server=hostspec;Database=database;UID=username;PWD=password'], {}], connection) class TypesTest(TestBase): __only_on__ = 'mssql' - def setUpAll(self): + @classmethod + def setup_class(cls): global numeric_table, metadata metadata = MetaData(testing.db) - def tearDown(self): + def teardown(self): metadata.drop_all() def test_decimal_notation(self): @@ -611,7 +617,7 @@ class TypesTest(TestBase): numeric_table.insert().execute(numericcol=value) for value in select([numeric_table.c.numericcol]).execute(): - self.assertTrue(value[0] in test_items, "%s not in test_items" % value[0]) + assert value[0] in test_items, "%s not in test_items" % value[0] except Exception, e: raise e @@ -763,7 +769,7 @@ class TypesTest2(TestBase, AssertsExecutionResults): t.insert().execute(adate=d1, adatetime=d2, atime=t1) - self.assertEquals(select([t.c.adate, t.c.atime, t.c.adatetime], t.c.adate==d1).execute().fetchall(), [(d1, t1, d2)]) + eq_(select([t.c.adate, t.c.atime, t.c.adatetime], t.c.adate==d1).execute().fetchall(), [(d1, t1, d2)]) finally: t.drop(checkfirst=True) @@ -1072,7 +1078,8 @@ def colspec(c): class BinaryTest(TestBase, AssertsExecutionResults): """Test the Binary and VarBinary types""" - def setUpAll(self): + @classmethod + def setup_class(cls): global binary_table, MyPickleType class MyPickleType(types.TypeDecorator): @@ -1102,10 +1109,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() def test_binary(self): @@ -1124,23 +1132,21 @@ 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'])) + eq_(list(stream1), list(l[0]['data'])) paddedstream = list(stream1[0:100]) paddedstream.extend(['\x00'] * (100 - len(paddedstream))) - self.assertEquals(paddedstream, list(l[0]['data_slice'])) + eq_(paddedstream, list(l[0]['data_slice'])) - self.assertEquals(list(stream2), list(l[1]['data'])) - self.assertEquals(list(stream2), list(l[1]['data_image'])) - 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(stream2), list(l[1]['data'])) + eq_(list(stream2), list(l[1]['data_image'])) + 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=3000): - f = os.path.join(os.path.dirname(testenv.__file__), name) + f = os.path.join(os.path.dirname(__file__), "..", name) return file(f).read(len) -if __name__ == "__main__": - testenv.main() diff --git a/test/dialect/mysql.py b/test/dialect/test_mysql.py index fa8a85ec4..8adb2d71c 100644 --- a/test/dialect/mysql.py +++ b/test/dialect/test_mysql.py @@ -1,10 +1,10 @@ -import testenv; testenv.configure_for_tests() +from sqlalchemy.test.testing import eq_ import sets from sqlalchemy import * from sqlalchemy import sql, exc from sqlalchemy.databases import mysql -from testlib.testing import eq_ -from testlib import * +from sqlalchemy.test.testing import eq_ +from sqlalchemy.test import * class TypesTest(TestBase, AssertsExecutionResults): @@ -522,7 +522,7 @@ class TypesTest(TestBase, AssertsExecutionResults): [set_table.c.s3], set_table.c.s3.in_([set(['5']), set(['5', '7'])])).execute()) found = set([frozenset(row[0]) for row in rows]) - self.assertEquals(found, + eq_(found, set([frozenset(['5']), frozenset(['5', '7'])])) finally: meta.drop_all() @@ -812,7 +812,7 @@ class TypesTest(TestBase, AssertsExecutionResults): if got != wanted: print "Expected %s" % wanted print "Found %s" % got - self.assertEqual(got, wanted) + eq_(got, wanted) class SQLTest(TestBase, AssertsCompiledSQL): @@ -831,24 +831,24 @@ class SQLTest(TestBase, AssertsCompiledSQL): kw['prefixes'] = prefixes return str(select(['q'], **kw).compile(dialect=dialect)) - self.assertEqual(gen(None), 'SELECT q') - self.assertEqual(gen(True), 'SELECT DISTINCT q') - self.assertEqual(gen(1), 'SELECT DISTINCT q') - self.assertEqual(gen('diSTInct'), 'SELECT DISTINCT q') - self.assertEqual(gen('DISTINCT'), 'SELECT DISTINCT q') + eq_(gen(None), 'SELECT q') + eq_(gen(True), 'SELECT DISTINCT q') + eq_(gen(1), 'SELECT DISTINCT q') + eq_(gen('diSTInct'), 'SELECT DISTINCT q') + eq_(gen('DISTINCT'), 'SELECT DISTINCT q') # Standard SQL - self.assertEqual(gen('all'), 'SELECT ALL q') - self.assertEqual(gen('distinctrow'), 'SELECT DISTINCTROW q') + eq_(gen('all'), 'SELECT ALL q') + eq_(gen('distinctrow'), 'SELECT DISTINCTROW q') # Interaction with MySQL prefix extensions - self.assertEqual( + eq_( gen(None, ['straight_join']), 'SELECT straight_join q') - self.assertEqual( + eq_( gen('all', ['HIGH_PRIORITY SQL_SMALL_RESULT']), 'SELECT HIGH_PRIORITY SQL_SMALL_RESULT ALL q') - self.assertEqual( + eq_( gen(True, ['high_priority', sql.text('sql_cache')]), 'SELECT high_priority sql_cache DISTINCT q') @@ -997,7 +997,7 @@ class SQLTest(TestBase, AssertsCompiledSQL): class RawReflectionTest(TestBase): - def setUp(self): + def setup(self): self.dialect = mysql.dialect() self.reflector = mysql.MySQLSchemaReflector( self.dialect.identifier_preparer) @@ -1059,7 +1059,8 @@ class ExecutionTest(TestBase): class MatchTest(TestBase, AssertsCompiledSQL): __only_on__ = 'mysql' - def setUpAll(self): + @classmethod + def setup_class(cls): global metadata, cattable, matchtable metadata = MetaData(testing.db) @@ -1096,7 +1097,8 @@ class MatchTest(TestBase, AssertsCompiledSQL): 'category_id': 1} ]) - def tearDownAll(self): + @classmethod + def teardown_class(cls): metadata.drop_all() def test_expression(self): @@ -1110,14 +1112,14 @@ class MatchTest(TestBase, AssertsCompiledSQL): order_by(matchtable.c.id). execute(). fetchall()) - self.assertEquals([2, 5], [r.id for r in results]) + eq_([2, 5], [r.id for r in results]) def test_simple_match_with_apostrophe(self): results = (matchtable.select(). where(matchtable.c.title.match('"Matz''s"')). execute(). fetchall()) - self.assertEquals([3], [r.id for r in results]) + eq_([3], [r.id for r in results]) def test_or_match(self): results1 = (matchtable.select(). @@ -1126,13 +1128,13 @@ class MatchTest(TestBase, AssertsCompiledSQL): order_by(matchtable.c.id). execute(). fetchall()) - self.assertEquals([3, 5], [r.id for r in results1]) + eq_([3, 5], [r.id for r in results1]) results2 = (matchtable.select(). where(matchtable.c.title.match('nutshell ruby')). order_by(matchtable.c.id). execute(). fetchall()) - self.assertEquals([3, 5], [r.id for r in results2]) + eq_([3, 5], [r.id for r in results2]) def test_and_match(self): @@ -1141,12 +1143,12 @@ class MatchTest(TestBase, AssertsCompiledSQL): matchtable.c.title.match('nutshell'))). execute(). fetchall()) - self.assertEquals([5], [r.id for r in results1]) + eq_([5], [r.id for r in results1]) results2 = (matchtable.select(). where(matchtable.c.title.match('+python +nutshell')). execute(). fetchall()) - self.assertEquals([5], [r.id for r in results2]) + eq_([5], [r.id for r in results2]) def test_match_across_joins(self): results = (matchtable.select(). @@ -1156,12 +1158,10 @@ class MatchTest(TestBase, AssertsCompiledSQL): order_by(matchtable.c.id). execute(). fetchall()) - self.assertEquals([1, 3, 5], [r.id for r in results]) + eq_([1, 3, 5], [r.id for r in results]) def colspec(c): return testing.db.dialect.schemagenerator(testing.db.dialect, testing.db, None, None).get_column_specification(c) -if __name__ == "__main__": - testenv.main() diff --git a/test/dialect/oracle.py b/test/dialect/test_oracle.py index 2186f2259..16175c851 100644 --- a/test/dialect/oracle.py +++ b/test/dialect/test_oracle.py @@ -1,19 +1,20 @@ # coding: utf-8 -import testenv; testenv.configure_for_tests() +from sqlalchemy.test.testing import eq_ from sqlalchemy import * from sqlalchemy.sql import table, column from sqlalchemy.databases import oracle -from testlib import * -from testlib.testing import eq_ -from testlib.engines import testing_engine +from sqlalchemy.test import * +from sqlalchemy.test.testing import eq_ +from sqlalchemy.test.engines import testing_engine import os class OutParamTest(TestBase, AssertsExecutionResults): __only_on__ = 'oracle' - def setUpAll(self): + @classmethod + def setup_class(cls): testing.db.execute(""" create or replace procedure foo(x_in IN number, x_out OUT number, y_out OUT number, z_out OUT varchar) IS retval number; @@ -29,7 +30,8 @@ create or replace procedure foo(x_in IN number, x_out OUT number, y_out OUT numb result = testing.db.execute(text("begin foo(:x_in, :x_out, :y_out, :z_out); end;", bindparams=[bindparam('x_in', Numeric), outparam('x_out', Numeric), outparam('y_out', Numeric), outparam('z_out', String)]), x_in=5) assert result.out_parameters == {'x_out':10, 'y_out':75, 'z_out':None}, result.out_parameters - def tearDownAll(self): + @classmethod + def teardown_class(cls): testing.db.execute("DROP PROCEDURE foo") @@ -200,7 +202,7 @@ class MultiSchemaTest(TestBase, AssertsCompiledSQL): try: parent.insert().execute({'pid':1}) child.insert().execute({'cid':1, 'pid':1}) - self.assertEquals(child.select().execute().fetchall(), [(1, 1)]) + eq_(child.select().execute().fetchall(), [(1, 1)]) finally: meta.drop_all() @@ -217,7 +219,7 @@ class MultiSchemaTest(TestBase, AssertsCompiledSQL): try: parent.insert().execute({'pid':1}) child.insert().execute({'cid':1, 'pid':1}) - self.assertEquals(child.select().execute().fetchall(), [(1, 1)]) + eq_(child.select().execute().fetchall(), [(1, 1)]) finally: meta.drop_all() @@ -346,7 +348,8 @@ class TypesTest(TestBase, AssertsCompiledSQL): class BufferedColumnTest(TestBase, AssertsCompiledSQL): __only_on__ = 'oracle' - def setUpAll(self): + @classmethod + def setup_class(cls): global binary_table, stream, meta meta = MetaData(testing.db) binary_table = Table('binary_table', meta, @@ -360,18 +363,19 @@ class BufferedColumnTest(TestBase, AssertsCompiledSQL): for i in range(1, 11): binary_table.insert().execute(id=i, data=stream) - def tearDownAll(self): + @classmethod + def teardown_class(cls): meta.drop_all() def test_fetch(self): - self.assertEquals( + eq_( binary_table.select().execute().fetchall() , [(i, stream) for i in range(1, 11)], ) def test_fetch_single_arraysize(self): eng = testing_engine(options={'arraysize':1}) - self.assertEquals( + eq_( eng.execute(binary_table.select()).fetchall(), [(i, stream) for i in range(1, 11)], ) @@ -393,5 +397,3 @@ class ExecuteTest(TestBase): def test_basic(self): assert testing.db.execute("/*+ this is a comment */ SELECT 1 FROM DUAL").fetchall() == [(1,)] -if __name__ == '__main__': - testenv.main() diff --git a/test/dialect/postgres.py b/test/dialect/test_postgres.py index 2dfbe018c..8ca714bad 100644 --- a/test/dialect/postgres.py +++ b/test/dialect/test_postgres.py @@ -1,11 +1,11 @@ -import testenv; testenv.configure_for_tests() +from sqlalchemy.test.testing import eq_, assert_raises, assert_raises_message import datetime from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy import exc from sqlalchemy.databases import postgres from sqlalchemy.engine.strategies import MockEngineStrategy -from testlib import * +from sqlalchemy.test import * from sqlalchemy.sql import table, column @@ -86,10 +86,10 @@ class ReturningTest(TestBase, AssertsExecutionResults): table.insert().execute([{'persons': 5, 'full': False}, {'persons': 3, 'full': False}]) result = table.update(table.c.persons > 4, dict(full=True), postgres_returning=[table.c.id]).execute() - self.assertEqual(result.fetchall(), [(1,)]) + eq_(result.fetchall(), [(1,)]) result2 = select([table.c.id, table.c.full]).order_by(table.c.id).execute() - self.assertEqual(result2.fetchall(), [(1,True),(2,False)]) + eq_(result2.fetchall(), [(1,True),(2,False)]) finally: table.drop() @@ -105,22 +105,22 @@ class ReturningTest(TestBase, AssertsExecutionResults): try: result = table.insert(postgres_returning=[table.c.id]).execute({'persons': 1, 'full': False}) - self.assertEqual(result.fetchall(), [(1,)]) + eq_(result.fetchall(), [(1,)]) @testing.fails_on('postgres', 'Known limitation of psycopg2') def test_executemany(): # return value is documented as failing with psycopg2/executemany result2 = table.insert(postgres_returning=[table]).execute( [{'persons': 2, 'full': False}, {'persons': 3, 'full': True}]) - self.assertEqual(result2.fetchall(), [(2, 2, False), (3,3,True)]) + eq_(result2.fetchall(), [(2, 2, False), (3,3,True)]) test_executemany() result3 = table.insert(postgres_returning=[(table.c.id*2).label('double_id')]).execute({'persons': 4, 'full': False}) - self.assertEqual([dict(row) for row in result3], [{'double_id':8}]) + eq_([dict(row) for row in result3], [{'double_id':8}]) result4 = testing.db.execute('insert into tables (id, persons, "full") values (5, 10, true) returning persons') - self.assertEqual([dict(row) for row in result4], [{'persons': 10}]) + eq_([dict(row) for row in result4], [{'persons': 10}]) finally: table.drop() @@ -128,11 +128,12 @@ class ReturningTest(TestBase, AssertsExecutionResults): class InsertTest(TestBase, AssertsExecutionResults): __only_on__ = 'postgres' - def setUpAll(self): + @classmethod + def setup_class(cls): global metadata metadata = MetaData(testing.db) - def tearDown(self): + def teardown(self): metadata.drop_all() metadata.tables.clear() @@ -397,7 +398,8 @@ class DomainReflectionTest(TestBase, AssertsExecutionResults): __only_on__ = 'postgres' - def setUpAll(self): + @classmethod + def setup_class(cls): con = testing.db.connect() for ddl in ('CREATE DOMAIN testdomain INTEGER NOT NULL DEFAULT 42', 'CREATE DOMAIN alt_schema.testdomain INTEGER DEFAULT 0'): @@ -410,7 +412,8 @@ class DomainReflectionTest(TestBase, AssertsExecutionResults): con.execute('CREATE TABLE alt_schema.testtable(question integer, answer alt_schema.testdomain, anything integer)') con.execute('CREATE TABLE crosschema (question integer, answer alt_schema.testdomain)') - def tearDownAll(self): + @classmethod + def teardown_class(cls): con = testing.db.connect() con.execute('DROP TABLE testtable') con.execute('DROP TABLE alt_schema.testtable') @@ -421,32 +424,32 @@ class DomainReflectionTest(TestBase, AssertsExecutionResults): def test_table_is_reflected(self): metadata = MetaData(testing.db) table = Table('testtable', metadata, autoload=True) - self.assertEquals(set(table.columns.keys()), set(['question', 'answer']), "Columns of reflected table didn't equal expected columns") - self.assertEquals(table.c.answer.type.__class__, postgres.PGInteger) + eq_(set(table.columns.keys()), set(['question', 'answer']), "Columns of reflected table didn't equal expected columns") + eq_(table.c.answer.type.__class__, postgres.PGInteger) def test_domain_is_reflected(self): metadata = MetaData(testing.db) table = Table('testtable', metadata, autoload=True) - self.assertEquals(str(table.columns.answer.server_default.arg), '42', "Reflected default value didn't equal expected value") - self.assertFalse(table.columns.answer.nullable, "Expected reflected column to not be nullable.") + eq_(str(table.columns.answer.server_default.arg), '42', "Reflected default value didn't equal expected value") + assert not table.columns.answer.nullable, "Expected reflected column to not be nullable." def test_table_is_reflected_alt_schema(self): metadata = MetaData(testing.db) table = Table('testtable', metadata, autoload=True, schema='alt_schema') - self.assertEquals(set(table.columns.keys()), set(['question', 'answer', 'anything']), "Columns of reflected table didn't equal expected columns") - self.assertEquals(table.c.anything.type.__class__, postgres.PGInteger) + eq_(set(table.columns.keys()), set(['question', 'answer', 'anything']), "Columns of reflected table didn't equal expected columns") + eq_(table.c.anything.type.__class__, postgres.PGInteger) def test_schema_domain_is_reflected(self): metadata = MetaData(testing.db) table = Table('testtable', metadata, autoload=True, schema='alt_schema') - self.assertEquals(str(table.columns.answer.server_default.arg), '0', "Reflected default value didn't equal expected value") - self.assertTrue(table.columns.answer.nullable, "Expected reflected column to be nullable.") + eq_(str(table.columns.answer.server_default.arg), '0', "Reflected default value didn't equal expected value") + assert table.columns.answer.nullable, "Expected reflected column to be nullable." def test_crosschema_domain_is_reflected(self): metadata = MetaData(testing.db) table = Table('crosschema', metadata, autoload=True) - self.assertEquals(str(table.columns.answer.server_default.arg), '0', "Reflected default value didn't equal expected value") - self.assertTrue(table.columns.answer.nullable, "Expected reflected column to be nullable.") + eq_(str(table.columns.answer.server_default.arg), '0', "Reflected default value didn't equal expected value") + assert table.columns.answer.nullable, "Expected reflected column to be nullable." def test_unknown_types(self): from sqlalchemy.databases import postgres @@ -455,7 +458,7 @@ class DomainReflectionTest(TestBase, AssertsExecutionResults): postgres.ischema_names = {} try: m2 = MetaData(testing.db) - self.assertRaises(exc.SAWarning, Table, "testtable", m2, autoload=True) + assert_raises(exc.SAWarning, Table, "testtable", m2, autoload=True) @testing.emits_warning('Did not recognize type') def warns(): @@ -519,15 +522,15 @@ class MiscTest(TestBase, AssertsExecutionResults): t = Table('mytable', MetaData(testing.db), Column('id', Integer, primary_key=True), Column('a', String(8))) - self.assertEquals( + eq_( str(t.select(distinct=t.c.a)), 'SELECT DISTINCT ON (mytable.a) mytable.id, mytable.a \n' 'FROM mytable') - self.assertEquals( + eq_( str(t.select(distinct=['id','a'])), 'SELECT DISTINCT ON (id, a) mytable.id, mytable.a \n' 'FROM mytable') - self.assertEquals( + eq_( str(t.select(distinct=[t.c.id, t.c.a])), 'SELECT DISTINCT ON (mytable.id, mytable.a) mytable.id, mytable.a \n' 'FROM mytable') @@ -616,14 +619,14 @@ class MiscTest(TestBase, AssertsExecutionResults): users.insert().execute(id=3, name='name3') users.insert().execute(id=4, name='name4') - self.assertEquals(users.select().where(users.c.name=='name2').execute().fetchall(), [(2, 'name2')]) - self.assertEquals(users.select(use_labels=True).where(users.c.name=='name2').execute().fetchall(), [(2, 'name2')]) + eq_(users.select().where(users.c.name=='name2').execute().fetchall(), [(2, 'name2')]) + eq_(users.select(use_labels=True).where(users.c.name=='name2').execute().fetchall(), [(2, 'name2')]) users.delete().where(users.c.id==3).execute() - self.assertEquals(users.select().where(users.c.name=='name3').execute().fetchall(), []) + eq_(users.select().where(users.c.name=='name3').execute().fetchall(), []) users.update().where(users.c.name=='name4').execute(name='newname') - self.assertEquals(users.select(use_labels=True).where(users.c.id==4).execute().fetchall(), [(4, 'newname')]) + eq_(users.select(use_labels=True).where(users.c.id==4).execute().fetchall(), [(4, 'newname')]) finally: users.drop() @@ -733,7 +736,8 @@ class TimezoneTest(TestBase, AssertsExecutionResults): __only_on__ = 'postgres' - def setUpAll(self): + @classmethod + def setup_class(cls): global tztable, notztable, metadata metadata = MetaData(testing.db) @@ -749,7 +753,8 @@ class TimezoneTest(TestBase, AssertsExecutionResults): Column("name", String(20)), ) metadata.create_all() - def tearDownAll(self): + @classmethod + def teardown_class(cls): metadata.drop_all() def test_with_timezone(self): @@ -769,7 +774,8 @@ class TimezoneTest(TestBase, AssertsExecutionResults): class ArrayTest(TestBase, AssertsExecutionResults): __only_on__ = 'postgres' - def setUpAll(self): + @classmethod + def setup_class(cls): global metadata, arrtable metadata = MetaData(testing.db) @@ -779,47 +785,48 @@ class ArrayTest(TestBase, AssertsExecutionResults): Column('strarr', postgres.PGArray(String(convert_unicode=True)), nullable=False) ) metadata.create_all() - def tearDownAll(self): + @classmethod + def teardown_class(cls): metadata.drop_all() def test_reflect_array_column(self): metadata2 = MetaData(testing.db) tbl = Table('arrtable', metadata2, autoload=True) - self.assertTrue(isinstance(tbl.c.intarr.type, postgres.PGArray)) - self.assertTrue(isinstance(tbl.c.strarr.type, postgres.PGArray)) - self.assertTrue(isinstance(tbl.c.intarr.type.item_type, Integer)) - self.assertTrue(isinstance(tbl.c.strarr.type.item_type, String)) + assert isinstance(tbl.c.intarr.type, postgres.PGArray) + assert isinstance(tbl.c.strarr.type, postgres.PGArray) + assert isinstance(tbl.c.intarr.type.item_type, Integer) + assert isinstance(tbl.c.strarr.type.item_type, String) def test_insert_array(self): arrtable.insert().execute(intarr=[1,2,3], strarr=['abc', 'def']) results = arrtable.select().execute().fetchall() - self.assertEquals(len(results), 1) - self.assertEquals(results[0]['intarr'], [1,2,3]) - self.assertEquals(results[0]['strarr'], ['abc','def']) + eq_(len(results), 1) + eq_(results[0]['intarr'], [1,2,3]) + eq_(results[0]['strarr'], ['abc','def']) arrtable.delete().execute() def test_array_where(self): arrtable.insert().execute(intarr=[1,2,3], strarr=['abc', 'def']) arrtable.insert().execute(intarr=[4,5,6], strarr='ABC') results = arrtable.select().where(arrtable.c.intarr == [1,2,3]).execute().fetchall() - self.assertEquals(len(results), 1) - self.assertEquals(results[0]['intarr'], [1,2,3]) + eq_(len(results), 1) + eq_(results[0]['intarr'], [1,2,3]) arrtable.delete().execute() def test_array_concat(self): arrtable.insert().execute(intarr=[1,2,3], strarr=['abc', 'def']) results = select([arrtable.c.intarr + [4,5,6]]).execute().fetchall() - self.assertEquals(len(results), 1) - self.assertEquals(results[0][0], [1,2,3,4,5,6]) + eq_(len(results), 1) + eq_(results[0][0], [1,2,3,4,5,6]) arrtable.delete().execute() def test_array_subtype_resultprocessor(self): arrtable.insert().execute(intarr=[4,5,6], strarr=[[u'm\xe4\xe4'], [u'm\xf6\xf6']]) arrtable.insert().execute(intarr=[1,2,3], strarr=[u'm\xe4\xe4', u'm\xf6\xf6']) results = arrtable.select(order_by=[arrtable.c.intarr]).execute().fetchall() - self.assertEquals(len(results), 2) - self.assertEquals(results[0]['strarr'], [u'm\xe4\xe4', u'm\xf6\xf6']) - self.assertEquals(results[1]['strarr'], [[u'm\xe4\xe4'], [u'm\xf6\xf6']]) + eq_(len(results), 2) + eq_(results[0]['strarr'], [u'm\xe4\xe4', u'm\xf6\xf6']) + eq_(results[1]['strarr'], [[u'm\xe4\xe4'], [u'm\xf6\xf6']]) arrtable.delete().execute() def test_array_mutability(self): @@ -839,23 +846,23 @@ class ArrayTest(TestBase, AssertsExecutionResults): sess.flush() sess.expunge_all() foo = sess.query(Foo).get(1) - self.assertEquals(foo.intarr, [1,2,3]) + eq_(foo.intarr, [1,2,3]) foo.intarr.append(4) sess.flush() sess.expunge_all() foo = sess.query(Foo).get(1) - self.assertEquals(foo.intarr, [1,2,3,4]) + eq_(foo.intarr, [1,2,3,4]) foo.intarr = [] sess.flush() sess.expunge_all() - self.assertEquals(foo.intarr, []) + eq_(foo.intarr, []) foo.intarr = None sess.flush() sess.expunge_all() - self.assertEquals(foo.intarr, None) + eq_(foo.intarr, None) # Errors in r4217: foo = Foo() @@ -872,16 +879,18 @@ class TimeStampTest(TestBase, AssertsExecutionResults): connection = engine.connect() s = select([func.TIMESTAMP("12/25/07").label("ts")]) result = connection.execute(s).fetchone() - self.assertEqual(result[0], datetime.datetime(2007, 12, 25, 0, 0)) + eq_(result[0], datetime.datetime(2007, 12, 25, 0, 0)) class ServerSideCursorsTest(TestBase, AssertsExecutionResults): __only_on__ = 'postgres' - def setUpAll(self): + @classmethod + def setup_class(cls): global ss_engine ss_engine = engines.testing_engine(options={'server_side_cursors':True}) - def tearDownAll(self): + @classmethod + def teardown_class(cls): ss_engine.dispose() def test_uses_ss(self): @@ -906,12 +915,12 @@ class ServerSideCursorsTest(TestBase, AssertsExecutionResults): nextid = ss_engine.execute(Sequence('test_table_id_seq')) test_table.insert().execute(id=nextid, data='data2') - self.assertEquals(test_table.select().execute().fetchall(), [(1, 'data1'), (2, 'data2')]) + eq_(test_table.select().execute().fetchall(), [(1, 'data1'), (2, 'data2')]) test_table.update().where(test_table.c.id==2).values(data=test_table.c.data + ' updated').execute() - self.assertEquals(test_table.select().execute().fetchall(), [(1, 'data1'), (2, 'data2 updated')]) + eq_(test_table.select().execute().fetchall(), [(1, 'data1'), (2, 'data2 updated')]) test_table.delete().execute() - self.assertEquals(test_table.count().scalar(), 0) + eq_(test_table.count().scalar(), 0) finally: test_table.drop(checkfirst=True) @@ -921,7 +930,8 @@ class SpecialTypesTest(TestBase, ComparesTables): __only_on__ = 'postgres' __excluded_on__ = (('postgres', '<', (8, 3, 0)),) - def setUpAll(self): + @classmethod + def setup_class(cls): global metadata, table metadata = MetaData(testing.db) @@ -935,7 +945,8 @@ class SpecialTypesTest(TestBase, ComparesTables): metadata.create_all() - def tearDownAll(self): + @classmethod + def teardown_class(cls): metadata.drop_all() def test_reflection(self): @@ -949,7 +960,8 @@ class MatchTest(TestBase, AssertsCompiledSQL): __only_on__ = 'postgres' __excluded_on__ = (('postgres', '<', (8, 3, 0)),) - def setUpAll(self): + @classmethod + def setup_class(cls): global metadata, cattable, matchtable metadata = MetaData(testing.db) @@ -976,7 +988,8 @@ class MatchTest(TestBase, AssertsCompiledSQL): {'id': 5, 'title': 'Python in a Nutshell', 'category_id': 1} ]) - def tearDownAll(self): + @classmethod + def teardown_class(cls): metadata.drop_all() def test_expression(self): @@ -984,42 +997,40 @@ class MatchTest(TestBase, AssertsCompiledSQL): def test_simple_match(self): results = matchtable.select().where(matchtable.c.title.match('python')).order_by(matchtable.c.id).execute().fetchall() - self.assertEquals([2, 5], [r.id for r in results]) + eq_([2, 5], [r.id for r in results]) def test_simple_match_with_apostrophe(self): results = matchtable.select().where(matchtable.c.title.match("Matz''s")).execute().fetchall() - self.assertEquals([3], [r.id for r in results]) + eq_([3], [r.id for r in results]) def test_simple_derivative_match(self): results = matchtable.select().where(matchtable.c.title.match('nutshells')).execute().fetchall() - self.assertEquals([5], [r.id for r in results]) + eq_([5], [r.id for r in results]) def test_or_match(self): results1 = matchtable.select().where(or_(matchtable.c.title.match('nutshells'), matchtable.c.title.match('rubies')) ).order_by(matchtable.c.id).execute().fetchall() - self.assertEquals([3, 5], [r.id for r in results1]) + eq_([3, 5], [r.id for r in results1]) results2 = matchtable.select().where(matchtable.c.title.match('nutshells | rubies'), ).order_by(matchtable.c.id).execute().fetchall() - self.assertEquals([3, 5], [r.id for r in results2]) + eq_([3, 5], [r.id for r in results2]) def test_and_match(self): results1 = matchtable.select().where(and_(matchtable.c.title.match('python'), matchtable.c.title.match('nutshells')) ).execute().fetchall() - self.assertEquals([5], [r.id for r in results1]) + eq_([5], [r.id for r in results1]) results2 = matchtable.select().where(matchtable.c.title.match('python & nutshells'), ).execute().fetchall() - self.assertEquals([5], [r.id for r in results2]) + eq_([5], [r.id for r in results2]) def test_match_across_joins(self): results = matchtable.select().where(and_(cattable.c.id==matchtable.c.category_id, or_(cattable.c.description.match('Ruby'), matchtable.c.title.match('nutshells'))) ).order_by(matchtable.c.id).execute().fetchall() - self.assertEquals([1, 3, 5], [r.id for r in results]) + eq_([1, 3, 5], [r.id for r in results]) -if __name__ == "__main__": - testenv.main() diff --git a/test/dialect/sqlite.py b/test/dialect/test_sqlite.py index d01be3521..eb4581e20 100644 --- a/test/dialect/sqlite.py +++ b/test/dialect/test_sqlite.py @@ -1,11 +1,11 @@ """SQLite-specific tests.""" -import testenv; testenv.configure_for_tests() +from sqlalchemy.test.testing import eq_, assert_raises, assert_raises_message import datetime from sqlalchemy import * from sqlalchemy import exc, sql from sqlalchemy.databases import sqlite -from testlib import * +from sqlalchemy.test import * class TestTypes(TestBase, AssertsExecutionResults): @@ -34,22 +34,22 @@ class TestTypes(TestBase, AssertsExecutionResults): meta.drop_all() def test_string_dates_raise(self): - self.assertRaises(TypeError, testing.db.execute, select([1]).where(bindparam("date", type_=Date)), date=str(datetime.date(2007, 10, 30))) + assert_raises(TypeError, testing.db.execute, select([1]).where(bindparam("date", type_=Date)), date=str(datetime.date(2007, 10, 30))) def test_time_microseconds(self): dt = datetime.datetime(2008, 6, 27, 12, 0, 0, 125) # 125 usec - self.assertEquals(str(dt), '2008-06-27 12:00:00.000125') + eq_(str(dt), '2008-06-27 12:00:00.000125') sldt = sqlite.SLDateTime() bp = sldt.bind_processor(None) - self.assertEquals(bp(dt), '2008-06-27 12:00:00.000125') + eq_(bp(dt), '2008-06-27 12:00:00.000125') rp = sldt.result_processor(None) - self.assertEquals(rp(bp(dt)), dt) + eq_(rp(bp(dt)), dt) sldt.__legacy_microseconds__ = True bp = sldt.bind_processor(None) - self.assertEquals(bp(dt), '2008-06-27 12:00:00.125') - self.assertEquals(rp(bp(dt)), dt) + eq_(bp(dt), '2008-06-27 12:00:00.125') + eq_(rp(bp(dt)), dt) def test_no_convert_unicode(self): """test no utf-8 encoding occurs""" @@ -163,7 +163,7 @@ class TestDefaults(TestBase, AssertsExecutionResults): rt = Table('t_defaults', m2, autoload=True) expected = [c[1] for c in specs] for i, reflected in enumerate(rt.c): - self.assertEquals(reflected.server_default.arg.text, expected[i]) + eq_(reflected.server_default.arg.text, expected[i]) finally: m.drop_all() @@ -184,7 +184,7 @@ class TestDefaults(TestBase, AssertsExecutionResults): rt = Table('r_defaults', m, autoload=True) for i, reflected in enumerate(rt.c): - self.assertEquals(reflected.server_default.arg.text, expected[i]) + eq_(reflected.server_default.arg.text, expected[i]) finally: db.execute("DROP TABLE r_defaults") @@ -258,7 +258,7 @@ class DialectTest(TestBase, AssertsExecutionResults): schema='alt_schema') meta.create_all(cx) - self.assertEquals(dialect.table_names(cx, 'alt_schema'), + eq_(dialect.table_names(cx, 'alt_schema'), ['created']) assert len(alt_master.c) > 0 @@ -350,7 +350,7 @@ class InsertTest(TestBase, AssertsExecutionResults): table.insert().execute() rows = table.select().execute().fetchall() - self.assertEquals(len(rows), wanted) + eq_(len(rows), wanted) finally: table.drop() @@ -362,7 +362,7 @@ class InsertTest(TestBase, AssertsExecutionResults): @testing.exclude('sqlite', '<', (3, 3, 8), 'no database support') def test_empty_insert_pk2(self): - self.assertRaises( + assert_raises( exc.DBAPIError, self._test_empty_insert, Table('b', MetaData(testing.db), @@ -371,7 +371,7 @@ class InsertTest(TestBase, AssertsExecutionResults): @testing.exclude('sqlite', '<', (3, 3, 8), 'no database support') def test_empty_insert_pk3(self): - self.assertRaises( + assert_raises( exc.DBAPIError, self._test_empty_insert, Table('c', MetaData(testing.db), @@ -429,7 +429,8 @@ class MatchTest(TestBase, AssertsCompiledSQL): __only_on__ = 'sqlite' __skip_if__ = (full_text_search_missing, ) - def setUpAll(self): + @classmethod + def setup_class(cls): global metadata, cattable, matchtable metadata = MetaData(testing.db) @@ -465,7 +466,8 @@ class MatchTest(TestBase, AssertsCompiledSQL): {'id': 5, 'title': 'Python in a Nutshell', 'category_id': 1} ]) - def tearDownAll(self): + @classmethod + def teardown_class(cls): metadata.drop_all() def test_expression(self): @@ -473,29 +475,27 @@ class MatchTest(TestBase, AssertsCompiledSQL): def test_simple_match(self): results = matchtable.select().where(matchtable.c.title.match('python')).order_by(matchtable.c.id).execute().fetchall() - self.assertEquals([2, 5], [r.id for r in results]) + eq_([2, 5], [r.id for r in results]) def test_simple_prefix_match(self): results = matchtable.select().where(matchtable.c.title.match('nut*')).execute().fetchall() - self.assertEquals([5], [r.id for r in results]) + eq_([5], [r.id for r in results]) def test_or_match(self): results2 = matchtable.select().where(matchtable.c.title.match('nutshell OR ruby'), ).order_by(matchtable.c.id).execute().fetchall() - self.assertEquals([3, 5], [r.id for r in results2]) + eq_([3, 5], [r.id for r in results2]) def test_and_match(self): results2 = matchtable.select().where(matchtable.c.title.match('python nutshell'), ).execute().fetchall() - self.assertEquals([5], [r.id for r in results2]) + eq_([5], [r.id for r in results2]) def test_match_across_joins(self): results = matchtable.select().where(and_(cattable.c.id==matchtable.c.category_id, cattable.c.description.match('Ruby')) ).order_by(matchtable.c.id).execute().fetchall() - self.assertEquals([1, 3], [r.id for r in results]) + eq_([1, 3], [r.id for r in results]) -if __name__ == "__main__": - testenv.main() diff --git a/test/dialect/sybase.py b/test/dialect/test_sybase.py index 32b9904d8..37de91d1c 100644 --- a/test/dialect/sybase.py +++ b/test/dialect/test_sybase.py @@ -1,8 +1,7 @@ -import testenv; testenv.configure_for_tests() from sqlalchemy import * from sqlalchemy import sql from sqlalchemy.databases import sybase -from testlib import * +from sqlalchemy.test import * class CompileTest(TestBase, AssertsCompiledSQL): @@ -27,5 +26,3 @@ class CompileTest(TestBase, AssertsCompiledSQL): -if __name__ == "__main__": - testenv.main() |
