Tweak test cases to run properly under Python 3.x.

This commit is contained in:
Anthony Tuininga 2008-10-17 04:46:26 +00:00
parent 9f0125410b
commit 6b8ab25684

View File

@ -1,5 +1,7 @@
"""Module for testing LOB (CLOB and BLOB) variables.""" """Module for testing LOB (CLOB and BLOB) variables."""
import sys
class TestLobVar(BaseTestCase): class TestLobVar(BaseTestCase):
def __PerformTest(self, type, inputType): def __PerformTest(self, type, inputType):
@ -13,6 +15,10 @@ class TestLobVar(BaseTestCase):
elif inputType != directType: elif inputType != directType:
continue continue
self.cursor.setinputsizes(longString = inputType) self.cursor.setinputsizes(longString = inputType)
if type == "BLOB" and sys.version_info[0] >= 3:
bindValue = longString.encode("ascii")
else:
bindValue = longString
self.cursor.execute(""" self.cursor.execute("""
insert into Test%ss ( insert into Test%ss (
IntCol, IntCol,
@ -22,7 +28,7 @@ class TestLobVar(BaseTestCase):
:longString :longString
)""" % (type, type), )""" % (type, type),
integerValue = i, integerValue = i,
longString = longString) longString = bindValue)
self.connection.commit() self.connection.commit()
self.cursor.execute(""" self.cursor.execute("""
select * select *
@ -33,15 +39,25 @@ class TestLobVar(BaseTestCase):
integerValue, lob = row integerValue, lob = row
if integerValue == 0: if integerValue == 0:
self.failUnlessEqual(lob.size(), 0) self.failUnlessEqual(lob.size(), 0)
self.failUnlessEqual(lob.read(), "") expectedValue = ""
if type == "BLOB" and sys.version_info[0] >= 3:
expectedValue = expectedValue.encode("ascii")
self.failUnlessEqual(lob.read(), expectedValue)
else: else:
char = chr(ord('A') + integerValue - 1) char = chr(ord('A') + integerValue - 1)
prevChar = chr(ord('A') + integerValue - 2) prevChar = chr(ord('A') + integerValue - 2)
longString += char * 25000 longString += char * 25000
self.failUnlessEqual(lob.size(), len(longString)) if type == "BLOB" and sys.version_info[0] >= 3:
self.failUnlessEqual(lob.read(), longString) actualValue = longString.encode("ascii")
self.failUnlessEqual(str(lob), longString) char = char.encode("ascii")
self.failUnlessEqual(lob.read(len(longString)), char) prevChar = prevChar.encode("ascii")
else:
actualValue = longString
self.failUnlessEqual(lob.size(), len(actualValue))
self.failUnlessEqual(lob.read(), actualValue)
if type == "CLOB":
self.failUnlessEqual(str(lob), actualValue)
self.failUnlessEqual(lob.read(len(actualValue)), char)
if integerValue > 1: if integerValue > 1:
offset = (integerValue - 1) * 25000 - 4 offset = (integerValue - 1) * 25000 - 4
string = prevChar * 5 + char * 5 string = prevChar * 5 + char * 5
@ -50,6 +66,9 @@ class TestLobVar(BaseTestCase):
def __TestTrim(self, type): def __TestTrim(self, type):
self.cursor.execute("truncate table Test%ss" % type) self.cursor.execute("truncate table Test%ss" % type)
self.cursor.setinputsizes(longString = getattr(cx_Oracle, type)) self.cursor.setinputsizes(longString = getattr(cx_Oracle, type))
longString = "X" * 75000
if type == "BLOB" and sys.version_info[0] >= 3:
longString = longString.encode("ascii")
self.cursor.execute(""" self.cursor.execute("""
insert into Test%ss ( insert into Test%ss (
IntCol, IntCol,
@ -59,7 +78,7 @@ class TestLobVar(BaseTestCase):
:longString :longString
)""" % (type, type), )""" % (type, type),
integerValue = 1, integerValue = 1,
longString = "X" * 75000) longString = longString)
self.cursor.execute(""" self.cursor.execute("""
select %sCol select %sCol
from Test%ss from Test%ss