Add Python 3 compatibility.
This commit is contained in:
@@ -27,9 +27,14 @@ import unittest2 as unittest
|
||||
|
||||
_THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
PY26 = not sys.version_info >= (2, 7)
|
||||
|
||||
def is_jython():
|
||||
return sys.platform.lower().startswith('java')
|
||||
|
||||
if PY26 and not is_jython:
|
||||
memoryview = buffer
|
||||
|
||||
class IntegrationTestBase(object):
|
||||
|
||||
def sql_file(self, filename):
|
||||
@@ -140,12 +145,12 @@ class IntegrationTestBase(object):
|
||||
"BLOCKING, DBL_COL, OPENED_AT, VALID, PRODUCT_NAME) " \
|
||||
"values (?, ?, ?, ?, ?, ?, ?, ?)"
|
||||
d = self.dbapi
|
||||
account_id = d.Timestamp(2010, 01, 26, 14, 31, 59)
|
||||
account_id = d.Timestamp(2010, 1, 26, 14, 31, 59)
|
||||
account_no = 20
|
||||
balance = 1.2
|
||||
blocking = 10.0
|
||||
dbl_col = 3.5
|
||||
opened_at = d.Date(2008, 02, 27)
|
||||
opened_at = d.Date(2008, 2, 27)
|
||||
valid = 1
|
||||
product_name = u'Savings account'
|
||||
parms = (account_id, account_no, balance, blocking, dbl_col,
|
||||
@@ -168,7 +173,7 @@ class IntegrationTestBase(object):
|
||||
"OPENED_AT_TIME) " \
|
||||
"values (?, ?, ?, ?)"
|
||||
d = self.dbapi
|
||||
account_id = d.Timestamp(2010, 01, 26, 14, 31, 59)
|
||||
account_id = d.Timestamp(2010, 1, 26, 14, 31, 59)
|
||||
account_no = 20
|
||||
balance = 1.2
|
||||
opened_at_time = d.Time(13, 59, 59)
|
||||
@@ -209,7 +214,8 @@ class SqliteTestBase(IntegrationTestBase):
|
||||
cursor = self.conn.cursor()
|
||||
stmt = "insert into ACCOUNT (ACCOUNT_ID, ACCOUNT_NO, BALANCE, " \
|
||||
"STUFF) values (?, ?, ?, ?)"
|
||||
stuff = self.dbapi.Binary('abcdef')
|
||||
binary_stuff = 'abcdef'.encode('UTF-8')
|
||||
stuff = self.dbapi.Binary(binary_stuff)
|
||||
parms = ('2009-09-11 14:15:22.123450', 20, 13.1, stuff)
|
||||
cursor.execute(stmt, parms)
|
||||
stmt = "select STUFF from ACCOUNT where ACCOUNT_NO = ?"
|
||||
@@ -218,7 +224,7 @@ class SqliteTestBase(IntegrationTestBase):
|
||||
result = cursor.fetchone()
|
||||
cursor.close()
|
||||
value = result[0]
|
||||
self.assertEqual(value, buffer('abcdef'))
|
||||
self.assertEqual(value, memoryview(binary_stuff))
|
||||
|
||||
@unittest.skipIf(is_jython(), "requires python")
|
||||
class SqlitePyTest(SqliteTestBase, unittest.TestCase):
|
||||
|
||||
+6
-6
@@ -53,7 +53,7 @@ class MockTest(unittest.TestCase):
|
||||
try:
|
||||
cursor.execute("dummy stmt")
|
||||
fail("expected exception")
|
||||
except jaydebeapi.DatabaseError, e:
|
||||
except jaydebeapi.DatabaseError as e:
|
||||
self.assertEquals(str(e), "java.sql.SQLException: expected")
|
||||
|
||||
def test_runtime_exception_on_execute(self):
|
||||
@@ -62,7 +62,7 @@ class MockTest(unittest.TestCase):
|
||||
try:
|
||||
cursor.execute("dummy stmt")
|
||||
fail("expected exception")
|
||||
except jaydebeapi.InterfaceError, e:
|
||||
except jaydebeapi.InterfaceError as e:
|
||||
self.assertEquals(str(e), "java.lang.RuntimeException: expected")
|
||||
|
||||
def test_sql_exception_on_commit(self):
|
||||
@@ -70,7 +70,7 @@ class MockTest(unittest.TestCase):
|
||||
try:
|
||||
self.conn.commit()
|
||||
fail("expected exception")
|
||||
except jaydebeapi.DatabaseError, e:
|
||||
except jaydebeapi.DatabaseError as e:
|
||||
self.assertEquals(str(e), "java.sql.SQLException: expected")
|
||||
|
||||
def test_runtime_exception_on_commit(self):
|
||||
@@ -78,7 +78,7 @@ class MockTest(unittest.TestCase):
|
||||
try:
|
||||
self.conn.commit()
|
||||
fail("expected exception")
|
||||
except jaydebeapi.InterfaceError, e:
|
||||
except jaydebeapi.InterfaceError as e:
|
||||
self.assertEquals(str(e), "java.lang.RuntimeException: expected")
|
||||
|
||||
def test_sql_exception_on_rollback(self):
|
||||
@@ -86,7 +86,7 @@ class MockTest(unittest.TestCase):
|
||||
try:
|
||||
self.conn.rollback()
|
||||
fail("expected exception")
|
||||
except jaydebeapi.DatabaseError, e:
|
||||
except jaydebeapi.DatabaseError as e:
|
||||
self.assertEquals(str(e), "java.sql.SQLException: expected")
|
||||
|
||||
def test_runtime_exception_on_rollback(self):
|
||||
@@ -94,5 +94,5 @@ class MockTest(unittest.TestCase):
|
||||
try:
|
||||
self.conn.rollback()
|
||||
fail("expected exception")
|
||||
except jaydebeapi.InterfaceError, e:
|
||||
except jaydebeapi.InterfaceError as e:
|
||||
self.assertEquals(str(e), "java.lang.RuntimeException: expected")
|
||||
|
||||
Reference in New Issue
Block a user