Set up test cases for Python 3.x.

This commit is contained in:
Anthony Tuininga 2008-10-17 03:51:38 +00:00
parent 93bdbb7425
commit 8854fdde7d
6 changed files with 621 additions and 10 deletions

254
test/3kNumberVar.py Normal file
View File

@ -0,0 +1,254 @@
"""Module for testing number variables."""
import cx_Oracle
import decimal
class TestNumberVar(BaseTestCase):
def setUp(self):
BaseTestCase.setUp(self)
self.rawData = []
self.dataByKey = {}
for i in range(1, 11):
numberCol = i + i * 0.25
floatCol = i + i * 0.75
unconstrainedCol = i ** 3 + i * 0.5
if i % 2:
nullableCol = 143 ** i
else:
nullableCol = None
dataTuple = (i, numberCol, floatCol, unconstrainedCol, nullableCol)
self.rawData.append(dataTuple)
self.dataByKey[i] = dataTuple
def testBindDecimal(self):
"test binding in a decimal.Decimal"
self.cursor.execute("""
select * from TestNumbers
where NumberCol - :value1 - :value2 = trunc(NumberCol)""",
value1 = decimal.Decimal("0.20"),
value2 = decimal.Decimal("0.05"))
self.failUnlessEqual(self.cursor.fetchall(),
[self.dataByKey[1], self.dataByKey[5], self.dataByKey[9]])
def testBindFloat(self):
"test binding in a float"
self.cursor.execute("""
select * from TestNumbers
where NumberCol - :value = trunc(NumberCol)""",
value = 0.25)
self.failUnlessEqual(self.cursor.fetchall(),
[self.dataByKey[1], self.dataByKey[5], self.dataByKey[9]])
def testBindSmallLong(self):
"test binding in a small long integer"
self.cursor.execute("""
select * from TestNumbers
where IntCol = :value""",
value = 3)
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[3]])
def testBindLargeLong(self):
"test binding in a large long integer"
valueVar = self.cursor.var(cx_Oracle.NUMBER)
valueVar.setvalue(0, 6088343244)
self.cursor.execute("""
begin
:value := :value + 5;
end;""",
value = valueVar)
value = valueVar.getvalue()
self.failUnlessEqual(value, 6088343249)
def testBindIntegerAfterString(self):
"test binding in an number after setting input sizes to a string"
self.cursor.setinputsizes(value = 15)
self.cursor.execute("""
select * from TestNumbers
where IntCol = :value""",
value = 3)
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[3]])
def testBindNull(self):
"test binding in a null"
self.cursor.execute("""
select * from TestNumbers
where IntCol = :value""",
value = None)
self.failUnlessEqual(self.cursor.fetchall(), [])
def testBindNumberArrayDirect(self):
"test binding in a number array"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = [r[1] for r in self.rawData]
statement = """
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_StartValue, :p_Array);
end;"""
self.cursor.execute(statement,
p_ReturnValue = returnValue,
p_StartValue = 5,
p_Array = array)
self.failUnlessEqual(returnValue.getvalue(), 73.75)
array = list(range(15))
self.cursor.execute(statement,
p_StartValue = 10,
p_Array = array)
self.failUnlessEqual(returnValue.getvalue(), 115.0)
def testBindNumberArrayBySizes(self):
"test binding in a number array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(p_Array = [cx_Oracle.NUMBER, 10])
array = [r[1] for r in self.rawData]
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_StartValue, :p_Array);
end;""",
p_ReturnValue = returnValue,
p_StartValue = 6,
p_Array = array)
self.failUnlessEqual(returnValue.getvalue(), 74.75)
def testBindNumberArrayByVar(self):
"test binding in a number array (with arrayvar)"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = self.cursor.arrayvar(cx_Oracle.NUMBER,
[r[1] for r in self.rawData])
array.setvalue(0, [r[1] for r in self.rawData])
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_IntegerValue, :p_Array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 7,
p_Array = array)
self.failUnlessEqual(returnValue.getvalue(), 75.75)
def testBindZeroLengthNumberArrayByVar(self):
"test binding in a zero length number array (with arrayvar)"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 0)
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_IntegerValue, :p_Array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 8,
p_Array = array)
self.failUnlessEqual(returnValue.getvalue(), 8.0)
self.failUnlessEqual(array.getvalue(), [])
def testBindInOutNumberArrayByVar(self):
"test binding in/out a number array (with arrayvar)"
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 10)
originalData = [r[1] for r in self.rawData]
expectedData = [originalData[i - 1] * 10 for i in range(1, 6)] + \
originalData[5:]
array.setvalue(0, originalData)
self.cursor.execute("""
begin
pkg_TestNumberArrays.TestInOutArrays(:p_NumElems, :p_Array);
end;""",
p_NumElems = 5,
p_Array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindOutNumberArrayByVar(self):
"test binding out a Number array (with arrayvar)"
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 6)
expectedData = [i * 100 for i in range(1, 7)]
self.cursor.execute("""
begin
pkg_TestNumberArrays.TestOutArrays(:p_NumElems, :p_Array);
end;""",
p_NumElems = 6,
p_Array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindOutSetInputSizes(self):
"test binding out with set input sizes defined"
vars = self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
self.cursor.execute("""
begin
:value := 5;
end;""")
self.failUnlessEqual(vars["value"].getvalue(), 5)
def testBindInOutSetInputSizes(self):
"test binding in/out with set input sizes defined"
vars = self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
self.cursor.execute("""
begin
:value := :value + 5;
end;""",
value = 1.25)
self.failUnlessEqual(vars["value"].getvalue(), 6.25)
def testBindOutVar(self):
"test binding out with cursor.var() method"
var = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.execute("""
begin
:value := 5;
end;""",
value = var)
self.failUnlessEqual(var.getvalue(), 5)
def testBindInOutVarDirectSet(self):
"test binding in/out with cursor.var() method"
var = self.cursor.var(cx_Oracle.NUMBER)
var.setvalue(0, 2.25)
self.cursor.execute("""
begin
:value := :value + 5;
end;""",
value = var)
self.failUnlessEqual(var.getvalue(), 7.25)
def testCursorDescription(self):
"test cursor description is accurate"
self.cursor.execute("select * from TestNumbers")
self.failUnlessEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.NUMBER, 10, 22, 9, 0, 0),
('NUMBERCOL', cx_Oracle.NUMBER, 13, 22, 9, 2, 0),
('FLOATCOL', cx_Oracle.NUMBER, 127, 22, 126, -127, 0),
('UNCONSTRAINEDCOL', cx_Oracle.NUMBER, 127, 22, 0, -127, 0),
('NULLABLECOL', cx_Oracle.NUMBER, 39, 22, 38, 0, 1) ])
def testFetchAll(self):
"test that fetching all of the data returns the correct results"
self.cursor.execute("select * From TestNumbers order by IntCol")
self.failUnlessEqual(self.cursor.fetchall(), self.rawData)
self.failUnlessEqual(self.cursor.fetchall(), [])
def testFetchMany(self):
"test that fetching data in chunks returns the correct results"
self.cursor.execute("select * From TestNumbers order by IntCol")
self.failUnlessEqual(self.cursor.fetchmany(3), self.rawData[0:3])
self.failUnlessEqual(self.cursor.fetchmany(2), self.rawData[3:5])
self.failUnlessEqual(self.cursor.fetchmany(4), self.rawData[5:9])
self.failUnlessEqual(self.cursor.fetchmany(3), self.rawData[9:])
self.failUnlessEqual(self.cursor.fetchmany(3), [])
def testFetchOne(self):
"test that fetching a single row returns the correct results"
self.cursor.execute("""
select *
from TestNumbers
where IntCol in (3, 4)
order by IntCol""")
self.failUnlessEqual(self.cursor.fetchone(), self.dataByKey[3])
self.failUnlessEqual(self.cursor.fetchone(), self.dataByKey[4])
self.failUnlessEqual(self.cursor.fetchone(), None)
def testReturnAsFloat(self):
"test that fetching a floating point number returns such in Python"
self.cursor.execute("select 1.25 from dual")
result, = self.cursor.fetchone()
self.failUnlessEqual(result, 1.25)

286
test/3kStringVar.py Normal file
View File

@ -0,0 +1,286 @@
"""Module for testing string variables."""
class TestStringVar(BaseTestCase):
def setUp(self):
BaseTestCase.setUp(self)
self.rawData = []
self.dataByKey = {}
for i in range(1, 11):
stringCol = "String %d" % i
fixedCharCol = ("Fixed Char %d" % i).ljust(40)
rawCol = ("Raw %d" % i).encode("ascii")
if i % 2:
nullableCol = "Nullable %d" % i
else:
nullableCol = None
dataTuple = (i, stringCol, rawCol, fixedCharCol, nullableCol)
self.rawData.append(dataTuple)
self.dataByKey[i] = dataTuple
def testBindString(self):
"test binding in a string"
self.cursor.execute("""
select * from TestStrings
where StringCol = :p_Value""",
p_Value = "String 5")
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[5]])
def testBindDifferentVar(self):
"test binding a different variable on second execution"
retval_1 = self.cursor.var(cx_Oracle.STRING, 30)
retval_2 = self.cursor.var(cx_Oracle.STRING, 30)
self.cursor.execute("begin :retval := 'Called'; end;",
retval = retval_1)
self.failUnlessEqual(retval_1.getvalue(), "Called")
self.cursor.execute("begin :retval := 'Called'; end;",
retval = retval_2)
self.failUnlessEqual(retval_2.getvalue(), "Called")
def testBindStringAfterNumber(self):
"test binding in a string after setting input sizes to a number"
self.cursor.setinputsizes(p_Value = cx_Oracle.NUMBER)
self.cursor.execute("""
select * from TestStrings
where StringCol = :p_Value""",
p_Value = "String 6")
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[6]])
def testBindStringArrayDirect(self):
"test binding in a string array"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = [r[1] for r in self.rawData]
statement = """
begin
:p_ReturnValue := pkg_TestStringArrays.TestInArrays(
:p_IntegerValue, :p_Array);
end;"""
self.cursor.execute(statement,
p_ReturnValue = returnValue,
p_IntegerValue = 5,
p_Array = array)
self.failUnlessEqual(returnValue.getvalue(), 86)
array = [ "String - %d" % i for i in range(15) ]
self.cursor.execute(statement,
p_IntegerValue = 8,
p_Array = array)
self.failUnlessEqual(returnValue.getvalue(), 163)
def testBindStringArrayBySizes(self):
"test binding in a string array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(p_Array = [cx_Oracle.STRING, 10])
array = [r[1] for r in self.rawData]
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestStringArrays.TestInArrays(
:p_IntegerValue, :p_Array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 6,
p_Array = array)
self.failUnlessEqual(returnValue.getvalue(), 87)
def testBindStringArrayByVar(self):
"test binding in a string array (with arrayvar)"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
array = self.cursor.arrayvar(cx_Oracle.STRING, 10, 20)
array.setvalue(0, [r[1] for r in self.rawData])
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestStringArrays.TestInArrays(
:p_IntegerValue, :p_Array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 7,
p_Array = array)
self.failUnlessEqual(returnValue.getvalue(), 88)
def testBindInOutStringArrayByVar(self):
"test binding in/out a string array (with arrayvar)"
array = self.cursor.arrayvar(cx_Oracle.STRING, 10, 100)
originalData = [r[1] for r in self.rawData]
expectedData = ["Converted element # %d originally had length %d" % \
(i, len(originalData[i - 1])) for i in range(1, 6)] + \
originalData[5:]
array.setvalue(0, originalData)
self.cursor.execute("""
begin
pkg_TestStringArrays.TestInOutArrays(:p_NumElems, :p_Array);
end;""",
p_NumElems = 5,
p_Array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindOutStringArrayByVar(self):
"test binding out a string array (with arrayvar)"
array = self.cursor.arrayvar(cx_Oracle.STRING, 6, 100)
expectedData = ["Test out element # %d" % i for i in range(1, 7)]
self.cursor.execute("""
begin
pkg_TestStringArrays.TestOutArrays(:p_NumElems, :p_Array);
end;""",
p_NumElems = 6,
p_Array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindRaw(self):
"test binding in a raw"
self.cursor.setinputsizes(p_Value = cx_Oracle.BINARY)
self.cursor.execute("""
select * from TestStrings
where RawCol = :p_Value""",
p_Value = b"Raw 4")
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[4]])
def testBindAndFetchRowid(self):
"test binding (and fetching) a rowid"
self.cursor.execute("""
select rowid
from TestStrings
where IntCol = 3""")
rowid, = self.cursor.fetchone()
self.cursor.execute("""
select *
from TestStrings
where rowid = :p_Value""",
p_Value = rowid)
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[3]])
def testBindNull(self):
"test binding in a null"
self.cursor.execute("""
select * from TestStrings
where StringCol = :p_Value""",
p_Value = None)
self.failUnlessEqual(self.cursor.fetchall(), [])
def testBindOutSetInputSizesByType(self):
"test binding out with set input sizes defined (by type)"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.STRING)
self.cursor.execute("""
begin
:p_Value := 'TSI';
end;""")
self.failUnlessEqual(vars["p_Value"].getvalue(), "TSI")
def testBindOutSetInputSizesByInteger(self):
"test binding out with set input sizes defined (by integer)"
vars = self.cursor.setinputsizes(p_Value = 30)
self.cursor.execute("""
begin
:p_Value := 'TSI (I)';
end;""")
self.failUnlessEqual(vars["p_Value"].getvalue(), "TSI (I)")
def testBindInOutSetInputSizesByType(self):
"test binding in/out with set input sizes defined (by type)"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.STRING)
self.cursor.execute("""
begin
:p_Value := :p_Value || ' TSI';
end;""",
p_Value = "InVal")
self.failUnlessEqual(vars["p_Value"].getvalue(), "InVal TSI")
def testBindInOutSetInputSizesByInteger(self):
"test binding in/out with set input sizes defined (by integer)"
vars = self.cursor.setinputsizes(p_Value = 30)
self.cursor.execute("""
begin
:p_Value := :p_Value || ' TSI (I)';
end;""",
p_Value = "InVal")
self.failUnlessEqual(vars["p_Value"].getvalue(), "InVal TSI (I)")
def testBindOutVar(self):
"test binding out with cursor.var() method"
var = self.cursor.var(cx_Oracle.STRING)
self.cursor.execute("""
begin
:p_Value := 'TSI (VAR)';
end;""",
p_Value = var)
self.failUnlessEqual(var.getvalue(), "TSI (VAR)")
def testBindInOutVarDirectSet(self):
"test binding in/out with cursor.var() method"
var = self.cursor.var(cx_Oracle.STRING)
var.setvalue(0, "InVal")
self.cursor.execute("""
begin
:p_Value := :p_Value || ' TSI (VAR)';
end;""",
p_Value = var)
self.failUnlessEqual(var.getvalue(), "InVal TSI (VAR)")
def testBindLongString(self):
"test that binding a long string succeeds"
self.cursor.execute("""
declare
t_Temp varchar2(10000);
begin
t_Temp := :bigString;
end;""",
bigString = "X" * 10000)
def testBindLongStringAfterSettingSize(self):
"test that setinputsizes() returns a long variable"
var = self.cursor.setinputsizes(test = 90000)["test"]
self.failUnlessEqual(type(var), cx_Oracle.LONG_STRING)
inString = "1234567890" * 9000
var.setvalue(0, inString)
outString = var.getvalue()
self.failUnlessEqual(inString, outString,
"output does not match: in was %d, out was %d" % \
(len(inString), len(outString)))
def testStringMaximumReached(self):
"test that an error is raised when maximum string length exceeded"
var = self.cursor.setinputsizes(test = 100)["test"]
inString = "1234567890" * 400
var.setvalue(0, inString)
outString = var.getvalue()
self.failUnlessEqual(inString, outString,
"output does not match: in was %d, out was %d" % \
(len(inString), len(outString)))
badStringSize = 4000 * self.connection.maxBytesPerCharacter + 1
inString = "X" * badStringSize
self.failUnlessRaises(ValueError, var.setvalue, 0, inString)
def testCursorDescription(self):
"test cursor description is accurate"
self.cursor.execute("select * from TestStrings")
self.failUnlessEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.NUMBER, 10, 22, 9, 0, 0),
('STRINGCOL', cx_Oracle.STRING, 20, 20, 0, 0, 0),
('RAWCOL', cx_Oracle.BINARY, 30, 30, 0, 0, 0),
('FIXEDCHARCOL', cx_Oracle.FIXED_CHAR, 40, 40, 0, 0, 0),
('NULLABLECOL', cx_Oracle.STRING, 50, 50, 0, 0, 1) ])
def testFetchAll(self):
"test that fetching all of the data returns the correct results"
self.cursor.execute("select * From TestStrings order by IntCol")
self.failUnlessEqual(self.cursor.fetchall(), self.rawData)
self.failUnlessEqual(self.cursor.fetchall(), [])
def testFetchMany(self):
"test that fetching data in chunks returns the correct results"
self.cursor.execute("select * From TestStrings order by IntCol")
self.failUnlessEqual(self.cursor.fetchmany(3), self.rawData[0:3])
self.failUnlessEqual(self.cursor.fetchmany(2), self.rawData[3:5])
self.failUnlessEqual(self.cursor.fetchmany(4), self.rawData[5:9])
self.failUnlessEqual(self.cursor.fetchmany(3), self.rawData[9:])
self.failUnlessEqual(self.cursor.fetchmany(3), [])
def testFetchOne(self):
"test that fetching a single row returns the correct results"
self.cursor.execute("""
select *
from TestStrings
where IntCol in (3, 4)
order by IntCol""")
self.failUnlessEqual(self.cursor.fetchone(), self.dataByKey[3])
self.failUnlessEqual(self.cursor.fetchone(), self.dataByKey[4])
self.failUnlessEqual(self.cursor.fetchone(), None)

View File

@ -1,6 +1,7 @@
"""Module for testing cursor objects.""" """Module for testing cursor objects."""
import cx_Oracle import cx_Oracle
import sys
class TestCursor(BaseTestCase): class TestCursor(BaseTestCase):
@ -175,9 +176,15 @@ class TestCursor(BaseTestCase):
where IntCol between 1 and 3 where IntCol between 1 and 3
order by IntCol""") order by IntCol""")
testIter = iter(self.cursor) testIter = iter(self.cursor)
value, = testIter.next() if sys.version_info[0] >= 3:
value, = next(testIter)
else:
value, = testIter.next()
self.cursor.execute("insert into TestExecuteMany values (1)") self.cursor.execute("insert into TestExecuteMany values (1)")
self.failUnlessRaises(cx_Oracle.InterfaceError, testIter.next) if sys.version_info[0] >= 3:
self.failUnlessRaises(cx_Oracle.InterfaceError, next, testIter)
else:
self.failUnlessRaises(cx_Oracle.InterfaceError, testIter.next)
def testBindNames(self): def testBindNames(self):
"""test that bindnames() works correctly.""" """test that bindnames() works correctly."""

View File

@ -1,5 +1,6 @@
"""Module for testing cursor variables.""" """Module for testing cursor variables."""
import struct
import sys import sys
class TestCursorVar(BaseTestCase): class TestCursorVar(BaseTestCase):
@ -36,10 +37,7 @@ class TestCursorVar(BaseTestCase):
cursor(select IntCol + 1 from dual) CursorValue cursor(select IntCol + 1 from dual) CursorValue
from TestNumbers from TestNumbers
order by IntCol""") order by IntCol""")
if len(str(sys.maxint)) == 10: size = len(struct.pack("i", 1))
size = 4
else:
size = 8
self.failUnlessEqual(self.cursor.description, self.failUnlessEqual(self.cursor.description,
[ ('INTCOL', cx_Oracle.NUMBER, 10, 22, 9, 0, 0), [ ('INTCOL', cx_Oracle.NUMBER, 10, 22, 9, 0, 0),
('CURSORVALUE', cx_Oracle.CURSOR, -1, size, 0, 0, 1) ]) ('CURSORVALUE', cx_Oracle.CURSOR, -1, size, 0, 0, 1) ])

View File

@ -12,7 +12,7 @@ import TestEnv
if len(sys.argv) > 1: if len(sys.argv) > 1:
moduleNames = [os.path.splitext(v)[0] for v in sys.argv[1:]] moduleNames = [os.path.splitext(v)[0] for v in sys.argv[1:]]
elif hasattr(cx_Oracle, "UNICODE") or sys.version_info[0] >= 3: elif hasattr(cx_Oracle, "UNICODE"):
moduleNames = [ moduleNames = [
"Connection", "Connection",
"Cursor", "Cursor",
@ -24,10 +24,9 @@ elif hasattr(cx_Oracle, "UNICODE") or sys.version_info[0] >= 3:
"ObjectVar", "ObjectVar",
"SessionPool", "SessionPool",
"StringVar", "StringVar",
"TimestampVar" "TimestampVar",
"UnicodeVar"
] ]
if sys.version_info[0] < 3:
moduleNames.append("UnicodeVar")
else: else:
moduleNames = [ moduleNames = [
"uConnection", "uConnection",

67
test/test3k.py Normal file
View File

@ -0,0 +1,67 @@
"""Runs all defined unit tests."""
import cx_Oracle
import imp
import os
import sys
import unittest
print("Running tests for cx_Oracle version", cx_Oracle.version)
import TestEnv
if len(sys.argv) > 1:
moduleNames = [os.path.splitext(v)[0] for v in sys.argv[1:]]
else:
moduleNames = [
"Connection",
"Cursor",
"CursorVar",
"DateTimeVar",
"LobVar",
"LongVar",
"3kNumberVar",
"ObjectVar",
"SessionPool",
"3kStringVar",
"TimestampVar"
]
class BaseTestCase(unittest.TestCase):
def setUp(self):
self.connection = cx_Oracle.connect(TestEnv.USERNAME,
TestEnv.PASSWORD, TestEnv.TNSENTRY)
self.cursor = self.connection.cursor()
self.cursor.arraysize = TestEnv.ARRAY_SIZE
def tearDown(self):
del self.cursor
del self.connection
loader = unittest.TestLoader()
runner = unittest.TextTestRunner(verbosity = 2)
failures = []
for name in moduleNames:
fileName = name + ".py"
print()
print("Running tests in", fileName)
module = imp.new_module(name)
setattr(module, "USERNAME", TestEnv.USERNAME)
setattr(module, "PASSWORD", TestEnv.PASSWORD)
setattr(module, "TNSENTRY", TestEnv.TNSENTRY)
setattr(module, "ARRAY_SIZE", TestEnv.ARRAY_SIZE)
setattr(module, "TestCase", unittest.TestCase)
setattr(module, "BaseTestCase", BaseTestCase)
setattr(module, "cx_Oracle", cx_Oracle)
exec(open(fileName).read(), module.__dict__)
tests = loader.loadTestsFromModule(module)
result = runner.run(tests)
if not result.wasSuccessful():
failures.append(name)
if failures:
print("***** Some tests in the following modules failed. *****")
for name in failures:
print(" %s" % name)