Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k ................ r73833 | gregory.p.smith | 2009-07-04 04:46:54 +0200 (Sa, 04 Jul 2009) | 20 lines Merged revisions 73825-73826 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r73825 | gregory.p.smith | 2009-07-03 18:49:29 -0700 (Fri, 03 Jul 2009) | 9 lines Use select.poll() in subprocess, when available, rather than select() so that it does not fail when file descriptors are large. Fixes issue3392. Patch largely contributed by Frank Chu (fpmc) with some improvements by me. See http://bugs.python.org/issue3392. ........ r73826 | gregory.p.smith | 2009-07-03 18:55:11 -0700 (Fri, 03 Jul 2009) | 2 lines news entry for r73825 ........ Candidate for backporting to release31-maint as it is a bug fix and changes no public API. ................ r73838 | gregory.p.smith | 2009-07-04 10:32:15 +0200 (Sa, 04 Jul 2009) | 2 lines change deprecated unittest method calls into their proper names. ................ r73850 | alexandre.vassalotti | 2009-07-05 07:38:18 +0200 (So, 05 Jul 2009) | 3 lines Issue 4509: Do not modify an array if we know the change would result in a failure due to exported buffers. ................ r73851 | alexandre.vassalotti | 2009-07-05 07:47:28 +0200 (So, 05 Jul 2009) | 2 lines Add more test cases to BaseTest.test_memoryview_no_resize. ................ r73852 | alexandre.vassalotti | 2009-07-05 08:25:14 +0200 (So, 05 Jul 2009) | 5 lines Fix array.extend and array.__iadd__ to handle the case where an array is extended with itself. This bug is specific the py3k version of arraymodule.c ................ r73856 | alexandre.vassalotti | 2009-07-05 08:42:44 +0200 (So, 05 Jul 2009) | 6 lines Issue 4005: Remove .sort() call on dict_keys object. This caused pydoc to fail when there was a zip file in sys.path. Patch contributed by Amaury Forgeot d'Arc. ................ r73857 | alexandre.vassalotti | 2009-07-05 08:50:08 +0200 (So, 05 Jul 2009) | 2 lines Add NEWS entries for the changes I made recently. ................
This commit is contained in:
parent
3deeed9a32
commit
ae83d6ee37
|
@ -318,8 +318,7 @@ try:
|
||||||
from zipimport import zipimporter
|
from zipimport import zipimporter
|
||||||
|
|
||||||
def iter_zipimport_modules(importer, prefix=''):
|
def iter_zipimport_modules(importer, prefix=''):
|
||||||
dirlist = zipimport._zip_directory_cache[importer.archive].keys()
|
dirlist = sorted(zipimport._zip_directory_cache[importer.archive])
|
||||||
dirlist.sort()
|
|
||||||
_prefix = importer.prefix
|
_prefix = importer.prefix
|
||||||
plen = len(_prefix)
|
plen = len(_prefix)
|
||||||
yielded = {}
|
yielded = {}
|
||||||
|
|
|
@ -44,39 +44,39 @@ class ModuleTests(unittest.TestCase):
|
||||||
"Warning is not a subclass of Exception")
|
"Warning is not a subclass of Exception")
|
||||||
|
|
||||||
def CheckError(self):
|
def CheckError(self):
|
||||||
self.failUnless(issubclass(sqlite.Error, Exception),
|
self.assertTrue(issubclass(sqlite.Error, Exception),
|
||||||
"Error is not a subclass of Exception")
|
"Error is not a subclass of Exception")
|
||||||
|
|
||||||
def CheckInterfaceError(self):
|
def CheckInterfaceError(self):
|
||||||
self.failUnless(issubclass(sqlite.InterfaceError, sqlite.Error),
|
self.assertTrue(issubclass(sqlite.InterfaceError, sqlite.Error),
|
||||||
"InterfaceError is not a subclass of Error")
|
"InterfaceError is not a subclass of Error")
|
||||||
|
|
||||||
def CheckDatabaseError(self):
|
def CheckDatabaseError(self):
|
||||||
self.failUnless(issubclass(sqlite.DatabaseError, sqlite.Error),
|
self.assertTrue(issubclass(sqlite.DatabaseError, sqlite.Error),
|
||||||
"DatabaseError is not a subclass of Error")
|
"DatabaseError is not a subclass of Error")
|
||||||
|
|
||||||
def CheckDataError(self):
|
def CheckDataError(self):
|
||||||
self.failUnless(issubclass(sqlite.DataError, sqlite.DatabaseError),
|
self.assertTrue(issubclass(sqlite.DataError, sqlite.DatabaseError),
|
||||||
"DataError is not a subclass of DatabaseError")
|
"DataError is not a subclass of DatabaseError")
|
||||||
|
|
||||||
def CheckOperationalError(self):
|
def CheckOperationalError(self):
|
||||||
self.failUnless(issubclass(sqlite.OperationalError, sqlite.DatabaseError),
|
self.assertTrue(issubclass(sqlite.OperationalError, sqlite.DatabaseError),
|
||||||
"OperationalError is not a subclass of DatabaseError")
|
"OperationalError is not a subclass of DatabaseError")
|
||||||
|
|
||||||
def CheckIntegrityError(self):
|
def CheckIntegrityError(self):
|
||||||
self.failUnless(issubclass(sqlite.IntegrityError, sqlite.DatabaseError),
|
self.assertTrue(issubclass(sqlite.IntegrityError, sqlite.DatabaseError),
|
||||||
"IntegrityError is not a subclass of DatabaseError")
|
"IntegrityError is not a subclass of DatabaseError")
|
||||||
|
|
||||||
def CheckInternalError(self):
|
def CheckInternalError(self):
|
||||||
self.failUnless(issubclass(sqlite.InternalError, sqlite.DatabaseError),
|
self.assertTrue(issubclass(sqlite.InternalError, sqlite.DatabaseError),
|
||||||
"InternalError is not a subclass of DatabaseError")
|
"InternalError is not a subclass of DatabaseError")
|
||||||
|
|
||||||
def CheckProgrammingError(self):
|
def CheckProgrammingError(self):
|
||||||
self.failUnless(issubclass(sqlite.ProgrammingError, sqlite.DatabaseError),
|
self.assertTrue(issubclass(sqlite.ProgrammingError, sqlite.DatabaseError),
|
||||||
"ProgrammingError is not a subclass of DatabaseError")
|
"ProgrammingError is not a subclass of DatabaseError")
|
||||||
|
|
||||||
def CheckNotSupportedError(self):
|
def CheckNotSupportedError(self):
|
||||||
self.failUnless(issubclass(sqlite.NotSupportedError,
|
self.assertTrue(issubclass(sqlite.NotSupportedError,
|
||||||
sqlite.DatabaseError),
|
sqlite.DatabaseError),
|
||||||
"NotSupportedError is not a subclass of DatabaseError")
|
"NotSupportedError is not a subclass of DatabaseError")
|
||||||
|
|
||||||
|
@ -126,16 +126,16 @@ class ConnectionTests(unittest.TestCase):
|
||||||
|
|
||||||
def CheckExceptions(self):
|
def CheckExceptions(self):
|
||||||
# Optional DB-API extension.
|
# Optional DB-API extension.
|
||||||
self.failUnlessEqual(self.cx.Warning, sqlite.Warning)
|
self.assertEqual(self.cx.Warning, sqlite.Warning)
|
||||||
self.failUnlessEqual(self.cx.Error, sqlite.Error)
|
self.assertEqual(self.cx.Error, sqlite.Error)
|
||||||
self.failUnlessEqual(self.cx.InterfaceError, sqlite.InterfaceError)
|
self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
|
||||||
self.failUnlessEqual(self.cx.DatabaseError, sqlite.DatabaseError)
|
self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
|
||||||
self.failUnlessEqual(self.cx.DataError, sqlite.DataError)
|
self.assertEqual(self.cx.DataError, sqlite.DataError)
|
||||||
self.failUnlessEqual(self.cx.OperationalError, sqlite.OperationalError)
|
self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
|
||||||
self.failUnlessEqual(self.cx.IntegrityError, sqlite.IntegrityError)
|
self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
|
||||||
self.failUnlessEqual(self.cx.InternalError, sqlite.InternalError)
|
self.assertEqual(self.cx.InternalError, sqlite.InternalError)
|
||||||
self.failUnlessEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
|
self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
|
||||||
self.failUnlessEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
|
self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
|
||||||
|
|
||||||
class CursorTests(unittest.TestCase):
|
class CursorTests(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -227,7 +227,7 @@ class CursorTests(unittest.TestCase):
|
||||||
self.cu.execute("insert into test(name) values ('foo')")
|
self.cu.execute("insert into test(name) values ('foo')")
|
||||||
self.cu.execute("select name from test where name=?", ["foo"])
|
self.cu.execute("select name from test where name=?", ["foo"])
|
||||||
row = self.cu.fetchone()
|
row = self.cu.fetchone()
|
||||||
self.failUnlessEqual(row[0], "foo")
|
self.assertEqual(row[0], "foo")
|
||||||
|
|
||||||
def CheckExecuteParamSequence(self):
|
def CheckExecuteParamSequence(self):
|
||||||
class L(object):
|
class L(object):
|
||||||
|
@ -240,13 +240,13 @@ class CursorTests(unittest.TestCase):
|
||||||
self.cu.execute("insert into test(name) values ('foo')")
|
self.cu.execute("insert into test(name) values ('foo')")
|
||||||
self.cu.execute("select name from test where name=?", L())
|
self.cu.execute("select name from test where name=?", L())
|
||||||
row = self.cu.fetchone()
|
row = self.cu.fetchone()
|
||||||
self.failUnlessEqual(row[0], "foo")
|
self.assertEqual(row[0], "foo")
|
||||||
|
|
||||||
def CheckExecuteDictMapping(self):
|
def CheckExecuteDictMapping(self):
|
||||||
self.cu.execute("insert into test(name) values ('foo')")
|
self.cu.execute("insert into test(name) values ('foo')")
|
||||||
self.cu.execute("select name from test where name=:name", {"name": "foo"})
|
self.cu.execute("select name from test where name=:name", {"name": "foo"})
|
||||||
row = self.cu.fetchone()
|
row = self.cu.fetchone()
|
||||||
self.failUnlessEqual(row[0], "foo")
|
self.assertEqual(row[0], "foo")
|
||||||
|
|
||||||
def CheckExecuteDictMapping_Mapping(self):
|
def CheckExecuteDictMapping_Mapping(self):
|
||||||
class D(dict):
|
class D(dict):
|
||||||
|
@ -256,7 +256,7 @@ class CursorTests(unittest.TestCase):
|
||||||
self.cu.execute("insert into test(name) values ('foo')")
|
self.cu.execute("insert into test(name) values ('foo')")
|
||||||
self.cu.execute("select name from test where name=:name", D())
|
self.cu.execute("select name from test where name=:name", D())
|
||||||
row = self.cu.fetchone()
|
row = self.cu.fetchone()
|
||||||
self.failUnlessEqual(row[0], "foo")
|
self.assertEqual(row[0], "foo")
|
||||||
|
|
||||||
def CheckExecuteDictMappingTooLittleArgs(self):
|
def CheckExecuteDictMappingTooLittleArgs(self):
|
||||||
self.cu.execute("insert into test(name) values ('foo')")
|
self.cu.execute("insert into test(name) values ('foo')")
|
||||||
|
@ -290,7 +290,7 @@ class CursorTests(unittest.TestCase):
|
||||||
self.cu.execute("insert into test(name) values ('foo')")
|
self.cu.execute("insert into test(name) values ('foo')")
|
||||||
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.cu.execute("update test set name='bar'")
|
||||||
self.failUnlessEqual(self.cu.rowcount, 2)
|
self.assertEqual(self.cu.rowcount, 2)
|
||||||
|
|
||||||
def CheckRowcountSelect(self):
|
def CheckRowcountSelect(self):
|
||||||
"""
|
"""
|
||||||
|
@ -299,12 +299,12 @@ class CursorTests(unittest.TestCase):
|
||||||
has thus to be -1.
|
has thus to be -1.
|
||||||
"""
|
"""
|
||||||
self.cu.execute("select 5 union select 6")
|
self.cu.execute("select 5 union select 6")
|
||||||
self.failUnlessEqual(self.cu.rowcount, -1)
|
self.assertEqual(self.cu.rowcount, -1)
|
||||||
|
|
||||||
def CheckRowcountExecutemany(self):
|
def CheckRowcountExecutemany(self):
|
||||||
self.cu.execute("delete from test")
|
self.cu.execute("delete from test")
|
||||||
self.cu.executemany("insert into test(name) values (?)", [(1,), (2,), (3,)])
|
self.cu.executemany("insert into test(name) values (?)", [(1,), (2,), (3,)])
|
||||||
self.failUnlessEqual(self.cu.rowcount, 3)
|
self.assertEqual(self.cu.rowcount, 3)
|
||||||
|
|
||||||
def CheckTotalChanges(self):
|
def CheckTotalChanges(self):
|
||||||
self.cu.execute("insert into test(name) values ('foo')")
|
self.cu.execute("insert into test(name) values ('foo')")
|
||||||
|
@ -377,24 +377,24 @@ class CursorTests(unittest.TestCase):
|
||||||
lst = []
|
lst = []
|
||||||
for row in self.cu:
|
for row in self.cu:
|
||||||
lst.append(row[0])
|
lst.append(row[0])
|
||||||
self.failUnlessEqual(lst[0], 5)
|
self.assertEqual(lst[0], 5)
|
||||||
self.failUnlessEqual(lst[1], 6)
|
self.assertEqual(lst[1], 6)
|
||||||
|
|
||||||
def CheckFetchone(self):
|
def CheckFetchone(self):
|
||||||
self.cu.execute("select name from test")
|
self.cu.execute("select name from test")
|
||||||
row = self.cu.fetchone()
|
row = self.cu.fetchone()
|
||||||
self.failUnlessEqual(row[0], "foo")
|
self.assertEqual(row[0], "foo")
|
||||||
row = self.cu.fetchone()
|
row = self.cu.fetchone()
|
||||||
self.failUnlessEqual(row, None)
|
self.assertEqual(row, None)
|
||||||
|
|
||||||
def CheckFetchoneNoStatement(self):
|
def CheckFetchoneNoStatement(self):
|
||||||
cur = self.cx.cursor()
|
cur = self.cx.cursor()
|
||||||
row = cur.fetchone()
|
row = cur.fetchone()
|
||||||
self.failUnlessEqual(row, None)
|
self.assertEqual(row, None)
|
||||||
|
|
||||||
def CheckArraySize(self):
|
def CheckArraySize(self):
|
||||||
# must default ot 1
|
# must default ot 1
|
||||||
self.failUnlessEqual(self.cu.arraysize, 1)
|
self.assertEqual(self.cu.arraysize, 1)
|
||||||
|
|
||||||
# now set to 2
|
# now set to 2
|
||||||
self.cu.arraysize = 2
|
self.cu.arraysize = 2
|
||||||
|
@ -407,27 +407,27 @@ class CursorTests(unittest.TestCase):
|
||||||
self.cu.execute("select name from test")
|
self.cu.execute("select name from test")
|
||||||
res = self.cu.fetchmany()
|
res = self.cu.fetchmany()
|
||||||
|
|
||||||
self.failUnlessEqual(len(res), 2)
|
self.assertEqual(len(res), 2)
|
||||||
|
|
||||||
def CheckFetchmany(self):
|
def CheckFetchmany(self):
|
||||||
self.cu.execute("select name from test")
|
self.cu.execute("select name from test")
|
||||||
res = self.cu.fetchmany(100)
|
res = self.cu.fetchmany(100)
|
||||||
self.failUnlessEqual(len(res), 1)
|
self.assertEqual(len(res), 1)
|
||||||
res = self.cu.fetchmany(100)
|
res = self.cu.fetchmany(100)
|
||||||
self.failUnlessEqual(res, [])
|
self.assertEqual(res, [])
|
||||||
|
|
||||||
def CheckFetchmanyKwArg(self):
|
def CheckFetchmanyKwArg(self):
|
||||||
"""Checks if fetchmany works with keyword arguments"""
|
"""Checks if fetchmany works with keyword arguments"""
|
||||||
self.cu.execute("select name from test")
|
self.cu.execute("select name from test")
|
||||||
res = self.cu.fetchmany(size=100)
|
res = self.cu.fetchmany(size=100)
|
||||||
self.failUnlessEqual(len(res), 1)
|
self.assertEqual(len(res), 1)
|
||||||
|
|
||||||
def CheckFetchall(self):
|
def CheckFetchall(self):
|
||||||
self.cu.execute("select name from test")
|
self.cu.execute("select name from test")
|
||||||
res = self.cu.fetchall()
|
res = self.cu.fetchall()
|
||||||
self.failUnlessEqual(len(res), 1)
|
self.assertEqual(len(res), 1)
|
||||||
res = self.cu.fetchall()
|
res = self.cu.fetchall()
|
||||||
self.failUnlessEqual(res, [])
|
self.assertEqual(res, [])
|
||||||
|
|
||||||
def CheckSetinputsizes(self):
|
def CheckSetinputsizes(self):
|
||||||
self.cu.setinputsizes([3, 4, 5])
|
self.cu.setinputsizes([3, 4, 5])
|
||||||
|
@ -440,7 +440,7 @@ class CursorTests(unittest.TestCase):
|
||||||
|
|
||||||
def CheckCursorConnection(self):
|
def CheckCursorConnection(self):
|
||||||
# Optional DB-API extension.
|
# Optional DB-API extension.
|
||||||
self.failUnlessEqual(self.cu.connection, self.cx)
|
self.assertEqual(self.cu.connection, self.cx)
|
||||||
|
|
||||||
def CheckWrongCursorCallable(self):
|
def CheckWrongCursorCallable(self):
|
||||||
try:
|
try:
|
||||||
|
@ -651,7 +651,7 @@ class ExtensionTests(unittest.TestCase):
|
||||||
""")
|
""")
|
||||||
cur.execute("select i from a")
|
cur.execute("select i from a")
|
||||||
res = cur.fetchone()[0]
|
res = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(res, 5)
|
self.assertEqual(res, 5)
|
||||||
|
|
||||||
def CheckScriptErrorIncomplete(self):
|
def CheckScriptErrorIncomplete(self):
|
||||||
con = sqlite.connect(":memory:")
|
con = sqlite.connect(":memory:")
|
||||||
|
@ -661,7 +661,7 @@ class ExtensionTests(unittest.TestCase):
|
||||||
cur.executescript("create table test(sadfsadfdsa")
|
cur.executescript("create table test(sadfsadfdsa")
|
||||||
except sqlite.ProgrammingError:
|
except sqlite.ProgrammingError:
|
||||||
raised = True
|
raised = True
|
||||||
self.failUnlessEqual(raised, True, "should have raised an exception")
|
self.assertEqual(raised, True, "should have raised an exception")
|
||||||
|
|
||||||
def CheckScriptErrorNormal(self):
|
def CheckScriptErrorNormal(self):
|
||||||
con = sqlite.connect(":memory:")
|
con = sqlite.connect(":memory:")
|
||||||
|
@ -671,26 +671,26 @@ class ExtensionTests(unittest.TestCase):
|
||||||
cur.executescript("create table test(sadfsadfdsa); select foo from hurz;")
|
cur.executescript("create table test(sadfsadfdsa); select foo from hurz;")
|
||||||
except sqlite.OperationalError:
|
except sqlite.OperationalError:
|
||||||
raised = True
|
raised = True
|
||||||
self.failUnlessEqual(raised, True, "should have raised an exception")
|
self.assertEqual(raised, True, "should have raised an exception")
|
||||||
|
|
||||||
def CheckConnectionExecute(self):
|
def CheckConnectionExecute(self):
|
||||||
con = sqlite.connect(":memory:")
|
con = sqlite.connect(":memory:")
|
||||||
result = con.execute("select 5").fetchone()[0]
|
result = con.execute("select 5").fetchone()[0]
|
||||||
self.failUnlessEqual(result, 5, "Basic test of Connection.execute")
|
self.assertEqual(result, 5, "Basic test of Connection.execute")
|
||||||
|
|
||||||
def CheckConnectionExecutemany(self):
|
def CheckConnectionExecutemany(self):
|
||||||
con = sqlite.connect(":memory:")
|
con = sqlite.connect(":memory:")
|
||||||
con.execute("create table test(foo)")
|
con.execute("create table test(foo)")
|
||||||
con.executemany("insert into test(foo) values (?)", [(3,), (4,)])
|
con.executemany("insert into test(foo) values (?)", [(3,), (4,)])
|
||||||
result = con.execute("select foo from test order by foo").fetchall()
|
result = con.execute("select foo from test order by foo").fetchall()
|
||||||
self.failUnlessEqual(result[0][0], 3, "Basic test of Connection.executemany")
|
self.assertEqual(result[0][0], 3, "Basic test of Connection.executemany")
|
||||||
self.failUnlessEqual(result[1][0], 4, "Basic test of Connection.executemany")
|
self.assertEqual(result[1][0], 4, "Basic test of Connection.executemany")
|
||||||
|
|
||||||
def CheckConnectionExecutescript(self):
|
def CheckConnectionExecutescript(self):
|
||||||
con = sqlite.connect(":memory:")
|
con = sqlite.connect(":memory:")
|
||||||
con.executescript("create table test(foo); insert into test(foo) values (5);")
|
con.executescript("create table test(foo); insert into test(foo) values (5);")
|
||||||
result = con.execute("select foo from test").fetchone()[0]
|
result = con.execute("select foo from test").fetchone()[0]
|
||||||
self.failUnlessEqual(result, 5, "Basic test of Connection.executescript")
|
self.assertEqual(result, 5, "Basic test of Connection.executescript")
|
||||||
|
|
||||||
class ClosedTests(unittest.TestCase):
|
class ClosedTests(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -47,7 +47,7 @@ class ConnectionFactoryTests(unittest.TestCase):
|
||||||
self.con.close()
|
self.con.close()
|
||||||
|
|
||||||
def CheckIsInstance(self):
|
def CheckIsInstance(self):
|
||||||
self.failUnless(isinstance(self.con,
|
self.assertTrue(isinstance(self.con,
|
||||||
MyConnection),
|
MyConnection),
|
||||||
"connection is not instance of MyConnection")
|
"connection is not instance of MyConnection")
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class CursorFactoryTests(unittest.TestCase):
|
||||||
|
|
||||||
def CheckIsInstance(self):
|
def CheckIsInstance(self):
|
||||||
cur = self.con.cursor(factory=MyCursor)
|
cur = self.con.cursor(factory=MyCursor)
|
||||||
self.failUnless(isinstance(cur,
|
self.assertTrue(isinstance(cur,
|
||||||
MyCursor),
|
MyCursor),
|
||||||
"cursor is not instance of MyCursor")
|
"cursor is not instance of MyCursor")
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ class RowFactoryTestsBackwardsCompat(unittest.TestCase):
|
||||||
cur = self.con.cursor(factory=MyCursor)
|
cur = self.con.cursor(factory=MyCursor)
|
||||||
cur.execute("select 4+5 as foo")
|
cur.execute("select 4+5 as foo")
|
||||||
row = cur.fetchone()
|
row = cur.fetchone()
|
||||||
self.failUnless(isinstance(row,
|
self.assertTrue(isinstance(row,
|
||||||
dict),
|
dict),
|
||||||
"row is not instance of dict")
|
"row is not instance of dict")
|
||||||
cur.close()
|
cur.close()
|
||||||
|
@ -87,28 +87,28 @@ class RowFactoryTests(unittest.TestCase):
|
||||||
def CheckCustomFactory(self):
|
def CheckCustomFactory(self):
|
||||||
self.con.row_factory = lambda cur, row: list(row)
|
self.con.row_factory = lambda cur, row: list(row)
|
||||||
row = self.con.execute("select 1, 2").fetchone()
|
row = self.con.execute("select 1, 2").fetchone()
|
||||||
self.failUnless(isinstance(row,
|
self.assertTrue(isinstance(row,
|
||||||
list),
|
list),
|
||||||
"row is not instance of list")
|
"row is not instance of list")
|
||||||
|
|
||||||
def CheckSqliteRowIndex(self):
|
def CheckSqliteRowIndex(self):
|
||||||
self.con.row_factory = sqlite.Row
|
self.con.row_factory = sqlite.Row
|
||||||
row = self.con.execute("select 1 as a, 2 as b").fetchone()
|
row = self.con.execute("select 1 as a, 2 as b").fetchone()
|
||||||
self.failUnless(isinstance(row,
|
self.assertTrue(isinstance(row,
|
||||||
sqlite.Row),
|
sqlite.Row),
|
||||||
"row is not instance of sqlite.Row")
|
"row is not instance of sqlite.Row")
|
||||||
|
|
||||||
col1, col2 = row["a"], row["b"]
|
col1, col2 = row["a"], row["b"]
|
||||||
self.failUnless(col1 == 1, "by name: wrong result for column 'a'")
|
self.assertTrue(col1 == 1, "by name: wrong result for column 'a'")
|
||||||
self.failUnless(col2 == 2, "by name: wrong result for column 'a'")
|
self.assertTrue(col2 == 2, "by name: wrong result for column 'a'")
|
||||||
|
|
||||||
col1, col2 = row["A"], row["B"]
|
col1, col2 = row["A"], row["B"]
|
||||||
self.failUnless(col1 == 1, "by name: wrong result for column 'A'")
|
self.assertTrue(col1 == 1, "by name: wrong result for column 'A'")
|
||||||
self.failUnless(col2 == 2, "by name: wrong result for column 'B'")
|
self.assertTrue(col2 == 2, "by name: wrong result for column 'B'")
|
||||||
|
|
||||||
col1, col2 = row[0], row[1]
|
col1, col2 = row[0], row[1]
|
||||||
self.failUnless(col1 == 1, "by index: wrong result for column 0")
|
self.assertTrue(col1 == 1, "by index: wrong result for column 0")
|
||||||
self.failUnless(col2 == 2, "by index: wrong result for column 1")
|
self.assertTrue(col2 == 2, "by index: wrong result for column 1")
|
||||||
|
|
||||||
def CheckSqliteRowIter(self):
|
def CheckSqliteRowIter(self):
|
||||||
"""Checks if the row object is iterable"""
|
"""Checks if the row object is iterable"""
|
||||||
|
@ -128,8 +128,8 @@ class RowFactoryTests(unittest.TestCase):
|
||||||
self.con.row_factory = sqlite.Row
|
self.con.row_factory = sqlite.Row
|
||||||
row = self.con.execute("select 1 as a, 2 as b").fetchone()
|
row = self.con.execute("select 1 as a, 2 as b").fetchone()
|
||||||
d = dict(row)
|
d = dict(row)
|
||||||
self.failUnlessEqual(d["a"], row["a"])
|
self.assertEqual(d["a"], row["a"])
|
||||||
self.failUnlessEqual(d["b"], row["b"])
|
self.assertEqual(d["b"], row["b"])
|
||||||
|
|
||||||
def CheckSqliteRowHashCmp(self):
|
def CheckSqliteRowHashCmp(self):
|
||||||
"""Checks if the row object compares and hashes correctly"""
|
"""Checks if the row object compares and hashes correctly"""
|
||||||
|
@ -138,18 +138,18 @@ class RowFactoryTests(unittest.TestCase):
|
||||||
row_2 = self.con.execute("select 1 as a, 2 as b").fetchone()
|
row_2 = self.con.execute("select 1 as a, 2 as b").fetchone()
|
||||||
row_3 = self.con.execute("select 1 as a, 3 as b").fetchone()
|
row_3 = self.con.execute("select 1 as a, 3 as b").fetchone()
|
||||||
|
|
||||||
self.failUnless(row_1 == row_1)
|
self.assertTrue(row_1 == row_1)
|
||||||
self.failUnless(row_1 == row_2)
|
self.assertTrue(row_1 == row_2)
|
||||||
self.failUnless(row_2 != row_3)
|
self.assertTrue(row_2 != row_3)
|
||||||
|
|
||||||
self.failIf(row_1 != row_1)
|
self.assertFalse(row_1 != row_1)
|
||||||
self.failIf(row_1 != row_2)
|
self.assertFalse(row_1 != row_2)
|
||||||
self.failIf(row_2 == row_3)
|
self.assertFalse(row_2 == row_3)
|
||||||
|
|
||||||
self.failUnlessEqual(row_1, row_2)
|
self.assertEqual(row_1, row_2)
|
||||||
self.failUnlessEqual(hash(row_1), hash(row_2))
|
self.assertEqual(hash(row_1), hash(row_2))
|
||||||
self.failIfEqual(row_1, row_3)
|
self.assertNotEqual(row_1, row_3)
|
||||||
self.failIfEqual(hash(row_1), hash(row_3))
|
self.assertNotEqual(hash(row_1), hash(row_3))
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.con.close()
|
self.con.close()
|
||||||
|
@ -161,21 +161,21 @@ class TextFactoryTests(unittest.TestCase):
|
||||||
def CheckUnicode(self):
|
def CheckUnicode(self):
|
||||||
austria = "Österreich"
|
austria = "Österreich"
|
||||||
row = self.con.execute("select ?", (austria,)).fetchone()
|
row = self.con.execute("select ?", (austria,)).fetchone()
|
||||||
self.failUnless(type(row[0]) == str, "type of row[0] must be unicode")
|
self.assertTrue(type(row[0]) == str, "type of row[0] must be unicode")
|
||||||
|
|
||||||
def CheckString(self):
|
def CheckString(self):
|
||||||
self.con.text_factory = bytes
|
self.con.text_factory = bytes
|
||||||
austria = "Österreich"
|
austria = "Österreich"
|
||||||
row = self.con.execute("select ?", (austria,)).fetchone()
|
row = self.con.execute("select ?", (austria,)).fetchone()
|
||||||
self.failUnless(type(row[0]) == bytes, "type of row[0] must be bytes")
|
self.assertTrue(type(row[0]) == bytes, "type of row[0] must be bytes")
|
||||||
self.failUnless(row[0] == austria.encode("utf-8"), "column must equal original data in UTF-8")
|
self.assertTrue(row[0] == austria.encode("utf-8"), "column must equal original data in UTF-8")
|
||||||
|
|
||||||
def CheckCustom(self):
|
def CheckCustom(self):
|
||||||
self.con.text_factory = lambda x: str(x, "utf-8", "ignore")
|
self.con.text_factory = lambda x: str(x, "utf-8", "ignore")
|
||||||
austria = "Österreich"
|
austria = "Österreich"
|
||||||
row = self.con.execute("select ?", (austria,)).fetchone()
|
row = self.con.execute("select ?", (austria,)).fetchone()
|
||||||
self.failUnless(type(row[0]) == str, "type of row[0] must be unicode")
|
self.assertTrue(type(row[0]) == str, "type of row[0] must be unicode")
|
||||||
self.failUnless(row[0].endswith("reich"), "column must contain original data")
|
self.assertTrue(row[0].endswith("reich"), "column must contain original data")
|
||||||
|
|
||||||
def CheckOptimizedUnicode(self):
|
def CheckOptimizedUnicode(self):
|
||||||
self.con.text_factory = sqlite.OptimizedUnicode
|
self.con.text_factory = sqlite.OptimizedUnicode
|
||||||
|
@ -183,8 +183,8 @@ class TextFactoryTests(unittest.TestCase):
|
||||||
germany = "Deutchland"
|
germany = "Deutchland"
|
||||||
a_row = self.con.execute("select ?", (austria,)).fetchone()
|
a_row = self.con.execute("select ?", (austria,)).fetchone()
|
||||||
d_row = self.con.execute("select ?", (germany,)).fetchone()
|
d_row = self.con.execute("select ?", (germany,)).fetchone()
|
||||||
self.failUnless(type(a_row[0]) == str, "type of non-ASCII row must be str")
|
self.assertTrue(type(a_row[0]) == str, "type of non-ASCII row must be str")
|
||||||
self.failUnless(type(d_row[0]) == str, "type of ASCII-only row must be str")
|
self.assertTrue(type(d_row[0]) == str, "type of ASCII-only row must be str")
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.con.close()
|
self.con.close()
|
||||||
|
|
|
@ -37,7 +37,7 @@ class CollationTests(unittest.TestCase):
|
||||||
con.create_collation("X", 42)
|
con.create_collation("X", 42)
|
||||||
self.fail("should have raised a TypeError")
|
self.fail("should have raised a TypeError")
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
self.failUnlessEqual(e.args[0], "parameter must be callable")
|
self.assertEqual(e.args[0], "parameter must be callable")
|
||||||
|
|
||||||
def CheckCreateCollationNotAscii(self):
|
def CheckCreateCollationNotAscii(self):
|
||||||
con = sqlite.connect(":memory:")
|
con = sqlite.connect(":memory:")
|
||||||
|
@ -74,7 +74,7 @@ class CollationTests(unittest.TestCase):
|
||||||
result = con.execute(sql).fetchall()
|
result = con.execute(sql).fetchall()
|
||||||
self.fail("should have raised an OperationalError")
|
self.fail("should have raised an OperationalError")
|
||||||
except sqlite.OperationalError as e:
|
except sqlite.OperationalError as e:
|
||||||
self.failUnlessEqual(e.args[0].lower(), "no such collation sequence: mycoll")
|
self.assertEqual(e.args[0].lower(), "no such collation sequence: mycoll")
|
||||||
|
|
||||||
def CheckCollationRegisterTwice(self):
|
def CheckCollationRegisterTwice(self):
|
||||||
"""
|
"""
|
||||||
|
@ -119,7 +119,7 @@ class ProgressTests(unittest.TestCase):
|
||||||
con.execute("""
|
con.execute("""
|
||||||
create table foo(a, b)
|
create table foo(a, b)
|
||||||
""")
|
""")
|
||||||
self.failUnless(progress_calls)
|
self.assertTrue(progress_calls)
|
||||||
|
|
||||||
|
|
||||||
def CheckOpcodeCount(self):
|
def CheckOpcodeCount(self):
|
||||||
|
@ -143,7 +143,7 @@ class ProgressTests(unittest.TestCase):
|
||||||
create table bar (a, b)
|
create table bar (a, b)
|
||||||
""")
|
""")
|
||||||
second_count = len(progress_calls)
|
second_count = len(progress_calls)
|
||||||
self.failUnless(first_count > second_count)
|
self.assertTrue(first_count > second_count)
|
||||||
|
|
||||||
def CheckCancelOperation(self):
|
def CheckCancelOperation(self):
|
||||||
"""
|
"""
|
||||||
|
@ -173,7 +173,7 @@ class ProgressTests(unittest.TestCase):
|
||||||
con.set_progress_handler(progress, 1)
|
con.set_progress_handler(progress, 1)
|
||||||
con.set_progress_handler(None, 1)
|
con.set_progress_handler(None, 1)
|
||||||
con.execute("select 1 union select 2 union select 3").fetchall()
|
con.execute("select 1 union select 2 union select 3").fetchall()
|
||||||
self.failUnlessEqual(action, 0, "progress handler was not cleared")
|
self.assertEqual(action, 0, "progress handler was not cleared")
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
collation_suite = unittest.makeSuite(CollationTests, "Check")
|
collation_suite = unittest.makeSuite(CollationTests, "Check")
|
||||||
|
|
|
@ -65,10 +65,10 @@ class RegressionTests(unittest.TestCase):
|
||||||
def CheckColumnNameWithSpaces(self):
|
def CheckColumnNameWithSpaces(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute('select 1 as "foo bar [datetime]"')
|
cur.execute('select 1 as "foo bar [datetime]"')
|
||||||
self.failUnlessEqual(cur.description[0][0], "foo bar")
|
self.assertEqual(cur.description[0][0], "foo bar")
|
||||||
|
|
||||||
cur.execute('select 1 as "foo baz"')
|
cur.execute('select 1 as "foo baz"')
|
||||||
self.failUnlessEqual(cur.description[0][0], "foo baz")
|
self.assertEqual(cur.description[0][0], "foo baz")
|
||||||
|
|
||||||
def CheckStatementAvailable(self):
|
def CheckStatementAvailable(self):
|
||||||
# pysqlite up to 2.3.2 crashed on this, because the active statement handle was not checked
|
# pysqlite up to 2.3.2 crashed on this, because the active statement handle was not checked
|
||||||
|
|
|
@ -58,14 +58,14 @@ class TransactionTests(unittest.TestCase):
|
||||||
self.cur1.execute("create table test2(j)")
|
self.cur1.execute("create table test2(j)")
|
||||||
self.cur2.execute("select i from test")
|
self.cur2.execute("select i from test")
|
||||||
res = self.cur2.fetchall()
|
res = self.cur2.fetchall()
|
||||||
self.failUnlessEqual(len(res), 1)
|
self.assertEqual(len(res), 1)
|
||||||
|
|
||||||
def CheckInsertStartsTransaction(self):
|
def CheckInsertStartsTransaction(self):
|
||||||
self.cur1.execute("create table test(i)")
|
self.cur1.execute("create table test(i)")
|
||||||
self.cur1.execute("insert into test(i) values (5)")
|
self.cur1.execute("insert into test(i) values (5)")
|
||||||
self.cur2.execute("select i from test")
|
self.cur2.execute("select i from test")
|
||||||
res = self.cur2.fetchall()
|
res = self.cur2.fetchall()
|
||||||
self.failUnlessEqual(len(res), 0)
|
self.assertEqual(len(res), 0)
|
||||||
|
|
||||||
def CheckUpdateStartsTransaction(self):
|
def CheckUpdateStartsTransaction(self):
|
||||||
self.cur1.execute("create table test(i)")
|
self.cur1.execute("create table test(i)")
|
||||||
|
@ -74,7 +74,7 @@ class TransactionTests(unittest.TestCase):
|
||||||
self.cur1.execute("update test set i=6")
|
self.cur1.execute("update test set i=6")
|
||||||
self.cur2.execute("select i from test")
|
self.cur2.execute("select i from test")
|
||||||
res = self.cur2.fetchone()[0]
|
res = self.cur2.fetchone()[0]
|
||||||
self.failUnlessEqual(res, 5)
|
self.assertEqual(res, 5)
|
||||||
|
|
||||||
def CheckDeleteStartsTransaction(self):
|
def CheckDeleteStartsTransaction(self):
|
||||||
self.cur1.execute("create table test(i)")
|
self.cur1.execute("create table test(i)")
|
||||||
|
@ -83,7 +83,7 @@ class TransactionTests(unittest.TestCase):
|
||||||
self.cur1.execute("delete from test")
|
self.cur1.execute("delete from test")
|
||||||
self.cur2.execute("select i from test")
|
self.cur2.execute("select i from test")
|
||||||
res = self.cur2.fetchall()
|
res = self.cur2.fetchall()
|
||||||
self.failUnlessEqual(len(res), 1)
|
self.assertEqual(len(res), 1)
|
||||||
|
|
||||||
def CheckReplaceStartsTransaction(self):
|
def CheckReplaceStartsTransaction(self):
|
||||||
self.cur1.execute("create table test(i)")
|
self.cur1.execute("create table test(i)")
|
||||||
|
@ -92,24 +92,24 @@ class TransactionTests(unittest.TestCase):
|
||||||
self.cur1.execute("replace into test(i) values (6)")
|
self.cur1.execute("replace into test(i) values (6)")
|
||||||
self.cur2.execute("select i from test")
|
self.cur2.execute("select i from test")
|
||||||
res = self.cur2.fetchall()
|
res = self.cur2.fetchall()
|
||||||
self.failUnlessEqual(len(res), 1)
|
self.assertEqual(len(res), 1)
|
||||||
self.failUnlessEqual(res[0][0], 5)
|
self.assertEqual(res[0][0], 5)
|
||||||
|
|
||||||
def CheckToggleAutoCommit(self):
|
def CheckToggleAutoCommit(self):
|
||||||
self.cur1.execute("create table test(i)")
|
self.cur1.execute("create table test(i)")
|
||||||
self.cur1.execute("insert into test(i) values (5)")
|
self.cur1.execute("insert into test(i) values (5)")
|
||||||
self.con1.isolation_level = None
|
self.con1.isolation_level = None
|
||||||
self.failUnlessEqual(self.con1.isolation_level, None)
|
self.assertEqual(self.con1.isolation_level, None)
|
||||||
self.cur2.execute("select i from test")
|
self.cur2.execute("select i from test")
|
||||||
res = self.cur2.fetchall()
|
res = self.cur2.fetchall()
|
||||||
self.failUnlessEqual(len(res), 1)
|
self.assertEqual(len(res), 1)
|
||||||
|
|
||||||
self.con1.isolation_level = "DEFERRED"
|
self.con1.isolation_level = "DEFERRED"
|
||||||
self.failUnlessEqual(self.con1.isolation_level , "DEFERRED")
|
self.assertEqual(self.con1.isolation_level , "DEFERRED")
|
||||||
self.cur1.execute("insert into test(i) values (5)")
|
self.cur1.execute("insert into test(i) values (5)")
|
||||||
self.cur2.execute("select i from test")
|
self.cur2.execute("select i from test")
|
||||||
res = self.cur2.fetchall()
|
res = self.cur2.fetchall()
|
||||||
self.failUnlessEqual(len(res), 1)
|
self.assertEqual(len(res), 1)
|
||||||
|
|
||||||
def CheckRaiseTimeout(self):
|
def CheckRaiseTimeout(self):
|
||||||
if sqlite.sqlite_version_info < (3, 2, 2):
|
if sqlite.sqlite_version_info < (3, 2, 2):
|
||||||
|
|
|
@ -39,27 +39,27 @@ class SqliteTypeTests(unittest.TestCase):
|
||||||
self.cur.execute("insert into test(s) values (?)", ("Österreich",))
|
self.cur.execute("insert into test(s) values (?)", ("Österreich",))
|
||||||
self.cur.execute("select s from test")
|
self.cur.execute("select s from test")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], "Österreich")
|
self.assertEqual(row[0], "Österreich")
|
||||||
|
|
||||||
def CheckSmallInt(self):
|
def CheckSmallInt(self):
|
||||||
self.cur.execute("insert into test(i) values (?)", (42,))
|
self.cur.execute("insert into test(i) values (?)", (42,))
|
||||||
self.cur.execute("select i from test")
|
self.cur.execute("select i from test")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], 42)
|
self.assertEqual(row[0], 42)
|
||||||
|
|
||||||
def CheckLargeInt(self):
|
def CheckLargeInt(self):
|
||||||
num = 2**40
|
num = 2**40
|
||||||
self.cur.execute("insert into test(i) values (?)", (num,))
|
self.cur.execute("insert into test(i) values (?)", (num,))
|
||||||
self.cur.execute("select i from test")
|
self.cur.execute("select i from test")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], num)
|
self.assertEqual(row[0], num)
|
||||||
|
|
||||||
def CheckFloat(self):
|
def CheckFloat(self):
|
||||||
val = 3.14
|
val = 3.14
|
||||||
self.cur.execute("insert into test(f) values (?)", (val,))
|
self.cur.execute("insert into test(f) values (?)", (val,))
|
||||||
self.cur.execute("select f from test")
|
self.cur.execute("select f from test")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], val)
|
self.assertEqual(row[0], val)
|
||||||
|
|
||||||
def CheckBlob(self):
|
def CheckBlob(self):
|
||||||
sample = b"Guglhupf"
|
sample = b"Guglhupf"
|
||||||
|
@ -67,12 +67,12 @@ class SqliteTypeTests(unittest.TestCase):
|
||||||
self.cur.execute("insert into test(b) values (?)", (val,))
|
self.cur.execute("insert into test(b) values (?)", (val,))
|
||||||
self.cur.execute("select b from test")
|
self.cur.execute("select b from test")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], sample)
|
self.assertEqual(row[0], sample)
|
||||||
|
|
||||||
def CheckUnicodeExecute(self):
|
def CheckUnicodeExecute(self):
|
||||||
self.cur.execute("select 'Österreich'")
|
self.cur.execute("select 'Österreich'")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], "Österreich")
|
self.assertEqual(row[0], "Österreich")
|
||||||
|
|
||||||
class DeclTypesTests(unittest.TestCase):
|
class DeclTypesTests(unittest.TestCase):
|
||||||
class Foo:
|
class Foo:
|
||||||
|
@ -133,14 +133,14 @@ class DeclTypesTests(unittest.TestCase):
|
||||||
self.cur.execute("insert into test(s) values (?)", ("foo",))
|
self.cur.execute("insert into test(s) values (?)", ("foo",))
|
||||||
self.cur.execute('select s as "s [WRONG]" from test')
|
self.cur.execute('select s as "s [WRONG]" from test')
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], "foo")
|
self.assertEqual(row[0], "foo")
|
||||||
|
|
||||||
def CheckSmallInt(self):
|
def CheckSmallInt(self):
|
||||||
# default
|
# default
|
||||||
self.cur.execute("insert into test(i) values (?)", (42,))
|
self.cur.execute("insert into test(i) values (?)", (42,))
|
||||||
self.cur.execute("select i from test")
|
self.cur.execute("select i from test")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], 42)
|
self.assertEqual(row[0], 42)
|
||||||
|
|
||||||
def CheckLargeInt(self):
|
def CheckLargeInt(self):
|
||||||
# default
|
# default
|
||||||
|
@ -148,7 +148,7 @@ class DeclTypesTests(unittest.TestCase):
|
||||||
self.cur.execute("insert into test(i) values (?)", (num,))
|
self.cur.execute("insert into test(i) values (?)", (num,))
|
||||||
self.cur.execute("select i from test")
|
self.cur.execute("select i from test")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], num)
|
self.assertEqual(row[0], num)
|
||||||
|
|
||||||
def CheckFloat(self):
|
def CheckFloat(self):
|
||||||
# custom
|
# custom
|
||||||
|
@ -156,20 +156,20 @@ class DeclTypesTests(unittest.TestCase):
|
||||||
self.cur.execute("insert into test(f) values (?)", (val,))
|
self.cur.execute("insert into test(f) values (?)", (val,))
|
||||||
self.cur.execute("select f from test")
|
self.cur.execute("select f from test")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], 47.2)
|
self.assertEqual(row[0], 47.2)
|
||||||
|
|
||||||
def CheckBool(self):
|
def CheckBool(self):
|
||||||
# custom
|
# custom
|
||||||
self.cur.execute("insert into test(b) values (?)", (False,))
|
self.cur.execute("insert into test(b) values (?)", (False,))
|
||||||
self.cur.execute("select b from test")
|
self.cur.execute("select b from test")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], False)
|
self.assertEqual(row[0], False)
|
||||||
|
|
||||||
self.cur.execute("delete from test")
|
self.cur.execute("delete from test")
|
||||||
self.cur.execute("insert into test(b) values (?)", (True,))
|
self.cur.execute("insert into test(b) values (?)", (True,))
|
||||||
self.cur.execute("select b from test")
|
self.cur.execute("select b from test")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], True)
|
self.assertEqual(row[0], True)
|
||||||
|
|
||||||
def CheckUnicode(self):
|
def CheckUnicode(self):
|
||||||
# default
|
# default
|
||||||
|
@ -177,14 +177,14 @@ class DeclTypesTests(unittest.TestCase):
|
||||||
self.cur.execute("insert into test(u) values (?)", (val,))
|
self.cur.execute("insert into test(u) values (?)", (val,))
|
||||||
self.cur.execute("select u from test")
|
self.cur.execute("select u from test")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], val)
|
self.assertEqual(row[0], val)
|
||||||
|
|
||||||
def CheckFoo(self):
|
def CheckFoo(self):
|
||||||
val = DeclTypesTests.Foo("bla")
|
val = DeclTypesTests.Foo("bla")
|
||||||
self.cur.execute("insert into test(foo) values (?)", (val,))
|
self.cur.execute("insert into test(foo) values (?)", (val,))
|
||||||
self.cur.execute("select foo from test")
|
self.cur.execute("select foo from test")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], val)
|
self.assertEqual(row[0], val)
|
||||||
|
|
||||||
def CheckUnsupportedSeq(self):
|
def CheckUnsupportedSeq(self):
|
||||||
class Bar: pass
|
class Bar: pass
|
||||||
|
@ -215,20 +215,20 @@ class DeclTypesTests(unittest.TestCase):
|
||||||
self.cur.execute("insert into test(bin) values (?)", (val,))
|
self.cur.execute("insert into test(bin) values (?)", (val,))
|
||||||
self.cur.execute("select bin from test")
|
self.cur.execute("select bin from test")
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
self.failUnlessEqual(row[0], sample)
|
self.assertEqual(row[0], sample)
|
||||||
|
|
||||||
def CheckNumber1(self):
|
def CheckNumber1(self):
|
||||||
self.cur.execute("insert into test(n1) values (5)")
|
self.cur.execute("insert into test(n1) values (5)")
|
||||||
value = self.cur.execute("select n1 from test").fetchone()[0]
|
value = self.cur.execute("select n1 from test").fetchone()[0]
|
||||||
# if the converter is not used, it's an int instead of a float
|
# if the converter is not used, it's an int instead of a float
|
||||||
self.failUnlessEqual(type(value), float)
|
self.assertEqual(type(value), float)
|
||||||
|
|
||||||
def CheckNumber2(self):
|
def CheckNumber2(self):
|
||||||
"""Checks wether converter names are cut off at '(' characters"""
|
"""Checks wether converter names are cut off at '(' characters"""
|
||||||
self.cur.execute("insert into test(n2) values (5)")
|
self.cur.execute("insert into test(n2) values (5)")
|
||||||
value = self.cur.execute("select n2 from test").fetchone()[0]
|
value = self.cur.execute("select n2 from test").fetchone()[0]
|
||||||
# if the converter is not used, it's an int instead of a float
|
# if the converter is not used, it's an int instead of a float
|
||||||
self.failUnlessEqual(type(value), float)
|
self.assertEqual(type(value), float)
|
||||||
|
|
||||||
class ColNamesTests(unittest.TestCase):
|
class ColNamesTests(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -257,28 +257,28 @@ class ColNamesTests(unittest.TestCase):
|
||||||
self.cur.execute("insert into test(x) values (?)", ("xxx",))
|
self.cur.execute("insert into test(x) values (?)", ("xxx",))
|
||||||
self.cur.execute("select x from test")
|
self.cur.execute("select x from test")
|
||||||
val = self.cur.fetchone()[0]
|
val = self.cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, "xxx")
|
self.assertEqual(val, "xxx")
|
||||||
|
|
||||||
def CheckNone(self):
|
def CheckNone(self):
|
||||||
self.cur.execute("insert into test(x) values (?)", (None,))
|
self.cur.execute("insert into test(x) values (?)", (None,))
|
||||||
self.cur.execute("select x from test")
|
self.cur.execute("select x from test")
|
||||||
val = self.cur.fetchone()[0]
|
val = self.cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, None)
|
self.assertEqual(val, None)
|
||||||
|
|
||||||
def CheckColName(self):
|
def CheckColName(self):
|
||||||
self.cur.execute("insert into test(x) values (?)", ("xxx",))
|
self.cur.execute("insert into test(x) values (?)", ("xxx",))
|
||||||
self.cur.execute('select x as "x [bar]" from test')
|
self.cur.execute('select x as "x [bar]" from test')
|
||||||
val = self.cur.fetchone()[0]
|
val = self.cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, "<xxx>")
|
self.assertEqual(val, "<xxx>")
|
||||||
|
|
||||||
# Check if the stripping of colnames works. Everything after the first
|
# Check if the stripping of colnames works. Everything after the first
|
||||||
# whitespace should be stripped.
|
# whitespace should be stripped.
|
||||||
self.failUnlessEqual(self.cur.description[0][0], "x")
|
self.assertEqual(self.cur.description[0][0], "x")
|
||||||
|
|
||||||
def CheckCaseInConverterName(self):
|
def CheckCaseInConverterName(self):
|
||||||
self.cur.execute("select 'other' as \"x [b1b1]\"")
|
self.cur.execute("select 'other' as \"x [b1b1]\"")
|
||||||
val = self.cur.fetchone()[0]
|
val = self.cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, "MARKER")
|
self.assertEqual(val, "MARKER")
|
||||||
|
|
||||||
def CheckCursorDescriptionNoRow(self):
|
def CheckCursorDescriptionNoRow(self):
|
||||||
"""
|
"""
|
||||||
|
@ -310,7 +310,7 @@ class ObjectAdaptationTests(unittest.TestCase):
|
||||||
def CheckCasterIsUsed(self):
|
def CheckCasterIsUsed(self):
|
||||||
self.cur.execute("select ?", (4,))
|
self.cur.execute("select ?", (4,))
|
||||||
val = self.cur.fetchone()[0]
|
val = self.cur.fetchone()[0]
|
||||||
self.failUnlessEqual(type(val), float)
|
self.assertEqual(type(val), float)
|
||||||
|
|
||||||
class BinaryConverterTests(unittest.TestCase):
|
class BinaryConverterTests(unittest.TestCase):
|
||||||
def convert(s):
|
def convert(s):
|
||||||
|
@ -327,7 +327,7 @@ class BinaryConverterTests(unittest.TestCase):
|
||||||
def CheckBinaryInputForConverter(self):
|
def CheckBinaryInputForConverter(self):
|
||||||
testdata = b"abcdefg" * 10
|
testdata = b"abcdefg" * 10
|
||||||
result = self.con.execute('select ? as "x [bin]"', (memoryview(zlib.compress(testdata)),)).fetchone()[0]
|
result = self.con.execute('select ? as "x [bin]"', (memoryview(zlib.compress(testdata)),)).fetchone()[0]
|
||||||
self.failUnlessEqual(testdata, result)
|
self.assertEqual(testdata, result)
|
||||||
|
|
||||||
class DateTimeTests(unittest.TestCase):
|
class DateTimeTests(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -344,14 +344,14 @@ class DateTimeTests(unittest.TestCase):
|
||||||
self.cur.execute("insert into test(d) values (?)", (d,))
|
self.cur.execute("insert into test(d) values (?)", (d,))
|
||||||
self.cur.execute("select d from test")
|
self.cur.execute("select d from test")
|
||||||
d2 = self.cur.fetchone()[0]
|
d2 = self.cur.fetchone()[0]
|
||||||
self.failUnlessEqual(d, d2)
|
self.assertEqual(d, d2)
|
||||||
|
|
||||||
def CheckSqliteTimestamp(self):
|
def CheckSqliteTimestamp(self):
|
||||||
ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0)
|
ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0)
|
||||||
self.cur.execute("insert into test(ts) values (?)", (ts,))
|
self.cur.execute("insert into test(ts) values (?)", (ts,))
|
||||||
self.cur.execute("select ts from test")
|
self.cur.execute("select ts from test")
|
||||||
ts2 = self.cur.fetchone()[0]
|
ts2 = self.cur.fetchone()[0]
|
||||||
self.failUnlessEqual(ts, ts2)
|
self.assertEqual(ts, ts2)
|
||||||
|
|
||||||
def CheckSqlTimestamp(self):
|
def CheckSqlTimestamp(self):
|
||||||
# The date functions are only available in SQLite version 3.1 or later
|
# The date functions are only available in SQLite version 3.1 or later
|
||||||
|
@ -363,22 +363,22 @@ class DateTimeTests(unittest.TestCase):
|
||||||
self.cur.execute("insert into test(ts) values (current_timestamp)")
|
self.cur.execute("insert into test(ts) values (current_timestamp)")
|
||||||
self.cur.execute("select ts from test")
|
self.cur.execute("select ts from test")
|
||||||
ts = self.cur.fetchone()[0]
|
ts = self.cur.fetchone()[0]
|
||||||
self.failUnlessEqual(type(ts), datetime.datetime)
|
self.assertEqual(type(ts), datetime.datetime)
|
||||||
self.failUnlessEqual(ts.year, now.year)
|
self.assertEqual(ts.year, now.year)
|
||||||
|
|
||||||
def CheckDateTimeSubSeconds(self):
|
def CheckDateTimeSubSeconds(self):
|
||||||
ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 500000)
|
ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 500000)
|
||||||
self.cur.execute("insert into test(ts) values (?)", (ts,))
|
self.cur.execute("insert into test(ts) values (?)", (ts,))
|
||||||
self.cur.execute("select ts from test")
|
self.cur.execute("select ts from test")
|
||||||
ts2 = self.cur.fetchone()[0]
|
ts2 = self.cur.fetchone()[0]
|
||||||
self.failUnlessEqual(ts, ts2)
|
self.assertEqual(ts, ts2)
|
||||||
|
|
||||||
def CheckDateTimeSubSecondsFloatingPoint(self):
|
def CheckDateTimeSubSecondsFloatingPoint(self):
|
||||||
ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 510241)
|
ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 510241)
|
||||||
self.cur.execute("insert into test(ts) values (?)", (ts,))
|
self.cur.execute("insert into test(ts) values (?)", (ts,))
|
||||||
self.cur.execute("select ts from test")
|
self.cur.execute("select ts from test")
|
||||||
ts2 = self.cur.fetchone()[0]
|
ts2 = self.cur.fetchone()[0]
|
||||||
self.failUnlessEqual(ts, ts2)
|
self.assertEqual(ts, ts2)
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
sqlite_type_suite = unittest.makeSuite(SqliteTypeTests, "Check")
|
sqlite_type_suite = unittest.makeSuite(SqliteTypeTests, "Check")
|
||||||
|
|
|
@ -161,28 +161,28 @@ class FunctionTests(unittest.TestCase):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select returntext()")
|
cur.execute("select returntext()")
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(type(val), str)
|
self.assertEqual(type(val), str)
|
||||||
self.failUnlessEqual(val, "foo")
|
self.assertEqual(val, "foo")
|
||||||
|
|
||||||
def CheckFuncReturnUnicode(self):
|
def CheckFuncReturnUnicode(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select returnunicode()")
|
cur.execute("select returnunicode()")
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(type(val), str)
|
self.assertEqual(type(val), str)
|
||||||
self.failUnlessEqual(val, "bar")
|
self.assertEqual(val, "bar")
|
||||||
|
|
||||||
def CheckFuncReturnInt(self):
|
def CheckFuncReturnInt(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select returnint()")
|
cur.execute("select returnint()")
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(type(val), int)
|
self.assertEqual(type(val), int)
|
||||||
self.failUnlessEqual(val, 42)
|
self.assertEqual(val, 42)
|
||||||
|
|
||||||
def CheckFuncReturnFloat(self):
|
def CheckFuncReturnFloat(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select returnfloat()")
|
cur.execute("select returnfloat()")
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(type(val), float)
|
self.assertEqual(type(val), float)
|
||||||
if val < 3.139 or val > 3.141:
|
if val < 3.139 or val > 3.141:
|
||||||
self.fail("wrong value")
|
self.fail("wrong value")
|
||||||
|
|
||||||
|
@ -190,15 +190,15 @@ class FunctionTests(unittest.TestCase):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select returnnull()")
|
cur.execute("select returnnull()")
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(type(val), type(None))
|
self.assertEqual(type(val), type(None))
|
||||||
self.failUnlessEqual(val, None)
|
self.assertEqual(val, None)
|
||||||
|
|
||||||
def CheckFuncReturnBlob(self):
|
def CheckFuncReturnBlob(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select returnblob()")
|
cur.execute("select returnblob()")
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(type(val), bytes)
|
self.assertEqual(type(val), bytes)
|
||||||
self.failUnlessEqual(val, b"blob")
|
self.assertEqual(val, b"blob")
|
||||||
|
|
||||||
def CheckFuncException(self):
|
def CheckFuncException(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
|
@ -207,37 +207,37 @@ class FunctionTests(unittest.TestCase):
|
||||||
cur.fetchone()
|
cur.fetchone()
|
||||||
self.fail("should have raised OperationalError")
|
self.fail("should have raised OperationalError")
|
||||||
except sqlite.OperationalError as e:
|
except sqlite.OperationalError as e:
|
||||||
self.failUnlessEqual(e.args[0], 'user-defined function raised exception')
|
self.assertEqual(e.args[0], 'user-defined function raised exception')
|
||||||
|
|
||||||
def CheckParamString(self):
|
def CheckParamString(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select isstring(?)", ("foo",))
|
cur.execute("select isstring(?)", ("foo",))
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, 1)
|
self.assertEqual(val, 1)
|
||||||
|
|
||||||
def CheckParamInt(self):
|
def CheckParamInt(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select isint(?)", (42,))
|
cur.execute("select isint(?)", (42,))
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, 1)
|
self.assertEqual(val, 1)
|
||||||
|
|
||||||
def CheckParamFloat(self):
|
def CheckParamFloat(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select isfloat(?)", (3.14,))
|
cur.execute("select isfloat(?)", (3.14,))
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, 1)
|
self.assertEqual(val, 1)
|
||||||
|
|
||||||
def CheckParamNone(self):
|
def CheckParamNone(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select isnone(?)", (None,))
|
cur.execute("select isnone(?)", (None,))
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, 1)
|
self.assertEqual(val, 1)
|
||||||
|
|
||||||
def CheckParamBlob(self):
|
def CheckParamBlob(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select isblob(?)", (memoryview(b"blob"),))
|
cur.execute("select isblob(?)", (memoryview(b"blob"),))
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, 1)
|
self.assertEqual(val, 1)
|
||||||
|
|
||||||
class AggregateTests(unittest.TestCase):
|
class AggregateTests(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -281,7 +281,7 @@ class AggregateTests(unittest.TestCase):
|
||||||
cur.execute("select nostep(t) from test")
|
cur.execute("select nostep(t) from test")
|
||||||
self.fail("should have raised an AttributeError")
|
self.fail("should have raised an AttributeError")
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
self.failUnlessEqual(e.args[0], "'AggrNoStep' object has no attribute 'step'")
|
self.assertEqual(e.args[0], "'AggrNoStep' object has no attribute 'step'")
|
||||||
|
|
||||||
def CheckAggrNoFinalize(self):
|
def CheckAggrNoFinalize(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
|
@ -290,7 +290,7 @@ class AggregateTests(unittest.TestCase):
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.fail("should have raised an OperationalError")
|
self.fail("should have raised an OperationalError")
|
||||||
except sqlite.OperationalError as e:
|
except sqlite.OperationalError as e:
|
||||||
self.failUnlessEqual(e.args[0], "user-defined aggregate's 'finalize' method raised error")
|
self.assertEqual(e.args[0], "user-defined aggregate's 'finalize' method raised error")
|
||||||
|
|
||||||
def CheckAggrExceptionInInit(self):
|
def CheckAggrExceptionInInit(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
|
@ -299,7 +299,7 @@ class AggregateTests(unittest.TestCase):
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.fail("should have raised an OperationalError")
|
self.fail("should have raised an OperationalError")
|
||||||
except sqlite.OperationalError as e:
|
except sqlite.OperationalError as e:
|
||||||
self.failUnlessEqual(e.args[0], "user-defined aggregate's '__init__' method raised error")
|
self.assertEqual(e.args[0], "user-defined aggregate's '__init__' method raised error")
|
||||||
|
|
||||||
def CheckAggrExceptionInStep(self):
|
def CheckAggrExceptionInStep(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
|
@ -308,7 +308,7 @@ class AggregateTests(unittest.TestCase):
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.fail("should have raised an OperationalError")
|
self.fail("should have raised an OperationalError")
|
||||||
except sqlite.OperationalError as e:
|
except sqlite.OperationalError as e:
|
||||||
self.failUnlessEqual(e.args[0], "user-defined aggregate's 'step' method raised error")
|
self.assertEqual(e.args[0], "user-defined aggregate's 'step' method raised error")
|
||||||
|
|
||||||
def CheckAggrExceptionInFinalize(self):
|
def CheckAggrExceptionInFinalize(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
|
@ -317,37 +317,37 @@ class AggregateTests(unittest.TestCase):
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.fail("should have raised an OperationalError")
|
self.fail("should have raised an OperationalError")
|
||||||
except sqlite.OperationalError as e:
|
except sqlite.OperationalError as e:
|
||||||
self.failUnlessEqual(e.args[0], "user-defined aggregate's 'finalize' method raised error")
|
self.assertEqual(e.args[0], "user-defined aggregate's 'finalize' method raised error")
|
||||||
|
|
||||||
def CheckAggrCheckParamStr(self):
|
def CheckAggrCheckParamStr(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select checkType('str', ?)", ("foo",))
|
cur.execute("select checkType('str', ?)", ("foo",))
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, 1)
|
self.assertEqual(val, 1)
|
||||||
|
|
||||||
def CheckAggrCheckParamInt(self):
|
def CheckAggrCheckParamInt(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select checkType('int', ?)", (42,))
|
cur.execute("select checkType('int', ?)", (42,))
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, 1)
|
self.assertEqual(val, 1)
|
||||||
|
|
||||||
def CheckAggrCheckParamFloat(self):
|
def CheckAggrCheckParamFloat(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select checkType('float', ?)", (3.14,))
|
cur.execute("select checkType('float', ?)", (3.14,))
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, 1)
|
self.assertEqual(val, 1)
|
||||||
|
|
||||||
def CheckAggrCheckParamNone(self):
|
def CheckAggrCheckParamNone(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select checkType('None', ?)", (None,))
|
cur.execute("select checkType('None', ?)", (None,))
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, 1)
|
self.assertEqual(val, 1)
|
||||||
|
|
||||||
def CheckAggrCheckParamBlob(self):
|
def CheckAggrCheckParamBlob(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
cur.execute("select checkType('blob', ?)", (memoryview(b"blob"),))
|
cur.execute("select checkType('blob', ?)", (memoryview(b"blob"),))
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, 1)
|
self.assertEqual(val, 1)
|
||||||
|
|
||||||
def CheckAggrCheckAggrSum(self):
|
def CheckAggrCheckAggrSum(self):
|
||||||
cur = self.con.cursor()
|
cur = self.con.cursor()
|
||||||
|
@ -355,7 +355,7 @@ class AggregateTests(unittest.TestCase):
|
||||||
cur.executemany("insert into test(i) values (?)", [(10,), (20,), (30,)])
|
cur.executemany("insert into test(i) values (?)", [(10,), (20,), (30,)])
|
||||||
cur.execute("select mysum(i) from test")
|
cur.execute("select mysum(i) from test")
|
||||||
val = cur.fetchone()[0]
|
val = cur.fetchone()[0]
|
||||||
self.failUnlessEqual(val, 60)
|
self.assertEqual(val, 60)
|
||||||
|
|
||||||
def authorizer_cb(action, arg1, arg2, dbname, source):
|
def authorizer_cb(action, arg1, arg2, dbname, source):
|
||||||
if action != sqlite.SQLITE_SELECT:
|
if action != sqlite.SQLITE_SELECT:
|
||||||
|
|
|
@ -371,6 +371,7 @@ if mswindows:
|
||||||
error = IOError
|
error = IOError
|
||||||
else:
|
else:
|
||||||
import select
|
import select
|
||||||
|
_has_poll = hasattr(select, 'poll')
|
||||||
import errno
|
import errno
|
||||||
import fcntl
|
import fcntl
|
||||||
import pickle
|
import pickle
|
||||||
|
@ -383,6 +384,11 @@ try:
|
||||||
except:
|
except:
|
||||||
MAXFD = 256
|
MAXFD = 256
|
||||||
|
|
||||||
|
# When select or poll has indicated that the file is writable,
|
||||||
|
# we can write up to _PIPE_BUF bytes without risk of blocking.
|
||||||
|
# POSIX defines PIPE_BUF as >= 512.
|
||||||
|
_PIPE_BUF = getattr(select, 'PIPE_BUF', 512)
|
||||||
|
|
||||||
_active = []
|
_active = []
|
||||||
|
|
||||||
def _cleanup():
|
def _cleanup():
|
||||||
|
@ -1173,19 +1179,103 @@ class Popen(object):
|
||||||
|
|
||||||
|
|
||||||
def _communicate(self, input):
|
def _communicate(self, input):
|
||||||
|
if self.stdin:
|
||||||
|
# Flush stdio buffer. This might block, if the user has
|
||||||
|
# been writing to .stdin in an uncontrolled fashion.
|
||||||
|
self.stdin.flush()
|
||||||
|
if not input:
|
||||||
|
self.stdin.close()
|
||||||
|
|
||||||
|
if _has_poll:
|
||||||
|
stdout, stderr = self._communicate_with_poll(input)
|
||||||
|
else:
|
||||||
|
stdout, stderr = self._communicate_with_select(input)
|
||||||
|
|
||||||
|
# All data exchanged. Translate lists into strings.
|
||||||
|
if stdout is not None:
|
||||||
|
stdout = b''.join(stdout)
|
||||||
|
if stderr is not None:
|
||||||
|
stderr = b''.join(stderr)
|
||||||
|
|
||||||
|
# Translate newlines, if requested.
|
||||||
|
# This also turns bytes into strings.
|
||||||
|
if self.universal_newlines:
|
||||||
|
if stdout is not None:
|
||||||
|
stdout = self._translate_newlines(stdout,
|
||||||
|
self.stdout.encoding)
|
||||||
|
if stderr is not None:
|
||||||
|
stderr = self._translate_newlines(stderr,
|
||||||
|
self.stderr.encoding)
|
||||||
|
|
||||||
|
self.wait()
|
||||||
|
return (stdout, stderr)
|
||||||
|
|
||||||
|
|
||||||
|
def _communicate_with_poll(self, input):
|
||||||
|
stdout = None # Return
|
||||||
|
stderr = None # Return
|
||||||
|
fd2file = {}
|
||||||
|
fd2output = {}
|
||||||
|
|
||||||
|
poller = select.poll()
|
||||||
|
def register_and_append(file_obj, eventmask):
|
||||||
|
poller.register(file_obj.fileno(), eventmask)
|
||||||
|
fd2file[file_obj.fileno()] = file_obj
|
||||||
|
|
||||||
|
def close_unregister_and_remove(fd):
|
||||||
|
poller.unregister(fd)
|
||||||
|
fd2file[fd].close()
|
||||||
|
fd2file.pop(fd)
|
||||||
|
|
||||||
|
if self.stdin and input:
|
||||||
|
register_and_append(self.stdin, select.POLLOUT)
|
||||||
|
|
||||||
|
select_POLLIN_POLLPRI = select.POLLIN | select.POLLPRI
|
||||||
|
if self.stdout:
|
||||||
|
register_and_append(self.stdout, select_POLLIN_POLLPRI)
|
||||||
|
fd2output[self.stdout.fileno()] = stdout = []
|
||||||
|
if self.stderr:
|
||||||
|
register_and_append(self.stderr, select_POLLIN_POLLPRI)
|
||||||
|
fd2output[self.stderr.fileno()] = stderr = []
|
||||||
|
|
||||||
|
input_offset = 0
|
||||||
|
while fd2file:
|
||||||
|
try:
|
||||||
|
ready = poller.poll()
|
||||||
|
except select.error as e:
|
||||||
|
if e.args[0] == errno.EINTR:
|
||||||
|
continue
|
||||||
|
raise
|
||||||
|
|
||||||
|
# XXX Rewrite these to use non-blocking I/O on the
|
||||||
|
# file objects; they are no longer using C stdio!
|
||||||
|
|
||||||
|
for fd, mode in ready:
|
||||||
|
if mode & select.POLLOUT:
|
||||||
|
chunk = input[input_offset : input_offset + _PIPE_BUF]
|
||||||
|
input_offset += os.write(fd, chunk)
|
||||||
|
if input_offset >= len(input):
|
||||||
|
close_unregister_and_remove(fd)
|
||||||
|
elif mode & select_POLLIN_POLLPRI:
|
||||||
|
data = os.read(fd, 4096)
|
||||||
|
if not data:
|
||||||
|
close_unregister_and_remove(fd)
|
||||||
|
fd2output[fd].append(data)
|
||||||
|
else:
|
||||||
|
# Ignore hang up or errors.
|
||||||
|
close_unregister_and_remove(fd)
|
||||||
|
|
||||||
|
return (stdout, stderr)
|
||||||
|
|
||||||
|
|
||||||
|
def _communicate_with_select(self, input):
|
||||||
read_set = []
|
read_set = []
|
||||||
write_set = []
|
write_set = []
|
||||||
stdout = None # Return
|
stdout = None # Return
|
||||||
stderr = None # Return
|
stderr = None # Return
|
||||||
|
|
||||||
if self.stdin:
|
if self.stdin and input:
|
||||||
# Flush stdio buffer. This might block, if the user has
|
write_set.append(self.stdin)
|
||||||
# been writing to .stdin in an uncontrolled fashion.
|
|
||||||
self.stdin.flush()
|
|
||||||
if input:
|
|
||||||
write_set.append(self.stdin)
|
|
||||||
else:
|
|
||||||
self.stdin.close()
|
|
||||||
if self.stdout:
|
if self.stdout:
|
||||||
read_set.append(self.stdout)
|
read_set.append(self.stdout)
|
||||||
stdout = []
|
stdout = []
|
||||||
|
@ -1206,10 +1296,7 @@ class Popen(object):
|
||||||
# file objects; they are no longer using C stdio!
|
# file objects; they are no longer using C stdio!
|
||||||
|
|
||||||
if self.stdin in wlist:
|
if self.stdin in wlist:
|
||||||
# When select has indicated that the file is writable,
|
chunk = input[input_offset : input_offset + _PIPE_BUF]
|
||||||
# we can write up to PIPE_BUF bytes without risk
|
|
||||||
# blocking. POSIX defines PIPE_BUF >= 512
|
|
||||||
chunk = input[input_offset : input_offset + 512]
|
|
||||||
bytes_written = os.write(self.stdin.fileno(), chunk)
|
bytes_written = os.write(self.stdin.fileno(), chunk)
|
||||||
input_offset += bytes_written
|
input_offset += bytes_written
|
||||||
if input_offset >= len(input):
|
if input_offset >= len(input):
|
||||||
|
@ -1230,25 +1317,9 @@ class Popen(object):
|
||||||
read_set.remove(self.stderr)
|
read_set.remove(self.stderr)
|
||||||
stderr.append(data)
|
stderr.append(data)
|
||||||
|
|
||||||
# All data exchanged. Translate lists into strings.
|
|
||||||
if stdout is not None:
|
|
||||||
stdout = b"".join(stdout)
|
|
||||||
if stderr is not None:
|
|
||||||
stderr = b"".join(stderr)
|
|
||||||
|
|
||||||
# Translate newlines, if requested.
|
|
||||||
# This also turns bytes into strings.
|
|
||||||
if self.universal_newlines:
|
|
||||||
if stdout is not None:
|
|
||||||
stdout = self._translate_newlines(stdout,
|
|
||||||
self.stdout.encoding)
|
|
||||||
if stderr is not None:
|
|
||||||
stderr = self._translate_newlines(stderr,
|
|
||||||
self.stderr.encoding)
|
|
||||||
|
|
||||||
self.wait()
|
|
||||||
return (stdout, stderr)
|
return (stdout, stderr)
|
||||||
|
|
||||||
|
|
||||||
def send_signal(self, sig):
|
def send_signal(self, sig):
|
||||||
"""Send a signal to the process
|
"""Send a signal to the process
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -272,6 +272,12 @@ class BaseTest(unittest.TestCase):
|
||||||
a,
|
a,
|
||||||
array.array(self.typecode, self.example[::-1]+2*self.example)
|
array.array(self.typecode, self.example[::-1]+2*self.example)
|
||||||
)
|
)
|
||||||
|
a = array.array(self.typecode, self.example)
|
||||||
|
a += a
|
||||||
|
self.assertEqual(
|
||||||
|
a,
|
||||||
|
array.array(self.typecode, self.example + self.example)
|
||||||
|
)
|
||||||
|
|
||||||
b = array.array(self.badtypecode())
|
b = array.array(self.badtypecode())
|
||||||
self.assertRaises(TypeError, a.__add__, b)
|
self.assertRaises(TypeError, a.__add__, b)
|
||||||
|
@ -667,6 +673,13 @@ class BaseTest(unittest.TestCase):
|
||||||
array.array(self.typecode, self.example+self.example[::-1])
|
array.array(self.typecode, self.example+self.example[::-1])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
a = array.array(self.typecode, self.example)
|
||||||
|
a.extend(a)
|
||||||
|
self.assertEqual(
|
||||||
|
a,
|
||||||
|
array.array(self.typecode, self.example+self.example)
|
||||||
|
)
|
||||||
|
|
||||||
b = array.array(self.badtypecode())
|
b = array.array(self.badtypecode())
|
||||||
self.assertRaises(TypeError, a.extend, b)
|
self.assertRaises(TypeError, a.extend, b)
|
||||||
|
|
||||||
|
@ -749,9 +762,31 @@ class BaseTest(unittest.TestCase):
|
||||||
ArraySubclassWithKwargs('b', newarg=1)
|
ArraySubclassWithKwargs('b', newarg=1)
|
||||||
|
|
||||||
def test_create_from_bytes(self):
|
def test_create_from_bytes(self):
|
||||||
|
# XXX This test probably needs to be moved in a subclass or
|
||||||
|
# generalized to use self.typecode.
|
||||||
a = array.array('H', b"1234")
|
a = array.array('H', b"1234")
|
||||||
self.assertEqual(len(a) * a.itemsize, 4)
|
self.assertEqual(len(a) * a.itemsize, 4)
|
||||||
|
|
||||||
|
def test_memoryview_no_resize(self):
|
||||||
|
# Test for issue 4509.
|
||||||
|
a = array.array(self.typecode, self.example)
|
||||||
|
m = memoryview(a)
|
||||||
|
expected = m.tobytes()
|
||||||
|
self.assertRaises(BufferError, a.pop, 0)
|
||||||
|
self.assertEqual(m.tobytes(), expected)
|
||||||
|
self.assertRaises(BufferError, a.remove, a[0])
|
||||||
|
self.assertEqual(m.tobytes(), expected)
|
||||||
|
self.assertRaises(BufferError, a.__setitem__, slice(0, 0), a)
|
||||||
|
self.assertEqual(m.tobytes(), expected)
|
||||||
|
self.assertRaises(BufferError, a.__delitem__, slice(0, len(a)))
|
||||||
|
self.assertEqual(m.tobytes(), expected)
|
||||||
|
self.assertRaises(BufferError, a.__imul__, 2)
|
||||||
|
self.assertEqual(m.tobytes(), expected)
|
||||||
|
self.assertRaises(BufferError, a.__iadd__, a)
|
||||||
|
self.assertEqual(m.tobytes(), expected)
|
||||||
|
self.assertRaises(BufferError, a.extend, a)
|
||||||
|
self.assertEqual(m.tobytes(), expected)
|
||||||
|
|
||||||
|
|
||||||
class StringTest(BaseTest):
|
class StringTest(BaseTest):
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,12 @@ class PkgutilTests(unittest.TestCase):
|
||||||
self.assertEqual(res1, RESOURCE_DATA)
|
self.assertEqual(res1, RESOURCE_DATA)
|
||||||
res2 = pkgutil.get_data(pkg, 'sub/res.txt')
|
res2 = pkgutil.get_data(pkg, 'sub/res.txt')
|
||||||
self.assertEqual(res2, RESOURCE_DATA)
|
self.assertEqual(res2, RESOURCE_DATA)
|
||||||
|
|
||||||
|
names = []
|
||||||
|
for loader, name, ispkg in pkgutil.iter_modules([zip_file]):
|
||||||
|
names.append(name)
|
||||||
|
self.assertEqual(names, ['test_getdata_zipfile'])
|
||||||
|
|
||||||
del sys.path[0]
|
del sys.path[0]
|
||||||
|
|
||||||
del sys.modules[pkg]
|
del sys.modules[pkg]
|
||||||
|
|
|
@ -798,8 +798,24 @@ class CommandTests(unittest.TestCase):
|
||||||
if dir is not None:
|
if dir is not None:
|
||||||
os.rmdir(dir)
|
os.rmdir(dir)
|
||||||
|
|
||||||
|
|
||||||
|
unit_tests = [ProcessTestCase, CommandTests]
|
||||||
|
|
||||||
|
if subprocess._has_poll:
|
||||||
|
class ProcessTestCaseNoPoll(ProcessTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
subprocess._has_poll = False
|
||||||
|
ProcessTestCase.setUp(self)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
subprocess._has_poll = True
|
||||||
|
ProcessTestCase.tearDown(self)
|
||||||
|
|
||||||
|
unit_tests.append(ProcessTestCaseNoPoll)
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
support.run_unittest(ProcessTestCase, CommandTests)
|
support.run_unittest(*unit_tests)
|
||||||
support.reap_children()
|
support.reap_children()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
13
Misc/NEWS
13
Misc/NEWS
|
@ -92,10 +92,23 @@ reported differently than it did with python 2.x.
|
||||||
- Issue #6323: The pdb debugger did not exit when running a script with a
|
- Issue #6323: The pdb debugger did not exit when running a script with a
|
||||||
syntax error.
|
syntax error.
|
||||||
|
|
||||||
|
- Issue #3392: The subprocess communicate() method no longer fails in select()
|
||||||
|
when file descriptors are large; communicate() now uses poll() when possible.
|
||||||
|
|
||||||
- Issue #6369: Fix an RLE decompression bug in the binhex module.
|
- Issue #6369: Fix an RLE decompression bug in the binhex module.
|
||||||
|
|
||||||
- Issue #6344: Fixed a crash of mmap.read() when passed a negative argument.
|
- Issue #6344: Fixed a crash of mmap.read() when passed a negative argument.
|
||||||
|
|
||||||
|
- Issue #4005: Fixed a crash of pydoc when there was a zip file present in
|
||||||
|
sys.path.
|
||||||
|
|
||||||
|
Extension Modules
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
- Issue #4509: array.array objects are no longer modified after an operation
|
||||||
|
failing due to the resize restriction in-place when the object has exported
|
||||||
|
buffers.
|
||||||
|
|
||||||
Build
|
Build
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
|
@ -735,6 +735,14 @@ array_ass_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
|
||||||
ihigh = Py_SIZE(a);
|
ihigh = Py_SIZE(a);
|
||||||
item = a->ob_item;
|
item = a->ob_item;
|
||||||
d = n - (ihigh-ilow);
|
d = n - (ihigh-ilow);
|
||||||
|
/* Issue #4509: If the array has exported buffers and the slice
|
||||||
|
assignment would change the size of the array, fail early to make
|
||||||
|
sure we don't modify it. */
|
||||||
|
if (d != 0 && a->ob_exports > 0) {
|
||||||
|
PyErr_SetString(PyExc_BufferError,
|
||||||
|
"cannot resize an array that is exporting buffers");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (d < 0) { /* Delete -d items */
|
if (d < 0) { /* Delete -d items */
|
||||||
memmove(item + (ihigh+d)*a->ob_descr->itemsize,
|
memmove(item + (ihigh+d)*a->ob_descr->itemsize,
|
||||||
item + ihigh*a->ob_descr->itemsize,
|
item + ihigh*a->ob_descr->itemsize,
|
||||||
|
@ -802,8 +810,8 @@ array_iter_extend(arrayobject *self, PyObject *bb)
|
||||||
static int
|
static int
|
||||||
array_do_extend(arrayobject *self, PyObject *bb)
|
array_do_extend(arrayobject *self, PyObject *bb)
|
||||||
{
|
{
|
||||||
Py_ssize_t size, oldsize;
|
Py_ssize_t size, oldsize, bbsize;
|
||||||
|
|
||||||
if (!array_Check(bb))
|
if (!array_Check(bb))
|
||||||
return array_iter_extend(self, bb);
|
return array_iter_extend(self, bb);
|
||||||
#define b ((arrayobject *)bb)
|
#define b ((arrayobject *)bb)
|
||||||
|
@ -818,11 +826,13 @@ array_do_extend(arrayobject *self, PyObject *bb)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
oldsize = Py_SIZE(self);
|
oldsize = Py_SIZE(self);
|
||||||
|
/* Get the size of bb before resizing the array since bb could be self. */
|
||||||
|
bbsize = Py_SIZE(bb);
|
||||||
size = oldsize + Py_SIZE(b);
|
size = oldsize + Py_SIZE(b);
|
||||||
if (array_resize(self, size) == -1)
|
if (array_resize(self, size) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
memcpy(self->ob_item + oldsize * self->ob_descr->itemsize,
|
memcpy(self->ob_item + oldsize * self->ob_descr->itemsize,
|
||||||
b->ob_item, Py_SIZE(b) * b->ob_descr->itemsize);
|
b->ob_item, bbsize * b->ob_descr->itemsize);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
#undef b
|
#undef b
|
||||||
|
|
Loading…
Reference in New Issue