# HG changeset patch # User Zachary Ware # Date 1407518606 18000 # Fri Aug 08 12:23:26 2014 -0500 # Node ID 805debbf5b8971a3dd37ba725b6cbe738acf768e # Parent 3b1c44248635e9b3eaa158d70e9efc8d701b5c5a Temp commit to export the patch diff --git a/Lib/sqlite3/test/__init__.py b/Lib/sqlite3/test/__init__.py deleted file mode 100644 diff --git a/Lib/test/test_sqlite.py b/Lib/test/test_sqlite3/__init__.py rename from Lib/test/test_sqlite.py rename to Lib/test/test_sqlite3/__init__.py --- a/Lib/test/test_sqlite.py +++ b/Lib/test/test_sqlite3/__init__.py @@ -1,24 +1,12 @@ -import test.support +import os +from test import support -# Skip test if _sqlite3 module not installed -test.support.import_module('_sqlite3') - -import unittest -import sqlite3 -from sqlite3.test import (dbapi, types, userfunctions, - factory, transactions, hooks, regression, - dump) +# skip tests if _sqlite3 is not available +sqlite3 = support.import_module('sqlite3') def load_tests(*args): - if test.support.verbose: + if support.verbose: print("test_sqlite: testing with version", "{!r}, sqlite_version {!r}".format(sqlite3.version, sqlite3.sqlite_version)) - return unittest.TestSuite([dbapi.suite(), types.suite(), - userfunctions.suite(), - factory.suite(), transactions.suite(), - hooks.suite(), regression.suite(), - dump.suite()]) - -if __name__ == "__main__": - unittest.main() + return support.load_package_tests(os.path.dirname(__file__), *args) diff --git a/Lib/test/test_sqlite3/__main__.py b/Lib/test/test_sqlite3/__main__.py new file mode 100644 --- /dev/null +++ b/Lib/test/test_sqlite3/__main__.py @@ -0,0 +1,4 @@ +from . import load_tests +import unittest + +unittest.main() diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/test/test_sqlite3/test_dbapi.py rename from Lib/sqlite3/test/dbapi.py rename to Lib/test/test_sqlite3/test_dbapi.py --- a/Lib/sqlite3/test/dbapi.py +++ b/Lib/test/test_sqlite3/test_dbapi.py @@ -32,56 +32,56 @@ class ModuleTests(unittest.TestCase): - def CheckAPILevel(self): + def testAPILevel(self): self.assertEqual(sqlite.apilevel, "2.0", "apilevel is %s, should be 2.0" % sqlite.apilevel) - def CheckThreadSafety(self): + def testThreadSafety(self): self.assertEqual(sqlite.threadsafety, 1, "threadsafety is %d, should be 1" % sqlite.threadsafety) - def CheckParamStyle(self): + def testParamStyle(self): self.assertEqual(sqlite.paramstyle, "qmark", "paramstyle is '%s', should be 'qmark'" % sqlite.paramstyle) - def CheckWarning(self): + def testWarning(self): self.assertTrue(issubclass(sqlite.Warning, Exception), "Warning is not a subclass of Exception") - def CheckError(self): + def testError(self): self.assertTrue(issubclass(sqlite.Error, Exception), "Error is not a subclass of Exception") - def CheckInterfaceError(self): + def testInterfaceError(self): self.assertTrue(issubclass(sqlite.InterfaceError, sqlite.Error), "InterfaceError is not a subclass of Error") - def CheckDatabaseError(self): + def testDatabaseError(self): self.assertTrue(issubclass(sqlite.DatabaseError, sqlite.Error), "DatabaseError is not a subclass of Error") - def CheckDataError(self): + def testDataError(self): self.assertTrue(issubclass(sqlite.DataError, sqlite.DatabaseError), "DataError is not a subclass of DatabaseError") - def CheckOperationalError(self): + def testOperationalError(self): self.assertTrue(issubclass(sqlite.OperationalError, sqlite.DatabaseError), "OperationalError is not a subclass of DatabaseError") - def CheckIntegrityError(self): + def testIntegrityError(self): self.assertTrue(issubclass(sqlite.IntegrityError, sqlite.DatabaseError), "IntegrityError is not a subclass of DatabaseError") - def CheckInternalError(self): + def testInternalError(self): self.assertTrue(issubclass(sqlite.InternalError, sqlite.DatabaseError), "InternalError is not a subclass of DatabaseError") - def CheckProgrammingError(self): + def testProgrammingError(self): self.assertTrue(issubclass(sqlite.ProgrammingError, sqlite.DatabaseError), "ProgrammingError is not a subclass of DatabaseError") - def CheckNotSupportedError(self): + def testNotSupportedError(self): self.assertTrue(issubclass(sqlite.NotSupportedError, sqlite.DatabaseError), "NotSupportedError is not a subclass of DatabaseError") @@ -97,30 +97,30 @@ def tearDown(self): self.cx.close() - def CheckCommit(self): + def testCommit(self): self.cx.commit() - def CheckCommitAfterNoChanges(self): + def testCommitAfterNoChanges(self): """ A commit should also work when no changes were made to the database. """ self.cx.commit() self.cx.commit() - def CheckRollback(self): + def testRollback(self): self.cx.rollback() - def CheckRollbackAfterNoChanges(self): + def testRollbackAfterNoChanges(self): """ A rollback should also work when no changes were made to the database. """ self.cx.rollback() self.cx.rollback() - def CheckCursor(self): + def testCursor(self): cu = self.cx.cursor() - def CheckFailedOpen(self): + def testFailedOpen(self): YOU_CANNOT_OPEN_THIS = "/foo/bar/bla/23534/mydb.db" try: con = sqlite.connect(YOU_CANNOT_OPEN_THIS) @@ -128,10 +128,10 @@ return self.fail("should have raised an OperationalError") - def CheckClose(self): + def testClose(self): self.cx.close() - def CheckExceptions(self): + def testExceptions(self): # Optional DB-API extension. self.assertEqual(self.cx.Warning, sqlite.Warning) self.assertEqual(self.cx.Error, sqlite.Error) @@ -144,7 +144,7 @@ self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError) self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError) - def CheckInTransaction(self): + def testInTransaction(self): # Can't use db from setUp because we want to test initial state. cx = sqlite.connect(":memory:") cu = cx.cursor() @@ -162,11 +162,11 @@ row = cu.fetchone() self.assertEqual(cx.in_transaction, False) - def CheckInTransactionRO(self): + def testInTransactionRO(self): with self.assertRaises(AttributeError): self.cx.in_transaction = True - def CheckOpenUri(self): + def testOpenUri(self): if sqlite.sqlite_version_info < (3, 7, 7): with self.assertRaises(sqlite.NotSupportedError): sqlite.connect(':memory:', uri=True) @@ -192,10 +192,10 @@ self.cu.close() self.cx.close() - def CheckExecuteNoArgs(self): + def testExecuteNoArgs(self): self.cu.execute("delete from test") - def CheckExecuteIllegalSql(self): + def testExecuteIllegalSql(self): try: self.cu.execute("select asdf") self.fail("should have raised an OperationalError") @@ -204,7 +204,7 @@ except: self.fail("raised wrong exception") - def CheckExecuteTooMuchSql(self): + def testExecuteTooMuchSql(self): try: self.cu.execute("select 5+4; select 4+5") self.fail("should have raised a Warning") @@ -213,10 +213,10 @@ except: self.fail("raised wrong exception") - def CheckExecuteTooMuchSql2(self): + def testExecuteTooMuchSql2(self): self.cu.execute("select 5+4; -- foo bar") - def CheckExecuteTooMuchSql3(self): + def testExecuteTooMuchSql3(self): self.cu.execute(""" select 5+4; @@ -225,7 +225,7 @@ */ """) - def CheckExecuteWrongSqlArg(self): + def testExecuteWrongSqlArg(self): try: self.cu.execute(42) self.fail("should have raised a ValueError") @@ -234,23 +234,23 @@ except: self.fail("raised wrong exception.") - def CheckExecuteArgInt(self): + def testExecuteArgInt(self): self.cu.execute("insert into test(id) values (?)", (42,)) - def CheckExecuteArgFloat(self): + def testExecuteArgFloat(self): self.cu.execute("insert into test(income) values (?)", (2500.32,)) - def CheckExecuteArgString(self): + def testExecuteArgString(self): self.cu.execute("insert into test(name) values (?)", ("Hugo",)) - def CheckExecuteArgStringWithZeroByte(self): + def testExecuteArgStringWithZeroByte(self): self.cu.execute("insert into test(name) values (?)", ("Hu\x00go",)) self.cu.execute("select name from test where id=?", (self.cu.lastrowid,)) row = self.cu.fetchone() self.assertEqual(row[0], "Hu\x00go") - def CheckExecuteWrongNoOfArgs1(self): + def testExecuteWrongNoOfArgs1(self): # too many parameters try: self.cu.execute("insert into test(id) values (?)", (17, "Egon")) @@ -258,7 +258,7 @@ except sqlite.ProgrammingError: pass - def CheckExecuteWrongNoOfArgs2(self): + def testExecuteWrongNoOfArgs2(self): # too little parameters try: self.cu.execute("insert into test(id) values (?)") @@ -266,7 +266,7 @@ except sqlite.ProgrammingError: pass - def CheckExecuteWrongNoOfArgs3(self): + def testExecuteWrongNoOfArgs3(self): # no parameters, parameters are needed try: self.cu.execute("insert into test(id) values (?)") @@ -274,13 +274,13 @@ except sqlite.ProgrammingError: pass - def CheckExecuteParamList(self): + def testExecuteParamList(self): self.cu.execute("insert into test(name) values ('foo')") self.cu.execute("select name from test where name=?", ["foo"]) row = self.cu.fetchone() self.assertEqual(row[0], "foo") - def CheckExecuteParamSequence(self): + def testExecuteParamSequence(self): class L(object): def __len__(self): return 1 @@ -293,13 +293,13 @@ row = self.cu.fetchone() self.assertEqual(row[0], "foo") - def CheckExecuteDictMapping(self): + def testExecuteDictMapping(self): self.cu.execute("insert into test(name) values ('foo')") self.cu.execute("select name from test where name=:name", {"name": "foo"}) row = self.cu.fetchone() self.assertEqual(row[0], "foo") - def CheckExecuteDictMapping_Mapping(self): + def testExecuteDictMapping_Mapping(self): class D(dict): def __missing__(self, key): return "foo" @@ -309,7 +309,7 @@ row = self.cu.fetchone() self.assertEqual(row[0], "foo") - def CheckExecuteDictMappingTooLittleArgs(self): + def testExecuteDictMappingTooLittleArgs(self): self.cu.execute("insert into test(name) values ('foo')") try: self.cu.execute("select name from test where name=:name and id=:id", {"name": "foo"}) @@ -317,7 +317,7 @@ except sqlite.ProgrammingError: pass - def CheckExecuteDictMappingNoArgs(self): + def testExecuteDictMappingNoArgs(self): self.cu.execute("insert into test(name) values ('foo')") try: self.cu.execute("select name from test where name=:name") @@ -325,7 +325,7 @@ except sqlite.ProgrammingError: pass - def CheckExecuteDictMappingUnnamed(self): + def testExecuteDictMappingUnnamed(self): self.cu.execute("insert into test(name) values ('foo')") try: self.cu.execute("select name from test where name=?", {"name": "foo"}) @@ -333,17 +333,17 @@ except sqlite.ProgrammingError: pass - def CheckClose(self): + def testClose(self): self.cu.close() - def CheckRowcountExecute(self): + def testRowcountExecute(self): self.cu.execute("delete from test") self.cu.execute("insert into test(name) values ('foo')") self.cu.execute("insert into test(name) values ('foo')") self.cu.execute("update test set name='bar'") self.assertEqual(self.cu.rowcount, 2) - def CheckRowcountSelect(self): + def testRowcountSelect(self): """ pysqlite does not know the rowcount of SELECT statements, because we don't fetch all rows after executing the select statement. The rowcount @@ -352,12 +352,12 @@ self.cu.execute("select 5 union select 6") self.assertEqual(self.cu.rowcount, -1) - def CheckRowcountExecutemany(self): + def testRowcountExecutemany(self): self.cu.execute("delete from test") self.cu.executemany("insert into test(name) values (?)", [(1,), (2,), (3,)]) self.assertEqual(self.cu.rowcount, 3) - def CheckTotalChanges(self): + def testTotalChanges(self): self.cu.execute("insert into test(name) values ('foo')") self.cu.execute("insert into test(name) values ('foo')") if self.cx.total_changes < 2: @@ -367,10 +367,10 @@ # Sequences are required by the DB-API, iterators # enhancements in pysqlite. - def CheckExecuteManySequence(self): + def testExecuteManySequence(self): self.cu.executemany("insert into test(income) values (?)", [(x,) for x in range(100, 110)]) - def CheckExecuteManyIterator(self): + def testExecuteManyIterator(self): class MyIter: def __init__(self): self.value = 5 @@ -384,14 +384,14 @@ self.cu.executemany("insert into test(income) values (?)", MyIter()) - def CheckExecuteManyGenerator(self): + def testExecuteManyGenerator(self): def mygen(): for i in range(5): yield (i,) self.cu.executemany("insert into test(income) values (?)", mygen()) - def CheckExecuteManyWrongSqlArg(self): + def testExecuteManyWrongSqlArg(self): try: self.cu.executemany(42, [(3,)]) self.fail("should have raised a ValueError") @@ -400,7 +400,7 @@ except: self.fail("raised wrong exception.") - def CheckExecuteManySelect(self): + def testExecuteManySelect(self): try: self.cu.executemany("select ?", [(3,)]) self.fail("should have raised a ProgrammingError") @@ -409,7 +409,7 @@ except: self.fail("raised wrong exception.") - def CheckExecuteManyNotIterable(self): + def testExecuteManyNotIterable(self): try: self.cu.executemany("insert into test(income) values (?)", 42) self.fail("should have raised a TypeError") @@ -419,7 +419,7 @@ print("raised", e.__class__) self.fail("raised wrong exception.") - def CheckFetchIter(self): + def testFetchIter(self): # Optional DB-API extension. self.cu.execute("delete from test") self.cu.execute("insert into test(id) values (?)", (5,)) @@ -431,19 +431,19 @@ self.assertEqual(lst[0], 5) self.assertEqual(lst[1], 6) - def CheckFetchone(self): + def testFetchone(self): self.cu.execute("select name from test") row = self.cu.fetchone() self.assertEqual(row[0], "foo") row = self.cu.fetchone() self.assertEqual(row, None) - def CheckFetchoneNoStatement(self): + def testFetchoneNoStatement(self): cur = self.cx.cursor() row = cur.fetchone() self.assertEqual(row, None) - def CheckArraySize(self): + def testArraySize(self): # must default ot 1 self.assertEqual(self.cu.arraysize, 1) @@ -460,40 +460,40 @@ self.assertEqual(len(res), 2) - def CheckFetchmany(self): + def testFetchmany(self): self.cu.execute("select name from test") res = self.cu.fetchmany(100) self.assertEqual(len(res), 1) res = self.cu.fetchmany(100) self.assertEqual(res, []) - def CheckFetchmanyKwArg(self): + def testFetchmanyKwArg(self): """Checks if fetchmany works with keyword arguments""" self.cu.execute("select name from test") res = self.cu.fetchmany(size=100) self.assertEqual(len(res), 1) - def CheckFetchall(self): + def testFetchall(self): self.cu.execute("select name from test") res = self.cu.fetchall() self.assertEqual(len(res), 1) res = self.cu.fetchall() self.assertEqual(res, []) - def CheckSetinputsizes(self): + def testSetinputsizes(self): self.cu.setinputsizes([3, 4, 5]) - def CheckSetoutputsize(self): + def testSetoutputsize(self): self.cu.setoutputsize(5, 0) - def CheckSetoutputsizeNoColumn(self): + def testSetoutputsizeNoColumn(self): self.cu.setoutputsize(42) - def CheckCursorConnection(self): + def testCursorConnection(self): # Optional DB-API extension. self.assertEqual(self.cu.connection, self.cx) - def CheckWrongCursorCallable(self): + def testWrongCursorCallable(self): try: def f(): pass cur = self.cx.cursor(f) @@ -502,7 +502,7 @@ return self.fail("should have raised a ValueError") - def CheckCursorWrongClass(self): + def testCursorWrongClass(self): class Foo: pass foo = Foo() try: @@ -522,7 +522,7 @@ self.cur.close() self.con.close() - def CheckConCursor(self): + def testConCursor(self): def run(con, errors): try: cur = con.cursor() @@ -540,7 +540,7 @@ if len(errors) > 0: self.fail("\n".join(errors)) - def CheckConCommit(self): + def testConCommit(self): def run(con, errors): try: con.commit() @@ -558,7 +558,7 @@ if len(errors) > 0: self.fail("\n".join(errors)) - def CheckConRollback(self): + def testConRollback(self): def run(con, errors): try: con.rollback() @@ -576,7 +576,7 @@ if len(errors) > 0: self.fail("\n".join(errors)) - def CheckConClose(self): + def testConClose(self): def run(con, errors): try: con.close() @@ -594,7 +594,7 @@ if len(errors) > 0: self.fail("\n".join(errors)) - def CheckCurImplicitBegin(self): + def testCurImplicitBegin(self): def run(cur, errors): try: cur.execute("insert into test(name) values ('a')") @@ -612,7 +612,7 @@ if len(errors) > 0: self.fail("\n".join(errors)) - def CheckCurClose(self): + def testCurClose(self): def run(cur, errors): try: cur.close() @@ -630,7 +630,7 @@ if len(errors) > 0: self.fail("\n".join(errors)) - def CheckCurExecute(self): + def testCurExecute(self): def run(cur, errors): try: cur.execute("select name from test") @@ -649,7 +649,7 @@ if len(errors) > 0: self.fail("\n".join(errors)) - def CheckCurIterNext(self): + def testCurIterNext(self): def run(cur, errors): try: row = cur.fetchone() @@ -670,29 +670,29 @@ self.fail("\n".join(errors)) class ConstructorTests(unittest.TestCase): - def CheckDate(self): + def testDate(self): d = sqlite.Date(2004, 10, 28) - def CheckTime(self): + def testTime(self): t = sqlite.Time(12, 39, 35) - def CheckTimestamp(self): + def testTimestamp(self): ts = sqlite.Timestamp(2004, 10, 28, 12, 39, 35) - def CheckDateFromTicks(self): + def testDateFromTicks(self): d = sqlite.DateFromTicks(42) - def CheckTimeFromTicks(self): + def testTimeFromTicks(self): t = sqlite.TimeFromTicks(42) - def CheckTimestampFromTicks(self): + def testTimestampFromTicks(self): ts = sqlite.TimestampFromTicks(42) - def CheckBinary(self): + def testBinary(self): b = sqlite.Binary(b"\0'") class ExtensionTests(unittest.TestCase): - def CheckScriptStringSql(self): + def testScriptStringSql(self): con = sqlite.connect(":memory:") cur = con.cursor() cur.executescript(""" @@ -705,7 +705,7 @@ res = cur.fetchone()[0] self.assertEqual(res, 5) - def CheckScriptSyntaxError(self): + def testScriptSyntaxError(self): con = sqlite.connect(":memory:") cur = con.cursor() raised = False @@ -715,7 +715,7 @@ raised = True self.assertEqual(raised, True, "should have raised an exception") - def CheckScriptErrorNormal(self): + def testScriptErrorNormal(self): con = sqlite.connect(":memory:") cur = con.cursor() raised = False @@ -725,12 +725,12 @@ raised = True self.assertEqual(raised, True, "should have raised an exception") - def CheckConnectionExecute(self): + def testConnectionExecute(self): con = sqlite.connect(":memory:") result = con.execute("select 5").fetchone()[0] self.assertEqual(result, 5, "Basic test of Connection.execute") - def CheckConnectionExecutemany(self): + def testConnectionExecutemany(self): con = sqlite.connect(":memory:") con.execute("create table test(foo)") con.executemany("insert into test(foo) values (?)", [(3,), (4,)]) @@ -738,7 +738,7 @@ self.assertEqual(result[0][0], 3, "Basic test of Connection.executemany") self.assertEqual(result[1][0], 4, "Basic test of Connection.executemany") - def CheckConnectionExecutescript(self): + def testConnectionExecutescript(self): con = sqlite.connect(":memory:") con.executescript("create table test(foo); insert into test(foo) values (5);") result = con.execute("select foo from test").fetchone()[0] @@ -751,7 +751,7 @@ def tearDown(self): pass - def CheckClosedConCursor(self): + def testClosedConCursor(self): con = sqlite.connect(":memory:") con.close() try: @@ -762,7 +762,7 @@ except: self.fail("Should have raised a ProgrammingError") - def CheckClosedConCommit(self): + def testClosedConCommit(self): con = sqlite.connect(":memory:") con.close() try: @@ -773,7 +773,7 @@ except: self.fail("Should have raised a ProgrammingError") - def CheckClosedConRollback(self): + def testClosedConRollback(self): con = sqlite.connect(":memory:") con.close() try: @@ -784,7 +784,7 @@ except: self.fail("Should have raised a ProgrammingError") - def CheckClosedCurExecute(self): + def testClosedCurExecute(self): con = sqlite.connect(":memory:") cur = con.cursor() con.close() @@ -796,7 +796,7 @@ except: self.fail("Should have raised a ProgrammingError") - def CheckClosedCreateFunction(self): + def testClosedCreateFunction(self): con = sqlite.connect(":memory:") con.close() def f(x): return 17 @@ -808,7 +808,7 @@ except: self.fail("Should have raised a ProgrammingError") - def CheckClosedCreateAggregate(self): + def testClosedCreateAggregate(self): con = sqlite.connect(":memory:") con.close() class Agg: @@ -826,7 +826,7 @@ except: self.fail("Should have raised a ProgrammingError") - def CheckClosedSetAuthorizer(self): + def testClosedSetAuthorizer(self): con = sqlite.connect(":memory:") con.close() def authorizer(*args): @@ -839,7 +839,7 @@ except: self.fail("Should have raised a ProgrammingError") - def CheckClosedSetProgressCallback(self): + def testClosedSetProgressCallback(self): con = sqlite.connect(":memory:") con.close() def progress(): pass @@ -851,7 +851,7 @@ except: self.fail("Should have raised a ProgrammingError") - def CheckClosedCall(self): + def testClosedCall(self): con = sqlite.connect(":memory:") con.close() try: @@ -869,7 +869,7 @@ def tearDown(self): pass - def CheckClosed(self): + def testClosed(self): con = sqlite.connect(":memory:") cur = con.cursor() cur.close() @@ -892,20 +892,5 @@ except: self.fail("Should have raised a ProgrammingError: " + method_name) -def suite(): - module_suite = unittest.makeSuite(ModuleTests, "Check") - connection_suite = unittest.makeSuite(ConnectionTests, "Check") - cursor_suite = unittest.makeSuite(CursorTests, "Check") - thread_suite = unittest.makeSuite(ThreadTests, "Check") - constructor_suite = unittest.makeSuite(ConstructorTests, "Check") - ext_suite = unittest.makeSuite(ExtensionTests, "Check") - closed_con_suite = unittest.makeSuite(ClosedConTests, "Check") - closed_cur_suite = unittest.makeSuite(ClosedCurTests, "Check") - return unittest.TestSuite((module_suite, connection_suite, cursor_suite, thread_suite, constructor_suite, ext_suite, closed_con_suite, closed_cur_suite)) - -def test(): - runner = unittest.TextTestRunner() - runner.run(suite()) - if __name__ == "__main__": - test() + unittest.main() diff --git a/Lib/sqlite3/test/dump.py b/Lib/test/test_sqlite3/test_dump.py rename from Lib/sqlite3/test/dump.py rename to Lib/test/test_sqlite3/test_dump.py --- a/Lib/sqlite3/test/dump.py +++ b/Lib/test/test_sqlite3/test_dump.py @@ -11,7 +11,7 @@ def tearDown(self): self.cx.close() - def CheckTableDump(self): + def testTableDump(self): expected_sqls = [ """CREATE TABLE "index"("index" blob);""" , @@ -49,7 +49,7 @@ [self.assertEqual(expected_sqls[i], actual_sqls[i]) for i in range(len(expected_sqls))] - def CheckUnorderableRow(self): + def testUnorderableRow(self): # iterdump() should be able to cope with unorderable row types (issue #15545) class UnorderableRow: def __init__(self, cursor, row): @@ -70,12 +70,5 @@ got = list(self.cx.iterdump()) self.assertEqual(expected, got) -def suite(): - return unittest.TestSuite(unittest.makeSuite(DumpTests, "Check")) - -def test(): - runner = unittest.TextTestRunner() - runner.run(suite()) - if __name__ == "__main__": - test() + unittest.main() diff --git a/Lib/sqlite3/test/factory.py b/Lib/test/test_sqlite3/test_factory.py rename from Lib/sqlite3/test/factory.py rename to Lib/test/test_sqlite3/test_factory.py --- a/Lib/sqlite3/test/factory.py +++ b/Lib/test/test_sqlite3/test_factory.py @@ -47,7 +47,7 @@ def tearDown(self): self.con.close() - def CheckIsInstance(self): + def testIsInstance(self): self.assertIsInstance(self.con, MyConnection) class CursorFactoryTests(unittest.TestCase): @@ -57,7 +57,7 @@ def tearDown(self): self.con.close() - def CheckIsInstance(self): + def testIsInstance(self): cur = self.con.cursor(factory=MyCursor) self.assertIsInstance(cur, MyCursor) @@ -65,7 +65,7 @@ def setUp(self): self.con = sqlite.connect(":memory:") - def CheckIsProducedByFactory(self): + def testIsProducedByFactory(self): cur = self.con.cursor(factory=MyCursor) cur.execute("select 4+5 as foo") row = cur.fetchone() @@ -79,12 +79,12 @@ def setUp(self): self.con = sqlite.connect(":memory:") - def CheckCustomFactory(self): + def testCustomFactory(self): self.con.row_factory = lambda cur, row: list(row) row = self.con.execute("select 1, 2").fetchone() self.assertIsInstance(row, list) - def CheckSqliteRowIndex(self): + def testSqliteRowIndex(self): self.con.row_factory = sqlite.Row row = self.con.execute("select 1 as a, 2 as b").fetchone() self.assertIsInstance(row, sqlite.Row) @@ -111,21 +111,21 @@ with self.assertRaises(IndexError): row[2**1000] - def CheckSqliteRowIter(self): + def testSqliteRowIter(self): """Checks if the row object is iterable""" self.con.row_factory = sqlite.Row row = self.con.execute("select 1 as a, 2 as b").fetchone() for col in row: pass - def CheckSqliteRowAsTuple(self): + def testSqliteRowAsTuple(self): """Checks if the row object can be converted to a tuple""" self.con.row_factory = sqlite.Row row = self.con.execute("select 1 as a, 2 as b").fetchone() t = tuple(row) self.assertEqual(t, (row['a'], row['b'])) - def CheckSqliteRowAsDict(self): + def testSqliteRowAsDict(self): """Checks if the row object can be correctly converted to a dictionary""" self.con.row_factory = sqlite.Row row = self.con.execute("select 1 as a, 2 as b").fetchone() @@ -133,7 +133,7 @@ self.assertEqual(d["a"], row["a"]) self.assertEqual(d["b"], row["b"]) - def CheckSqliteRowHashCmp(self): + def testSqliteRowHashCmp(self): """Checks if the row object compares and hashes correctly""" self.con.row_factory = sqlite.Row row_1 = self.con.execute("select 1 as a, 2 as b").fetchone() @@ -153,7 +153,7 @@ self.assertNotEqual(row_1, row_3) self.assertNotEqual(hash(row_1), hash(row_3)) - def CheckSqliteRowAsSequence(self): + def testSqliteRowAsSequence(self): """ Checks if the row object can act like a sequence """ self.con.row_factory = sqlite.Row row = self.con.execute("select 1 as a, 2 as b").fetchone() @@ -169,26 +169,26 @@ def setUp(self): self.con = sqlite.connect(":memory:") - def CheckUnicode(self): + def testUnicode(self): austria = "Österreich" row = self.con.execute("select ?", (austria,)).fetchone() self.assertEqual(type(row[0]), str, "type of row[0] must be unicode") - def CheckString(self): + def testString(self): self.con.text_factory = bytes austria = "Österreich" row = self.con.execute("select ?", (austria,)).fetchone() self.assertEqual(type(row[0]), bytes, "type of row[0] must be bytes") self.assertEqual(row[0], austria.encode("utf-8"), "column must equal original data in UTF-8") - def CheckCustom(self): + def testCustom(self): self.con.text_factory = lambda x: str(x, "utf-8", "ignore") austria = "Österreich" row = self.con.execute("select ?", (austria,)).fetchone() self.assertEqual(type(row[0]), str, "type of row[0] must be unicode") self.assertTrue(row[0].endswith("reich"), "column must contain original data") - def CheckOptimizedUnicode(self): + def testOptimizedUnicode(self): # In py3k, str objects are always returned when text_factory # is OptimizedUnicode self.con.text_factory = sqlite.OptimizedUnicode @@ -208,25 +208,25 @@ self.con.execute("create table test (value text)") self.con.execute("insert into test (value) values (?)", ("a\x00b",)) - def CheckString(self): + def testString(self): # text_factory defaults to str row = self.con.execute("select value from test").fetchone() self.assertIs(type(row[0]), str) self.assertEqual(row[0], "a\x00b") - def CheckBytes(self): + def testBytes(self): self.con.text_factory = bytes row = self.con.execute("select value from test").fetchone() self.assertIs(type(row[0]), bytes) self.assertEqual(row[0], b"a\x00b") - def CheckBytearray(self): + def testBytearray(self): self.con.text_factory = bytearray row = self.con.execute("select value from test").fetchone() self.assertIs(type(row[0]), bytearray) self.assertEqual(row[0], b"a\x00b") - def CheckCustom(self): + def testCustom(self): # A custom factory should receive a bytes argument self.con.text_factory = lambda x: x row = self.con.execute("select value from test").fetchone() @@ -236,18 +236,5 @@ def tearDown(self): self.con.close() -def suite(): - connection_suite = unittest.makeSuite(ConnectionFactoryTests, "Check") - cursor_suite = unittest.makeSuite(CursorFactoryTests, "Check") - row_suite_compat = unittest.makeSuite(RowFactoryTestsBackwardsCompat, "Check") - row_suite = unittest.makeSuite(RowFactoryTests, "Check") - text_suite = unittest.makeSuite(TextFactoryTests, "Check") - text_zero_bytes_suite = unittest.makeSuite(TextFactoryTestsWithEmbeddedZeroBytes, "Check") - return unittest.TestSuite((connection_suite, cursor_suite, row_suite_compat, row_suite, text_suite, text_zero_bytes_suite)) - -def test(): - runner = unittest.TextTestRunner() - runner.run(suite()) - if __name__ == "__main__": - test() + unittest.main() diff --git a/Lib/sqlite3/test/hooks.py b/Lib/test/test_sqlite3/test_hooks.py rename from Lib/sqlite3/test/hooks.py rename to Lib/test/test_sqlite3/test_hooks.py --- a/Lib/sqlite3/test/hooks.py +++ b/Lib/test/test_sqlite3/test_hooks.py @@ -31,7 +31,7 @@ def tearDown(self): pass - def CheckCreateCollationNotCallable(self): + def testCreateCollationNotCallable(self): con = sqlite.connect(":memory:") try: con.create_collation("X", 42) @@ -39,7 +39,7 @@ except TypeError as e: self.assertEqual(e.args[0], "parameter must be callable") - def CheckCreateCollationNotAscii(self): + def testCreateCollationNotAscii(self): con = sqlite.connect(":memory:") try: con.create_collation("collä", lambda x, y: (x > y) - (x < y)) @@ -49,7 +49,7 @@ @unittest.skipIf(sqlite.sqlite_version_info < (3, 2, 1), 'old SQLite versions crash on this test') - def CheckCollationIsUsed(self): + def testCollationIsUsed(self): def mycoll(x, y): # reverse order return -((x > y) - (x < y)) @@ -76,7 +76,7 @@ except sqlite.OperationalError as e: self.assertEqual(e.args[0].lower(), "no such collation sequence: mycoll") - def CheckCollationReturnsLargeInteger(self): + def testCollationReturnsLargeInteger(self): def mycoll(x, y): # reverse order return -((x > y) - (x < y)) * 2**32 @@ -95,7 +95,7 @@ self.assertEqual(result, [('c',), ('b',), ('a',)], msg="the expected order was not returned") - def CheckCollationRegisterTwice(self): + def testCollationRegisterTwice(self): """ Register two different collation functions under the same name. Verify that the last one is actually used. @@ -109,7 +109,7 @@ if result[0][0] != 'b' or result[1][0] != 'a': self.fail("wrong collation function is used") - def CheckDeregisterCollation(self): + def testDeregisterCollation(self): """ Register a collation, then deregister it. Make sure an error is raised if we try to use it. @@ -125,7 +125,7 @@ self.fail("wrong OperationalError raised") class ProgressTests(unittest.TestCase): - def CheckProgressHandlerUsed(self): + def testProgressHandlerUsed(self): """ Test that the progress handler is invoked once it is set. """ @@ -141,7 +141,7 @@ self.assertTrue(progress_calls) - def CheckOpcodeCount(self): + def testOpcodeCount(self): """ Test that the opcode argument is respected. """ @@ -164,7 +164,7 @@ second_count = len(progress_calls) self.assertGreaterEqual(first_count, second_count) - def CheckCancelOperation(self): + def testCancelOperation(self): """ Test that returning a non-zero value stops the operation in progress. """ @@ -180,7 +180,7 @@ curs.execute, "create table bar (a, b)") - def CheckClearHandler(self): + def testClearHandler(self): """ Test that setting the progress handler to None clears the previously set handler. """ @@ -196,7 +196,7 @@ self.assertEqual(action, 0, "progress handler was not cleared") class TraceCallbackTests(unittest.TestCase): - def CheckTraceCallbackUsed(self): + def testTraceCallbackUsed(self): """ Test that the trace callback is invoked once it is set. """ @@ -209,7 +209,7 @@ self.assertTrue(traced_statements) self.assertTrue(any("create table foo" in stmt for stmt in traced_statements)) - def CheckClearTraceCallback(self): + def testClearTraceCallback(self): """ Test that setting the trace callback to None clears the previously set callback. """ @@ -222,7 +222,7 @@ con.execute("create table foo(a, b)") self.assertFalse(traced_statements, "trace callback was not cleared") - def CheckUnicodeContent(self): + def testUnicodeContent(self): """ Test that the statement can contain unicode literals. """ @@ -243,16 +243,5 @@ % (ascii(unicode_value), ', '.join(map(ascii, traced_statements)))) - -def suite(): - collation_suite = unittest.makeSuite(CollationTests, "Check") - progress_suite = unittest.makeSuite(ProgressTests, "Check") - trace_suite = unittest.makeSuite(TraceCallbackTests, "Check") - return unittest.TestSuite((collation_suite, progress_suite, trace_suite)) - -def test(): - runner = unittest.TextTestRunner() - runner.run(suite()) - if __name__ == "__main__": - test() + unittest.main() diff --git a/Lib/sqlite3/test/regression.py b/Lib/test/test_sqlite3/test_regression.py rename from Lib/sqlite3/test/regression.py rename to Lib/test/test_sqlite3/test_regression.py --- a/Lib/sqlite3/test/regression.py +++ b/Lib/test/test_sqlite3/test_regression.py @@ -32,12 +32,12 @@ def tearDown(self): self.con.close() - def CheckPragmaUserVersion(self): + def testPragmaUserVersion(self): # This used to crash pysqlite because this pragma command returns NULL for the column name cur = self.con.cursor() cur.execute("pragma user_version") - def CheckPragmaSchemaVersion(self): + def testPragmaSchemaVersion(self): # This still crashed pysqlite <= 2.2.1 con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES) try: @@ -47,7 +47,7 @@ cur.close() con.close() - def CheckStatementReset(self): + def testStatementReset(self): # pysqlite 2.1.0 to 2.2.0 have the problem that not all statements are # reset before a rollback, but only those that are still in the # statement cache. The others are not accessible from the connection object. @@ -62,7 +62,7 @@ con.rollback() - def CheckColumnNameWithSpaces(self): + def testColumnNameWithSpaces(self): cur = self.con.cursor() cur.execute('select 1 as "foo bar [datetime]"') self.assertEqual(cur.description[0][0], "foo bar") @@ -70,7 +70,7 @@ cur.execute('select 1 as "foo baz"') self.assertEqual(cur.description[0][0], "foo baz") - def CheckStatementFinalizationOnCloseDb(self): + def testStatementFinalizationOnCloseDb(self): # pysqlite versions <= 2.3.3 only finalized statements in the statement # cache when closing the database. statements that were still # referenced in cursors weren't closed an could provoke " @@ -84,7 +84,7 @@ cur.execute("select 1 x union select " + str(i)) con.close() - def CheckOnConflictRollback(self): + def testOnConflictRollback(self): if sqlite.sqlite_version_info < (3, 2, 2): return con = sqlite.connect(":memory:") @@ -100,7 +100,7 @@ except sqlite.OperationalError: self.fail("pysqlite knew nothing about the implicit ROLLBACK") - def CheckWorkaroundForBuggySqliteTransferBindings(self): + def testWorkaroundForBuggySqliteTransferBindings(self): """ pysqlite would crash with older SQLite versions unless a workaround is implemented. @@ -109,14 +109,14 @@ self.con.execute("drop table foo") self.con.execute("create table foo(bar)") - def CheckEmptyStatement(self): + def testEmptyStatement(self): """ pysqlite used to segfault with SQLite versions 3.5.x. These return NULL for "no-operation" statements """ self.con.execute("") - def CheckTypeMapUsage(self): + def testTypeMapUsage(self): """ pysqlite until 2.4.1 did not rebuild the row_cast_map when recompiling a statement. This test exhibits the problem. @@ -131,7 +131,7 @@ con.execute("insert into foo(bar) values (5)") con.execute(SELECT) - def CheckErrorMsgDecodeError(self): + def testErrorMsgDecodeError(self): # When porting the module to Python 3.0, the error message about # decoding errors disappeared. This verifies they're back again. failure = None @@ -146,20 +146,20 @@ if failure: self.fail(failure) - def CheckRegisterAdapter(self): + def testRegisterAdapter(self): """ See issue 3312. """ self.assertRaises(TypeError, sqlite.register_adapter, {}, None) - def CheckSetIsolationLevel(self): + def testSetIsolationLevel(self): """ See issue 3312. """ con = sqlite.connect(":memory:") setattr(con, "isolation_level", "\xe9") - def CheckCursorConstructorCallCheck(self): + def testCursorConstructorCallCheck(self): """ Verifies that cursor methods check whether base class __init__ was called. @@ -179,14 +179,14 @@ self.fail("should have raised ProgrammingError") - def CheckStrSubclass(self): + def testStrSubclass(self): """ The Python 3.0 port of the module didn't cope with values of subclasses of str. """ class MyStr(str): pass self.con.execute("select ?", (MyStr("abc"),)) - def CheckConnectionConstructorCallCheck(self): + def testConnectionConstructorCallCheck(self): """ Verifies that connection methods check whether base class __init__ was called. @@ -204,7 +204,7 @@ except: self.fail("should have raised ProgrammingError") - def CheckCursorRegistration(self): + def testCursorRegistration(self): """ Verifies that subclassed cursor classes are correctly registered with the connection object, too. (fetch-across-rollback problem) @@ -231,7 +231,7 @@ except: self.fail("should have raised InterfaceError") - def CheckAutoCommit(self): + def testAutoCommit(self): """ Verifies that creating a connection in autocommit mode works. 2.5.3 introduced a regression so that these could no longer @@ -239,7 +239,7 @@ """ con = sqlite.connect(":memory:", isolation_level=None) - def CheckPragmaAutocommit(self): + def testPragmaAutocommit(self): """ Verifies that running a PRAGMA statement that does an autocommit does work. This did not work in 2.5.3/2.5.4. @@ -251,7 +251,7 @@ cur.execute("pragma page_size") row = cur.fetchone() - def CheckSetDict(self): + def testSetDict(self): """ See http://bugs.python.org/issue7478 @@ -269,21 +269,21 @@ self.assertRaises(TypeError, self.con.set_authorizer, var) self.assertRaises(TypeError, self.con.set_progress_handler, var) - def CheckConnectionCall(self): + def testConnectionCall(self): """ Call a connection with a non-string SQL request: check error handling of the statement constructor. """ self.assertRaises(sqlite.Warning, self.con, 1) - def CheckCollation(self): + def testCollation(self): def collation_cb(a, b): return 1 self.assertRaises(sqlite.ProgrammingError, self.con.create_collation, # Lone surrogate cannot be encoded to the default encoding (utf8) "\uDC80", collation_cb) - def CheckRecursiveCursorUse(self): + def testRecursiveCursorUse(self): """ http://bugs.python.org/issue10811 @@ -304,7 +304,7 @@ cur.executemany("insert into b (baz) values (?)", ((i,) for i in foo())) - def CheckConvertTimestampMicrosecondPadding(self): + def testConvertTimestampMicrosecondPadding(self): """ http://bugs.python.org/issue14720 @@ -330,19 +330,11 @@ datetime.datetime(2012, 4, 4, 15, 6, 0, 123456), ]) - def CheckInvalidIsolationLevelType(self): + def testInvalidIsolationLevelType(self): # isolation level is a string, not an integer self.assertRaises(TypeError, sqlite.connect, ":memory:", isolation_level=123) -def suite(): - regression_suite = unittest.makeSuite(RegressionTests, "Check") - return unittest.TestSuite((regression_suite,)) - -def test(): - runner = unittest.TextTestRunner() - runner.run(suite()) - if __name__ == "__main__": - test() + unittest.main() diff --git a/Lib/sqlite3/test/transactions.py b/Lib/test/test_sqlite3/test_transactions.py rename from Lib/sqlite3/test/transactions.py rename to Lib/test/test_sqlite3/test_transactions.py --- a/Lib/sqlite3/test/transactions.py +++ b/Lib/test/test_sqlite3/test_transactions.py @@ -52,7 +52,7 @@ except OSError: pass - def CheckDMLdoesAutoCommitBefore(self): + def testDMLdoesAutoCommitBefore(self): self.cur1.execute("create table test(i)") self.cur1.execute("insert into test(i) values (5)") self.cur1.execute("create table test2(j)") @@ -60,14 +60,14 @@ res = self.cur2.fetchall() self.assertEqual(len(res), 1) - def CheckInsertStartsTransaction(self): + def testInsertStartsTransaction(self): self.cur1.execute("create table test(i)") self.cur1.execute("insert into test(i) values (5)") self.cur2.execute("select i from test") res = self.cur2.fetchall() self.assertEqual(len(res), 0) - def CheckUpdateStartsTransaction(self): + def testUpdateStartsTransaction(self): self.cur1.execute("create table test(i)") self.cur1.execute("insert into test(i) values (5)") self.con1.commit() @@ -76,7 +76,7 @@ res = self.cur2.fetchone()[0] self.assertEqual(res, 5) - def CheckDeleteStartsTransaction(self): + def testDeleteStartsTransaction(self): self.cur1.execute("create table test(i)") self.cur1.execute("insert into test(i) values (5)") self.con1.commit() @@ -85,7 +85,7 @@ res = self.cur2.fetchall() self.assertEqual(len(res), 1) - def CheckReplaceStartsTransaction(self): + def testReplaceStartsTransaction(self): self.cur1.execute("create table test(i)") self.cur1.execute("insert into test(i) values (5)") self.con1.commit() @@ -95,7 +95,7 @@ self.assertEqual(len(res), 1) self.assertEqual(res[0][0], 5) - def CheckToggleAutoCommit(self): + def testToggleAutoCommit(self): self.cur1.execute("create table test(i)") self.cur1.execute("insert into test(i) values (5)") self.con1.isolation_level = None @@ -111,7 +111,7 @@ res = self.cur2.fetchall() self.assertEqual(len(res), 1) - def CheckRaiseTimeout(self): + def testRaiseTimeout(self): if sqlite.sqlite_version_info < (3, 2, 2): # This will fail (hang) on earlier versions of sqlite. # Determine exact version it was fixed. 3.2.1 hangs. @@ -126,7 +126,7 @@ except: self.fail("should have raised an OperationalError") - def CheckLocking(self): + def testLocking(self): """ This tests the improved concurrency with pysqlite 2.3.4. You needed to roll back con2 before you could commit con1. @@ -147,7 +147,7 @@ # NO self.con2.rollback() HERE!!! self.con1.commit() - def CheckRollbackCursorConsistency(self): + def testRollbackCursorConsistency(self): """ Checks if cursors on the connection are set into a "reset" state when a rollback is done on the connection. @@ -172,17 +172,17 @@ self.con = sqlite.connect(":memory:") self.cur = self.con.cursor() - def CheckVacuum(self): + def testVacuum(self): self.cur.execute("create table test(i)") self.cur.execute("insert into test(i) values (5)") self.cur.execute("vacuum") - def CheckDropTable(self): + def testDropTable(self): self.cur.execute("create table test(i)") self.cur.execute("insert into test(i) values (5)") self.cur.execute("drop table test") - def CheckPragma(self): + def testPragma(self): self.cur.execute("create table test(i)") self.cur.execute("insert into test(i) values (5)") self.cur.execute("pragma count_changes=1") @@ -191,14 +191,5 @@ self.cur.close() self.con.close() -def suite(): - default_suite = unittest.makeSuite(TransactionTests, "Check") - special_command_suite = unittest.makeSuite(SpecialCommandTests, "Check") - return unittest.TestSuite((default_suite, special_command_suite)) - -def test(): - runner = unittest.TextTestRunner() - runner.run(suite()) - if __name__ == "__main__": - test() + unittest.main() diff --git a/Lib/sqlite3/test/types.py b/Lib/test/test_sqlite3/test_types.py rename from Lib/sqlite3/test/types.py rename to Lib/test/test_sqlite3/test_types.py --- a/Lib/sqlite3/test/types.py +++ b/Lib/test/test_sqlite3/test_types.py @@ -40,33 +40,33 @@ self.cur.close() self.con.close() - def CheckString(self): + def testString(self): self.cur.execute("insert into test(s) values (?)", ("Österreich",)) self.cur.execute("select s from test") row = self.cur.fetchone() self.assertEqual(row[0], "Österreich") - def CheckSmallInt(self): + def testSmallInt(self): self.cur.execute("insert into test(i) values (?)", (42,)) self.cur.execute("select i from test") row = self.cur.fetchone() self.assertEqual(row[0], 42) - def CheckLargeInt(self): + def testLargeInt(self): num = 2**40 self.cur.execute("insert into test(i) values (?)", (num,)) self.cur.execute("select i from test") row = self.cur.fetchone() self.assertEqual(row[0], num) - def CheckFloat(self): + def testFloat(self): val = 3.14 self.cur.execute("insert into test(f) values (?)", (val,)) self.cur.execute("select f from test") row = self.cur.fetchone() self.assertEqual(row[0], val) - def CheckBlob(self): + def testBlob(self): sample = b"Guglhupf" val = memoryview(sample) self.cur.execute("insert into test(b) values (?)", (val,)) @@ -74,7 +74,7 @@ row = self.cur.fetchone() self.assertEqual(row[0], sample) - def CheckUnicodeExecute(self): + def testUnicodeExecute(self): self.cur.execute("select 'Österreich'") row = self.cur.fetchone() self.assertEqual(row[0], "Österreich") @@ -133,21 +133,21 @@ self.cur.close() self.con.close() - def CheckString(self): + def testString(self): # default self.cur.execute("insert into test(s) values (?)", ("foo",)) self.cur.execute('select s as "s [WRONG]" from test') row = self.cur.fetchone() self.assertEqual(row[0], "foo") - def CheckSmallInt(self): + def testSmallInt(self): # default self.cur.execute("insert into test(i) values (?)", (42,)) self.cur.execute("select i from test") row = self.cur.fetchone() self.assertEqual(row[0], 42) - def CheckLargeInt(self): + def testLargeInt(self): # default num = 2**40 self.cur.execute("insert into test(i) values (?)", (num,)) @@ -155,7 +155,7 @@ row = self.cur.fetchone() self.assertEqual(row[0], num) - def CheckFloat(self): + def testFloat(self): # custom val = 3.14 self.cur.execute("insert into test(f) values (?)", (val,)) @@ -163,7 +163,7 @@ row = self.cur.fetchone() self.assertEqual(row[0], 47.2) - def CheckBool(self): + def testBool(self): # custom self.cur.execute("insert into test(b) values (?)", (False,)) self.cur.execute("select b from test") @@ -176,7 +176,7 @@ row = self.cur.fetchone() self.assertEqual(row[0], True) - def CheckUnicode(self): + def testUnicode(self): # default val = "\xd6sterreich" self.cur.execute("insert into test(u) values (?)", (val,)) @@ -184,14 +184,14 @@ row = self.cur.fetchone() self.assertEqual(row[0], val) - def CheckFoo(self): + def testFoo(self): val = DeclTypesTests.Foo("bla") self.cur.execute("insert into test(foo) values (?)", (val,)) self.cur.execute("select foo from test") row = self.cur.fetchone() self.assertEqual(row[0], val) - def CheckUnsupportedSeq(self): + def testUnsupportedSeq(self): class Bar: pass val = Bar() try: @@ -202,7 +202,7 @@ except: self.fail("should have raised an InterfaceError") - def CheckUnsupportedDict(self): + def testUnsupportedDict(self): class Bar: pass val = Bar() try: @@ -213,7 +213,7 @@ except: self.fail("should have raised an InterfaceError") - def CheckBlob(self): + def testBlob(self): # default sample = b"Guglhupf" val = memoryview(sample) @@ -222,13 +222,13 @@ row = self.cur.fetchone() self.assertEqual(row[0], sample) - def CheckNumber1(self): + def testNumber1(self): self.cur.execute("insert into test(n1) values (5)") value = self.cur.execute("select n1 from test").fetchone()[0] # if the converter is not used, it's an int instead of a float self.assertEqual(type(value), float) - def CheckNumber2(self): + def testNumber2(self): """Checks whether converter names are cut off at '(' characters""" self.cur.execute("insert into test(n2) values (5)") value = self.cur.execute("select n2 from test").fetchone()[0] @@ -254,7 +254,7 @@ self.cur.close() self.con.close() - def CheckDeclTypeNotUsed(self): + def testDeclTypeNotUsed(self): """ Assures that the declared type is not used when PARSE_DECLTYPES is not set. @@ -264,13 +264,13 @@ val = self.cur.fetchone()[0] self.assertEqual(val, "xxx") - def CheckNone(self): + def testNone(self): self.cur.execute("insert into test(x) values (?)", (None,)) self.cur.execute("select x from test") val = self.cur.fetchone()[0] self.assertEqual(val, None) - def CheckColName(self): + def testColName(self): self.cur.execute("insert into test(x) values (?)", ("xxx",)) self.cur.execute('select x as "x [bar]" from test') val = self.cur.fetchone()[0] @@ -280,12 +280,12 @@ # whitespace should be stripped. self.assertEqual(self.cur.description[0][0], "x") - def CheckCaseInConverterName(self): + def testCaseInConverterName(self): self.cur.execute("select 'other' as \"x [b1b1]\"") val = self.cur.fetchone()[0] self.assertEqual(val, "MARKER") - def CheckCursorDescriptionNoRow(self): + def testCursorDescriptionNoRow(self): """ cursor.description should at least provide the column name(s), even if no row returned. @@ -312,7 +312,7 @@ self.cur.close() self.con.close() - def CheckCasterIsUsed(self): + def testCasterIsUsed(self): self.cur.execute("select ?", (4,)) val = self.cur.fetchone()[0] self.assertEqual(type(val), float) @@ -330,7 +330,7 @@ def tearDown(self): self.con.close() - def CheckBinaryInputForConverter(self): + def testBinaryInputForConverter(self): testdata = b"abcdefg" * 10 result = self.con.execute('select ? as "x [bin]"', (memoryview(zlib.compress(testdata)),)).fetchone()[0] self.assertEqual(testdata, result) @@ -345,21 +345,21 @@ self.cur.close() self.con.close() - def CheckSqliteDate(self): + def testSqliteDate(self): d = sqlite.Date(2004, 2, 14) self.cur.execute("insert into test(d) values (?)", (d,)) self.cur.execute("select d from test") d2 = self.cur.fetchone()[0] self.assertEqual(d, d2) - def CheckSqliteTimestamp(self): + def testSqliteTimestamp(self): ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0) self.cur.execute("insert into test(ts) values (?)", (ts,)) self.cur.execute("select ts from test") ts2 = self.cur.fetchone()[0] self.assertEqual(ts, ts2) - def CheckSqlTimestamp(self): + def testSqlTimestamp(self): # The date functions are only available in SQLite version 3.1 or later if sqlite.sqlite_version_info < (3, 1): return @@ -372,32 +372,19 @@ self.assertEqual(type(ts), datetime.datetime) self.assertEqual(ts.year, now.year) - def CheckDateTimeSubSeconds(self): + def testDateTimeSubSeconds(self): ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 500000) self.cur.execute("insert into test(ts) values (?)", (ts,)) self.cur.execute("select ts from test") ts2 = self.cur.fetchone()[0] self.assertEqual(ts, ts2) - def CheckDateTimeSubSecondsFloatingPoint(self): + def testDateTimeSubSecondsFloatingPoint(self): ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 510241) self.cur.execute("insert into test(ts) values (?)", (ts,)) self.cur.execute("select ts from test") ts2 = self.cur.fetchone()[0] self.assertEqual(ts, ts2) -def suite(): - sqlite_type_suite = unittest.makeSuite(SqliteTypeTests, "Check") - decltypes_type_suite = unittest.makeSuite(DeclTypesTests, "Check") - colnames_type_suite = unittest.makeSuite(ColNamesTests, "Check") - adaptation_suite = unittest.makeSuite(ObjectAdaptationTests, "Check") - bin_suite = unittest.makeSuite(BinaryConverterTests, "Check") - date_suite = unittest.makeSuite(DateTimeTests, "Check") - return unittest.TestSuite((sqlite_type_suite, decltypes_type_suite, colnames_type_suite, adaptation_suite, bin_suite, date_suite)) - -def test(): - runner = unittest.TextTestRunner() - runner.run(suite()) - if __name__ == "__main__": - test() + unittest.main() diff --git a/Lib/sqlite3/test/userfunctions.py b/Lib/test/test_sqlite3/test_userfunctions.py rename from Lib/sqlite3/test/userfunctions.py rename to Lib/test/test_sqlite3/test_userfunctions.py --- a/Lib/sqlite3/test/userfunctions.py +++ b/Lib/test/test_sqlite3/test_userfunctions.py @@ -144,14 +144,14 @@ def tearDown(self): self.con.close() - def CheckFuncErrorOnCreate(self): + def testFuncErrorOnCreate(self): try: self.con.create_function("bla", -100, lambda x: 2*x) self.fail("should have raised an OperationalError") except sqlite.OperationalError: pass - def CheckFuncRefCount(self): + def testFuncRefCount(self): def getfunc(): def f(): return 1 @@ -163,28 +163,28 @@ cur = self.con.cursor() cur.execute("select reftest()") - def CheckFuncReturnText(self): + def testFuncReturnText(self): cur = self.con.cursor() cur.execute("select returntext()") val = cur.fetchone()[0] self.assertEqual(type(val), str) self.assertEqual(val, "foo") - def CheckFuncReturnUnicode(self): + def testFuncReturnUnicode(self): cur = self.con.cursor() cur.execute("select returnunicode()") val = cur.fetchone()[0] self.assertEqual(type(val), str) self.assertEqual(val, "bar") - def CheckFuncReturnInt(self): + def testFuncReturnInt(self): cur = self.con.cursor() cur.execute("select returnint()") val = cur.fetchone()[0] self.assertEqual(type(val), int) self.assertEqual(val, 42) - def CheckFuncReturnFloat(self): + def testFuncReturnFloat(self): cur = self.con.cursor() cur.execute("select returnfloat()") val = cur.fetchone()[0] @@ -192,27 +192,27 @@ if val < 3.139 or val > 3.141: self.fail("wrong value") - def CheckFuncReturnNull(self): + def testFuncReturnNull(self): cur = self.con.cursor() cur.execute("select returnnull()") val = cur.fetchone()[0] self.assertEqual(type(val), type(None)) self.assertEqual(val, None) - def CheckFuncReturnBlob(self): + def testFuncReturnBlob(self): cur = self.con.cursor() cur.execute("select returnblob()") val = cur.fetchone()[0] self.assertEqual(type(val), bytes) self.assertEqual(val, b"blob") - def CheckFuncReturnLongLong(self): + def testFuncReturnLongLong(self): cur = self.con.cursor() cur.execute("select returnlonglong()") val = cur.fetchone()[0] self.assertEqual(val, 1<<31) - def CheckFuncException(self): + def testFuncException(self): cur = self.con.cursor() try: cur.execute("select raiseexception()") @@ -221,37 +221,37 @@ except sqlite.OperationalError as e: self.assertEqual(e.args[0], 'user-defined function raised exception') - def CheckParamString(self): + def testParamString(self): cur = self.con.cursor() cur.execute("select isstring(?)", ("foo",)) val = cur.fetchone()[0] self.assertEqual(val, 1) - def CheckParamInt(self): + def testParamInt(self): cur = self.con.cursor() cur.execute("select isint(?)", (42,)) val = cur.fetchone()[0] self.assertEqual(val, 1) - def CheckParamFloat(self): + def testParamFloat(self): cur = self.con.cursor() cur.execute("select isfloat(?)", (3.14,)) val = cur.fetchone()[0] self.assertEqual(val, 1) - def CheckParamNone(self): + def testParamNone(self): cur = self.con.cursor() cur.execute("select isnone(?)", (None,)) val = cur.fetchone()[0] self.assertEqual(val, 1) - def CheckParamBlob(self): + def testParamBlob(self): cur = self.con.cursor() cur.execute("select isblob(?)", (memoryview(b"blob"),)) val = cur.fetchone()[0] self.assertEqual(val, 1) - def CheckParamLongLong(self): + def testParamLongLong(self): cur = self.con.cursor() cur.execute("select islonglong(?)", (1<<42,)) val = cur.fetchone()[0] @@ -286,14 +286,14 @@ #self.con.close() pass - def CheckAggrErrorOnCreate(self): + def testAggrErrorOnCreate(self): try: self.con.create_function("bla", -100, AggrSum) self.fail("should have raised an OperationalError") except sqlite.OperationalError: pass - def CheckAggrNoStep(self): + def testAggrNoStep(self): cur = self.con.cursor() try: cur.execute("select nostep(t) from test") @@ -301,7 +301,7 @@ except AttributeError as e: self.assertEqual(e.args[0], "'AggrNoStep' object has no attribute 'step'") - def CheckAggrNoFinalize(self): + def testAggrNoFinalize(self): cur = self.con.cursor() try: cur.execute("select nofinalize(t) from test") @@ -310,7 +310,7 @@ except sqlite.OperationalError as e: self.assertEqual(e.args[0], "user-defined aggregate's 'finalize' method raised error") - def CheckAggrExceptionInInit(self): + def testAggrExceptionInInit(self): cur = self.con.cursor() try: cur.execute("select excInit(t) from test") @@ -319,7 +319,7 @@ except sqlite.OperationalError as e: self.assertEqual(e.args[0], "user-defined aggregate's '__init__' method raised error") - def CheckAggrExceptionInStep(self): + def testAggrExceptionInStep(self): cur = self.con.cursor() try: cur.execute("select excStep(t) from test") @@ -328,7 +328,7 @@ except sqlite.OperationalError as e: self.assertEqual(e.args[0], "user-defined aggregate's 'step' method raised error") - def CheckAggrExceptionInFinalize(self): + def testAggrExceptionInFinalize(self): cur = self.con.cursor() try: cur.execute("select excFinalize(t) from test") @@ -337,37 +337,37 @@ except sqlite.OperationalError as e: self.assertEqual(e.args[0], "user-defined aggregate's 'finalize' method raised error") - def CheckAggrCheckParamStr(self): + def testAggrCheckParamStr(self): cur = self.con.cursor() cur.execute("select checkType('str', ?)", ("foo",)) val = cur.fetchone()[0] self.assertEqual(val, 1) - def CheckAggrCheckParamInt(self): + def testAggrCheckParamInt(self): cur = self.con.cursor() cur.execute("select checkType('int', ?)", (42,)) val = cur.fetchone()[0] self.assertEqual(val, 1) - def CheckAggrCheckParamFloat(self): + def testAggrCheckParamFloat(self): cur = self.con.cursor() cur.execute("select checkType('float', ?)", (3.14,)) val = cur.fetchone()[0] self.assertEqual(val, 1) - def CheckAggrCheckParamNone(self): + def testAggrCheckParamNone(self): cur = self.con.cursor() cur.execute("select checkType('None', ?)", (None,)) val = cur.fetchone()[0] self.assertEqual(val, 1) - def CheckAggrCheckParamBlob(self): + def testAggrCheckParamBlob(self): cur = self.con.cursor() cur.execute("select checkType('blob', ?)", (memoryview(b"blob"),)) val = cur.fetchone()[0] self.assertEqual(val, 1) - def CheckAggrCheckAggrSum(self): + def testAggrCheckAggrSum(self): cur = self.con.cursor() cur.execute("delete from test") cur.executemany("insert into test(i) values (?)", [(10,), (20,), (30,)]) @@ -446,23 +446,5 @@ return 2**32 return sqlite.SQLITE_OK - -def suite(): - function_suite = unittest.makeSuite(FunctionTests, "Check") - aggregate_suite = unittest.makeSuite(AggregateTests, "Check") - authorizer_suite = unittest.makeSuite(AuthorizerTests) - return unittest.TestSuite(( - function_suite, - aggregate_suite, - authorizer_suite, - unittest.makeSuite(AuthorizerRaiseExceptionTests), - unittest.makeSuite(AuthorizerIllegalTypeTests), - unittest.makeSuite(AuthorizerLargeIntegerTests), - )) - -def test(): - runner = unittest.TextTestRunner() - runner.run(suite()) - if __name__ == "__main__": - test() + unittest.main()