Cleaned up the test cases for long variables thanks to some closer looks after

they failed with Python 3.x initially.
This commit is contained in:
Anthony Tuininga 2008-10-17 04:09:35 +00:00
parent 699d1eef58
commit 9f0125410b

View File

@ -1,5 +1,7 @@
"""Module for testing long and long raw variables.""" """Module for testing long and long raw variables."""
import sys
class TestLongVar(BaseTestCase): class TestLongVar(BaseTestCase):
def __PerformTest(self, a_Type, a_InputType): def __PerformTest(self, a_Type, a_InputType):
@ -9,6 +11,10 @@ class TestLongVar(BaseTestCase):
char = chr(ord('A') + i - 1) char = chr(ord('A') + i - 1)
longString += char * 25000 longString += char * 25000
self.cursor.setinputsizes(p_LongString = a_InputType) self.cursor.setinputsizes(p_LongString = a_InputType)
if a_Type == "LongRaw" 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,
@ -18,7 +24,7 @@ class TestLongVar(BaseTestCase):
:p_LongString :p_LongString
)""" % (a_Type, a_Type), )""" % (a_Type, a_Type),
p_IntegerValue = i, p_IntegerValue = i,
p_LongString = longString) p_LongString = bindValue)
self.connection.commit() self.connection.commit()
self.cursor.setoutputsize(250000, 2) self.cursor.setoutputsize(250000, 2)
self.cursor.execute(""" self.cursor.execute("""
@ -33,8 +39,12 @@ class TestLongVar(BaseTestCase):
integerValue, fetchedValue = row integerValue, fetchedValue = row
char = chr(ord('A') + integerValue - 1) char = chr(ord('A') + integerValue - 1)
longString += char * 25000 longString += char * 25000
if a_Type == "LongRaw" and sys.version_info[0] >= 3:
actualValue = longString.encode("ascii")
else:
actualValue = longString
self.failUnlessEqual(len(fetchedValue), integerValue * 25000) self.failUnlessEqual(len(fetchedValue), integerValue * 25000)
self.failUnlessEqual(fetchedValue, longString) self.failUnlessEqual(fetchedValue, actualValue)
def testLongs(self): def testLongs(self):
"test binding and fetching long data" "test binding and fetching long data"
@ -62,13 +72,12 @@ class TestLongVar(BaseTestCase):
"test setoutputsizes is valid (all)" "test setoutputsizes is valid (all)"
self.cursor.setoutputsize(25000) self.cursor.setoutputsize(25000)
longVar = self.cursor.execute("select * from TestLongRaws")[1] longVar = self.cursor.execute("select * from TestLongRaws")[1]
self.failUnlessEqual(longVar.maxlength, self.failUnlessEqual(longVar.maxlength, 25004)
25004 * self.connection.maxBytesPerCharacter)
def testSetOutputSizesWrongColumn(self): def testSetOutputSizesWrongColumn(self):
"test setoutputsizes is valid (wrong column)" "test setoutputsizes is valid (wrong column)"
self.cursor.setoutputsize(25000, 1) self.cursor.setoutputsize(25000, 1)
longVar = self.cursor.execute("select * from TestLongRaws")[1] longVar = self.cursor.execute("select * from TestLongs")[1]
self.failUnlessEqual(longVar.maxlength, self.failUnlessEqual(longVar.maxlength,
131072 * self.connection.maxBytesPerCharacter) 131072 * self.connection.maxBytesPerCharacter)
@ -76,8 +85,7 @@ class TestLongVar(BaseTestCase):
"test setoutputsizes is valid (right column)" "test setoutputsizes is valid (right column)"
self.cursor.setoutputsize(35000, 2) self.cursor.setoutputsize(35000, 2)
longVar = self.cursor.execute("select * from TestLongRaws")[1] longVar = self.cursor.execute("select * from TestLongRaws")[1]
self.failUnlessEqual(longVar.maxlength, self.failUnlessEqual(longVar.maxlength, 35004)
35004 * self.connection.maxBytesPerCharacter)
def testArraySizeTooLarge(self): def testArraySizeTooLarge(self):
"test array size too large generates an exception" "test array size too large generates an exception"